fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
fun::QAM< NumBits > Class Template Reference

Template for QAM class. More...

#include <qam.h>

Public Member Functions

 QAM (double power, int gain=0)
 QAM Constructor. More...
 
void encode (const char *bits, double *sym)
 Encode recursively to match the decoding process. More...
 
void decode (double sym, unsigned char *bits)
 Decode recursively. More...
 

Static Public Member Functions

static int sign (int v)
 sign More...
 
static int clamp (int i)
 clamp More...
 

Private Attributes

int d_gain
 
double d_scale_e
 
double d_scale_d
 

Detailed Description

template<int NumBits>
class fun::QAM< NumBits >

Template for QAM class.

fast QAM (uses at most 4x imull to decode) Tested on 7600 bogomips yields 600-1200Mbps encoding and 300Mbps decoding Compile with -O3

Definition at line 24 of file qam.h.

Constructor & Destructor Documentation

template<int NumBits>
fun::QAM< NumBits >::QAM ( double  power,
int  gain = 0 
)
inline

QAM Constructor.

Parameters
powerdesired symbol power
gaingain on the decoded confidence (power of 2)

Definition at line 35 of file qam.h.

References fun::QAM< NumBits >::d_gain, fun::QAM< NumBits >::d_scale_d, and fun::QAM< NumBits >::d_scale_e.

36  {
37  d_gain = gain + CHAR_BIT - NumBits;
38  const int nn = (1<<(NumBits-1));
39  // sum((2k+1)^2,k=0..n-1)
40  #if 0
41  int sum2 = 0;
42  for (int i = 0; i < nn; ++i) {
43  sum2+= (2*i + 1)*(2*i + 1);
44  }
45  #else
46  int sum2 = (4*nn*nn*nn-nn)/3;
47  #endif
48  double sf = sqrt(power * double(nn) / double(sum2));
49  d_scale_e = sf;
50  d_scale_d = (1 << d_gain) / sf;
51  }

Member Function Documentation

template<int NumBits>
static int fun::QAM< NumBits >::clamp ( int  i)
inlinestatic

clamp

Parameters
i
Returns
saturate between 0 and 255

Definition at line 68 of file qam.h.

Referenced by fun::QAM< NumBits >::decode().

69  {
70  return i < 0 ? 0 : (i > 255 ? 255 : i);
71  }
template<int NumBits>
void fun::QAM< NumBits >::decode ( double  sym,
unsigned char *  bits 
)
inline

Decode recursively.

We decode recursively because we want meaningful confidences. The alternative would be to simply divide and round, which only yields the smallest per-bit confidence.

output bit confidence is between 0 and 255.

Parameters
sym
bits

Definition at line 110 of file qam.h.

References amp, fun::QAM< NumBits >::clamp(), fun::QAM< NumBits >::d_gain, fun::QAM< NumBits >::d_scale_d, and fun::QAM< NumBits >::sign().

Referenced by fun::modulator::demodulate().

111  {
112  int pt = sym * d_scale_d;
113  int flip = 1; // +1 or -1 -- for gray coding
114  int amp = (1 << (NumBits-1)) << d_gain;
115  // unrolled with -O3
116  for (int i = 0; i < NumBits; ++i)
117  {
118  *bits = clamp(flip * pt + 128);
119  int bit = sign(pt);
120  pt -= bit * amp;
121  flip = -bit;
122  amp /= 2;
123  ++bits;
124  }
125  }
template<int NumBits>
void fun::QAM< NumBits >::encode ( const char *  bits,
double *  sym 
)
inline

Encode recursively to match the decoding process.

This could have been implemented by a gray + multiply. gray(i) = (i> >1)^i see: http://www.dspguru.com/dsp/tricks/gray-code-conversion

Parameters
bits
sym

Definition at line 83 of file qam.h.

References fun::QAM< NumBits >::d_scale_e.

Referenced by fun::modulator::modulate().

84  {
85  int pt = 0; // constellation point
86  int flip = 1; // +1 or -1 -- for gray coding
87  // unrolled with -O3
88  for (int i = 0; i < NumBits; ++i)
89  {
90  int bit = *bits * 2 - 1; // +1 or -1
91  pt = bit * flip + pt * 2;
92  flip *= -bit;
93  ++bits;
94  }
95  *sym = pt * d_scale_e;
96  }
template<int NumBits>
static int fun::QAM< NumBits >::sign ( int  v)
inlinestatic

sign

Parameters
v
Returns
+1 or -1

Definition at line 58 of file qam.h.

Referenced by fun::QAM< NumBits >::decode().

59  {
60  return +1 | (v >> (sizeof(int) * CHAR_BIT - 1));
61  }

Member Data Documentation

template<int NumBits>
int fun::QAM< NumBits >::d_gain
private

Definition at line 26 of file qam.h.

Referenced by fun::QAM< NumBits >::decode(), and fun::QAM< NumBits >::QAM().

template<int NumBits>
double fun::QAM< NumBits >::d_scale_d
private

Definition at line 28 of file qam.h.

Referenced by fun::QAM< NumBits >::decode(), and fun::QAM< NumBits >::QAM().

template<int NumBits>
double fun::QAM< NumBits >::d_scale_e
private

Definition at line 27 of file qam.h.

Referenced by fun::QAM< NumBits >::encode(), and fun::QAM< NumBits >::QAM().


The documentation for this class was generated from the following file: