GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > LDT / V0-2-0

Constituent: encdec     Tag: rad750


Interface   Data Structures   File List   Data Fields   Globals  

HDE.c File Reference

Implementation of the routines to encodes a distribution of symbols using a Huffman encoding technique. Routines are available to encode both the distribution itself and the resulting Huffman table. More...

#include "LDT/HDE.h"
#include "LDT/HUFF.h"
#include "LDT/BFP.h"
#include "ffs.h"
#include "dprintf.h"
#include <math.h>

Include dependency graph for HDE.c:


Data Structures

struct  _HistLimits
 Min and Max indices of a histogram. More...

Defines

#define NULL   ((void *)(0))

Typedefs

typedef _HistLimits HistLimits
 Typedef for struct _HistLimits.

Functions

static __inline HistLimits hist_limits_find (const unsigned short int *hist, int cnt)
static __inline int hist_copy (unsigned int *dst, const unsigned short int *src, int min, int max)
 Copies the core of the histogram (i.e. from the first non-zero element to the last non-zero element.
static __inline unsigned int huff_table_encode (unsigned int *buf, unsigned int pos, const HUFF_code *codes, const unsigned int *freq, int nentries, int nbits_min, int min)
 Encodes the Huffman encoding table.
static __inline unsigned int huff_symbols_encode (unsigned int *buf, unsigned int pos, const HUFF_code *codes, const short int *symbols, int nsymbols)
 Encodes the pedestal subtracted ADC values using the specified Huffman codes.
 _declare (static double calc_nbits(const int *f, int cnt, int tot))
unsigned int HDE_encodeSS (unsigned int *buf, unsigned int pos, const unsigned short int *hist, int nbins, const short int *symbols, int nsymbols)
 Encodes the specified symbols symbols using the specified histogram of frequencies. Both the symbols and the histogram are presented as 16-bit values.
double calc_nbits (const int *f, int cnt, int tot)
 Calculates the number of bits need to encode a sample with the specified frequency distribution.

Detailed Description

Implementation of the routines to encodes a distribution of symbols using a Huffman encoding technique. Routines are available to encode both the distribution itself and the resulting Huffman table.

Author:
JJRussell - russell@slac.stanford.edu
   CVS $Id: HDE.c,v 1.2 2006/09/13 17:58:41 russell Exp $

Typedef Documentation

static __inline HistLimits
 

Typedef for struct _HistLimits.

cal_hist_limits_find (const unsigned short int *hist, int cnt)

Parameters:
hist The target histogram
cnt The total number of entries in the histogram


Function Documentation

static double calc_nbits const int *  f,
int  cnt,
int  tot
 

Calculates the number of bits need to encode a sample with the specified frequency distribution.

Parameters:
f The frequency distribution
cnt The count of entries in the frequency distribution
tot The total number of entries in the frequency distribution
This is based on the following formula

nbits = - TOT * SUM [ f[i] / TOT * ln (f[i] / TOT) ] = - TOT/TOT * SUM [ f[i] * (ln (f[i]) - ln (TOT)) ] = - SUM [ f[i] * ln (f[i] ] + SUM [ f[i] * ln (TOT) ] = - SUM [ f[i] * ln (f[i] ] + TOT * ln (TOT) ]

unsigned int HDE_encodeSS unsigned int *  buf,
unsigned int  pos,
const unsigned short int *  hist,
int  nbins,
const short int *  symbols,
int  nsymbols
 

Encodes the specified symbols symbols using the specified histogram of frequencies. Both the symbols and the histogram are presented as 16-bit values.

Returns:
The updated bit write position
Parameters:
buf The output buffer address
pos The current write bit offset
hist The frequency histogram
nbins The number of bins in the histogram
symbols The array of symbols
nsymbols The number of symbols

static __inline int hist_copy unsigned int *  dst,
const unsigned short int *  src,
int  min,
int  max
[static]
 

Copies the core of the histogram (i.e. from the first non-zero element to the last non-zero element.

Parameters:
dst The destination histogram
src The source histogram
min The first non-zero histogram bin
max The last non-zero histogram bin
This routine exists solely because the HUFF build routines only take an integer (not a short integer) frequency distribution.

static __inline unsigned int huff_symbols_encode unsigned int *  buf,
unsigned int  pos,
const HUFF_code codes,
const short int *  symbols,
int  nsymbols
[static]
 

Encodes the pedestal subtracted ADC values using the specified Huffman codes.

Returns:
The updated write bit position
Parameters:
buf The output buffer
pos The position of the next bit to fill
codes The Huffman codes
symbols The symbols to encode
nsymbols The number of symbols to encode

static __inline unsigned int huff_table_encode unsigned int *  buf,
unsigned int  pos,
const HUFF_code codes,
const unsigned int *  freq,
int  cnt,
int  nbits_min,
int  min
[static]
 

Encodes the Huffman encoding table.

Returns:
The updated write bit position
Parameters:
buf The output buffer
pos The position of the next bit to fill
codes The Huffman codes
freq The frequency distribution. This is used to determine valid members.
cnt The count of codes
nbits_min The number bits to use in encoding the minimum, min If 0, the minimum offset will not be encoded If -1, the number of bits will be computed from min itself and stored as a 5-bit number
min The offset of the table. This value should be added onto the decoded symbol
The encoding is

  • nbits_min: 5, number of bits used to encode the minimum symbol value (fixed 5 bits)
  • min: nbits_min, the minumum symbol value
  • nbits_rl : 5, number of bits needed to encode the maximum run length, if 0, then this is a 0 entropy distribution with the only value of 'min'
  • rl[0] : Run length of the run of symbols
  • rl[1] : Run length till the next block of symbols, if 0, then finished. Note that the finish must always be on an odd run length index.
  • nbits_cl : 5, number of bits needed to hold the maximum code length
  • cl[0] : nbits_cl, the code length of the first symbol
  • cl[1] : nbits_cl, the code length of the second symbol
  • .
  • .
  • cl[n] : nbits_cl, the code length of the last symbol, the number of symbols is derived from the run length decoding


Generated on Thu Sep 14 09:17:33 2006 by  doxygen 1.4.4