TwoBitFour.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 // dspsr/Kernel/Classes/dsp/TwoBitFour.h
10 
11 #ifndef __TwoBitFour_h
12 #define __TwoBitFour_h
13 
14 #include "dsp/TwoBitLookup.h"
15 
16 namespace dsp
17 {
19  class TwoBitFour : public TwoBitLookup
20  {
21 
22  public:
23 
24  static const unsigned samples_per_byte;
25  static const unsigned lookup_block_size;
26 
28  bool bad;
29 
32 
34  void nlow_build (TwoBitTable* table);
35 
37  void get_lookup_block (float* lookup, TwoBitTable* table);
38 
40  unsigned get_lookup_block_size ();
41 
42  template<class Iterator>
43  inline void prepare (Iterator input, unsigned ndat)
44  {
45  const unsigned nbyte = ndat / samples_per_byte;
46  unsigned total = 0;
47 
48  nlow = 0;
49 
50  for (unsigned bt=0; bt < nbyte; bt++)
51  {
52  nlow += nlow_lookup[ *input ];
53  total += *input;
54  ++ input;
55  }
56 
57  bad = (total == 0);
58  }
59 
60  template<class Iterator>
61  inline void unpack (Iterator& input, unsigned ndat,
62  float* output, unsigned output_incr, unsigned& _nlow)
63  {
64  const unsigned nbyte = ndat / samples_per_byte;
65  _nlow = nlow;
66 
67  // if data are complex, divide n_low by two
68  nlow /= ndim;
69 
70  if (nlow < nlow_min)
71  nlow = nlow_min;
72 
73  else if (nlow > nlow_max)
74  nlow = nlow_max;
75 
76  float* lookup = lookup_base + (nlow-nlow_min) * lookup_block_size;
77 
78  for (unsigned bt=0; bt < nbyte; bt++)
79  {
80  float* fourval = lookup + *input * samples_per_byte;
81  ++ input;
82 
83  for (unsigned pt=0; pt < samples_per_byte; pt++)
84  {
85  *output = fourval[pt];
86  output += output_incr;
87  }
88  }
89  }
90 
91  protected:
92 
93  char nlow_lookup [256];
94  };
95 
96 }
97 
98 #endif
void generate(float *table) const
Generate a look-up table for conversion to floating point.
Definition: BitTable.C:128
Contains all Baseband Data Reduction Library classes.
Definition: ASCIIObservation.h:17
void get_lookup_block(float *lookup, TwoBitTable *table)
Implement TwoBitLookup::get_lookup_block.
Definition: TwoBitFour.C:41
unsigned get_lookup_block_size()
Implement TwoBitLookup::get_lookup_block_size.
Definition: TwoBitFour.C:50
void set_lo_val(float lo_val)
Set the value of the low voltage state.
Definition: TwoBitTable.C:21
virtual void lookup_build(TwoBitTable *, JenetAnderson98 *=0)
Build the output value lookup table.
Definition: TwoBitLookup.C:77
void lookup_build(TwoBitTable *, JenetAnderson98 *=0)
Build the output value lookup table.
Definition: TwoBitFour.C:17
void nlow_build(TwoBitTable *table)
Build counts of low voltage 2-bit states in each byte.
Definition: TwoBitFour.C:23
void rebuild()
Build a two-bit table with the current attributes.
Definition: TwoBitTable.C:37
const float * get_values(unsigned byte=0) const
Returns pointer to values_per_byte floats represented by byte.
Definition: BitTable.C:88
static const unsigned unique_bytes
Number of unique 8-bit combinations.
Definition: BitTable.h:35
bool bad
Flag set when the data should be flagged as bad.
Definition: TwoBitFour.h:38
Look-up table for converting 2-bit digitized to floating point numbers.
Definition: TwoBitTable.h:25
unsigned get_values_per_byte() const
Get the number of floating point values per byte, 8/N.
Definition: BitTable.h:80

Generated using doxygen 1.8.17