BitTable.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __BitTable_h
10 #define __BitTable_h
11 
12 #include "Reference.h"
13 
14 namespace dsp {
15 
17  class BitTable : public Reference::Able
18  {
19  public:
20 
22  static const unsigned bits_per_byte;
23 
25  static const unsigned unique_bytes;
26 
28  enum Type
29  {
30  OffsetBinary,
31  TwosComplement,
32  SignMagnitude // for 2-bit only
33  };
34 
36  enum Order
37  {
38  MostToLeast,
39  LeastToMost
40  };
41 
43  BitTable (unsigned nbit, Type type, bool reverse_bits = false);
44 
46  virtual ~BitTable ();
47 
49 
51  void set_effective_nbit (unsigned bits);
52  unsigned get_effective_nbit () const { return effective_nbit; }
53 
55  void set_order (Order);
56  Order get_order () const { return order; }
57 
59 
66  void set_zero_is_a_threshold (bool);
67  bool get_zero_is_a_threshold () const { return zero_is_a_threshold; }
68 
70  unsigned get_values_per_byte () const { return values_per_byte; }
71 
73  unsigned get_unique_values () const { return unique_values; }
74 
76  double get_scale () const;
77 
79  Type get_type () const { return type; }
80 
82  const float* get_values (unsigned byte = 0) const;
83 
85  void generate (float* table) const;
86 
88  virtual void generate_unique_values (float* values) const;
89 
91  virtual unsigned extract (unsigned byte, unsigned i) const;
92 
94  virtual double get_optimal_variance () const;
95 
97  virtual double get_nlow_threshold () const;
98 
100  virtual void get_nlow_lookup (char* nlow_lookup) const;
101 
102  protected:
103 
105  float* table;
106 
108  Type type;
109 
111  const unsigned nbit;
112 
114  unsigned zero_is_a_threshold;
115 
117  unsigned effective_nbit;
118 
120  const bool reverse_bits;
121 
123  Order order;
124 
126  const unsigned values_per_byte;
127 
129  const unsigned unique_values;
130 
132  const unsigned nbit_mask;
133 
135  mutable double scale;
136 
138  void build ();
139 
141  void destroy ();
142  };
143 
144 }
145 
146 #endif // !defined(__BitTable_h)
void generate(float *table) const
Generate a look-up table for conversion to floating point.
Definition: BitTable.C:128
double scale
The scale factor used to normalize the variance to unity.
Definition: BitTable.h:145
virtual void get_nlow_lookup(char *nlow_lookup) const
Return the number of low voltage states in each of 256 bytes.
Definition: BitTable.C:242
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
virtual double get_optimal_variance() const
Return the optimal variance of normally distributed samples.
Definition: BitTable.C:227
void set_order(Order)
Set the order of the samples in each byte.
Definition: BitTable.C:76
virtual ~BitTable()
Destructor.
Definition: BitTable.C:65
const unsigned unique_values
Number of unique N-bit values.
Definition: BitTable.h:139
Order
The order of values in each byte (bit significance)
Definition: BitTable.h:46
static const unsigned bits_per_byte
Number of bits per bytes.
Definition: BitTable.h:32
virtual unsigned extract(unsigned byte, unsigned i) const
Extract the ith sample from byte.
Definition: BitTable.C:161
const bool reverse_bits
Reverse the order of the bits.
Definition: BitTable.h:130
const float * get_values(unsigned byte=0) const
Returns pointer to values_per_byte floats represented by byte.
Definition: BitTable.C:88
void build()
Build the lookup table.
Definition: BitTable.C:104
virtual double get_nlow_threshold() const
Return the optimal threshold closest to and less than unity.
Definition: BitTable.C:235
static const unsigned unique_bytes
Number of unique 8-bit combinations.
Definition: BitTable.h:35
Type get_type() const
Return the digitization convention.
Definition: BitTable.h:89
Look-up table for converting N-bit digitized to floating point numbers.
Definition: BitTable.h:22
void set_effective_nbit(unsigned bits)
Set the effective number of bits.
Definition: BitTable.C:70
Type
Interpretation of the bits in each value.
Definition: BitTable.h:38
unsigned zero_is_a_threshold
Zero is a threshold.
Definition: BitTable.h:124
unsigned effective_nbit
The effective number of bits.
Definition: BitTable.h:127
Type type
Digitization convention.
Definition: BitTable.h:118
virtual void generate_unique_values(float *values) const
Generate a look-up table of unique_values floats.
Definition: BitTable.C:172
Order order
The order of the samples in each byte.
Definition: BitTable.h:133
BitTable(unsigned nbit, Type type, bool reverse_bits=false)
Constructor.
Definition: BitTable.C:39
double get_scale() const
Get the scale factor used to normalize the variance to unity.
Definition: BitTable.C:96
const unsigned nbit_mask
N-bit mask.
Definition: BitTable.h:142
const unsigned nbit
Number of bits.
Definition: BitTable.h:121
unsigned get_values_per_byte() const
Get the number of floating point values per byte, 8/N.
Definition: BitTable.h:80
void set_zero_is_a_threshold(bool)
Set to true if zero is a threshold; set to false if zero is a value.
Definition: BitTable.C:82
float * table
For each unsigned char, values of the two output voltage states.
Definition: BitTable.h:115
const unsigned values_per_byte
Number of N-bit values per byte.
Definition: BitTable.h:136
void destroy()
Destroy the lookup table.
Definition: BitTable.C:60
static double get_optimal_spacing(unsigned bits)
unsigned get_unique_values() const
Get the number of unique values of an N-bit integer, 2^N.
Definition: BitTable.h:83

Generated using doxygen 1.8.17