fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
fun::fft Class Reference

The fft class. More...

#include <fft.h>

Public Member Functions

 fft (int fft_length)
 Constructor for fft object. More...
 
void forward (std::complex< double > data[64])
 In place 64 point forward FFT. More...
 
void inverse (std::vector< std::complex< double > > &data)
 In place inverse FFT of input data. More...
 

Private Attributes

int m_fft_length
 Length of FFT. In 802.11a it is always a 64 Point FFT since There are 64 subcarriers. More...
 
fftw_complex * m_fftw_in_forward
 Forward input buffer for use by fftw3 library. More...
 
fftw_complex * m_fftw_out_forward
 Forward output buffer for use by fftw3 library. More...
 
fftw_complex * m_fftw_in_inverse
 Inverse input buffer for use by fftw3 library. More...
 
fftw_complex * m_fftw_out_inverse
 Inverse output buffer for use by fftw3 library. More...
 
fftw_plan m_fftw_plan_forward
 Forward FFT plan for use by fftw3 library. More...
 
fftw_plan m_fftw_plan_inverse
 Inverse FFT plan for use by fftw3 library. More...
 

Static Private Attributes

static const int fft_map [64]
 Mapping to/from FFT order. More...
 

Detailed Description

The fft class.

This class contains is a wrapper for the fftw3 library and contains the functions and necessary parameters for performing the IFFTs and FFTs in the transmit and receive chains respectively.

Definition at line 24 of file fft.h.

Constructor & Destructor Documentation

fun::fft::fft ( int  fft_length)

Constructor for fft object.

Parameters
fft_lengthlength of FFT - i.e. 64 point FFT

-Initializations:

  • m_fft_length -> 64 because we always deal with 64 point FFTs since there are 64 OFDM subcarriers

Definition at line 30 of file fft.cpp.

References m_fft_length, m_fftw_in_forward, m_fftw_in_inverse, m_fftw_out_forward, m_fftw_out_inverse, m_fftw_plan_forward, and m_fftw_plan_inverse.

30  :
31  m_fft_length(fft_length)
32  {
33  // Allocate the FFT buffers
34  m_fftw_in_forward = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_fft_length);
35  m_fftw_out_forward = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_fft_length);
36  m_fftw_in_inverse = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_fft_length);
37  m_fftw_out_inverse = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * m_fft_length);
38  m_fftw_plan_forward = fftw_plan_dft_1d(m_fft_length, m_fftw_in_forward, m_fftw_out_forward, FFTW_FORWARD, FFTW_MEASURE);
39  m_fftw_plan_inverse = fftw_plan_dft_1d(m_fft_length, m_fftw_in_inverse, m_fftw_out_inverse, FFTW_BACKWARD, FFTW_MEASURE);
40  }

Member Function Documentation

void fun::fft::forward ( std::complex< double >  data[64])

In place 64 point forward FFT.

Parameters
dataArray of 64 complex samples in time domain to be converted to frequency domain.

This function performs a single in-place 64 point FFT on the 64 complex data samples. The user must loop over time-domain signal and pass each 64 sample symbol to this function individually. This function handles the shifting from all positive (0-63) indexing to positive & negative frequency indexing.

Definition at line 50 of file fft.cpp.

References fft_map, m_fft_length, m_fftw_in_forward, m_fftw_out_forward, and m_fftw_plan_forward.

Referenced by fun::fft_symbols::work().

51  {
52  memcpy(m_fftw_in_forward, &data[0], m_fft_length * sizeof(std::complex<double>));
53  fftw_execute(m_fftw_plan_forward);
54 
55  for(int s = 0; s < 64; s++)
56  {
57  memcpy(&data[s], &m_fftw_out_forward[fft_map[s]], sizeof(std::complex<double>));
58  }
59  }
void fun::fft::inverse ( std::vector< std::complex< double > > &  data)

In place inverse FFT of input data.

Parameters
dataVector of complex doubles in frequency domain to be converted to time domain. The length of the data vector must be an integer multiple of m_fft_length.

This function loops over the input vector (which must be an integer multiple of 64) and performs in-place 64 point IFFTs on each consecutive 64 sample chunk of the input vector. This function handles the shifting from positive & negative frequency (-32 to 31) indexing to all positive (0 to 63) indexing. This function also scales the output by 1/64 to be consistent with the IFFT function.

Definition at line 68 of file fft.cpp.

References fft_map, m_fft_length, m_fftw_in_inverse, m_fftw_out_inverse, and m_fftw_plan_inverse.

Referenced by fun::frame_builder::build_frame().

69  {
70  assert(data.size() % m_fft_length == 0);
71 
72  // Run the IFFT on each m_fft_length samples
73  for(int x = 0; x < data.size(); x += m_fft_length)
74  {
75  if(m_fft_length == 64)
76  {
77  for(int s = 0; s < 64; s++)
78  {
79  memcpy(&m_fftw_in_inverse[s], &data[x + fft_map[s]], sizeof(std::complex<double>));
80  }
81  }
82  else
83  {
84  memcpy(&m_fftw_in_inverse[0], &data[x], m_fft_length * sizeof(std::complex<double>));
85  }
86 
87  fftw_execute(m_fftw_plan_inverse);
88  memcpy(&data[x], m_fftw_out_inverse, m_fft_length * sizeof(std::complex<double>));
89  }
90 
91  // Scale by 1/fft_length
92  for(int x = 0; x < data.size(); x++)
93  {
94  data[x] /= m_fft_length;
95  }
96  }

Member Data Documentation

const int fun::fft::fft_map
staticprivate
Initial value:
=
{
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
}

Mapping to/from FFT order.

This map shifts the subcarriers so that instead of being thought of sequentially from 0-63 they can be thought of as positive and negative frequencies which is the ordering that the FFTW3 library uses.

Definition at line 55 of file fft.h.

Referenced by forward(), and inverse().

int fun::fft::m_fft_length
private

Length of FFT. In 802.11a it is always a 64 Point FFT since There are 64 subcarriers.

Definition at line 61 of file fft.h.

Referenced by fft(), forward(), and inverse().

fftw_complex* fun::fft::m_fftw_in_forward
private

Forward input buffer for use by fftw3 library.

Definition at line 66 of file fft.h.

Referenced by fft(), and forward().

fftw_complex* fun::fft::m_fftw_in_inverse
private

Inverse input buffer for use by fftw3 library.

Definition at line 76 of file fft.h.

Referenced by fft(), and inverse().

fftw_complex* fun::fft::m_fftw_out_forward
private

Forward output buffer for use by fftw3 library.

Definition at line 71 of file fft.h.

Referenced by fft(), and forward().

fftw_complex* fun::fft::m_fftw_out_inverse
private

Inverse output buffer for use by fftw3 library.

Definition at line 81 of file fft.h.

Referenced by fft(), and inverse().

fftw_plan fun::fft::m_fftw_plan_forward
private

Forward FFT plan for use by fftw3 library.

Definition at line 86 of file fft.h.

Referenced by fft(), and forward().

fftw_plan fun::fft::m_fftw_plan_inverse
private

Inverse FFT plan for use by fftw3 library.

Definition at line 91 of file fft.h.

Referenced by fft(), and inverse().


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