fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
channel_est.cpp
Go to the documentation of this file.
1 
9 #include <cstring>
10 
11 #include "channel_est.h"
12 #include "preamble.h"
13 
14 namespace fun
15 {
23  block("channel_est"),
24  m_chan_est(64, std::complex<double>(1, 0)),
25  m_lts_flag(0),
26  m_frame_start(false)
27  {
28  }
29 
37 
38  if(input_buffer.size() == 0) return;
39  output_buffer.resize(0);
40 
41  for(int i = 0; i < input_buffer.size(); i++)
42  {
43  // Start of LTS found
44  if(input_buffer[i].tag == LTS_START)
45  {
46  m_lts_flag = 1;
47  for(int j = 0; j < 64; j++) m_chan_est[j] = std::complex<double>(0.0,0.0);
48  }
49 
50  if(m_lts_flag > 0) // This is a LTS symbol
51  {
52  // Calculate channel correction
53  for(int j = 0; j < 64; j++)
54  {
55  std::complex<double> ref_lts_sample = LTS_FREQ_DOMAIN[j];
56  std::complex<double> rec_lts_sample = input_buffer[i].samples[j];
57  m_chan_est[j] += ref_lts_sample / rec_lts_sample / 2.0;
58  }
59 
60  m_lts_flag++;
61  if(m_lts_flag == 3) // No more LTS symbols
62  {
63  m_lts_flag = 0;
64  m_frame_start = true; // Next symbol is the start of frame
65  }
66  }
67  else
68  {
69  tagged_vector<64> symbol;
70  if(m_frame_start)
71  {
72  symbol.tag = START_OF_FRAME;
73  m_frame_start = false;
74  }
75 
76  // Apply channel correction
77  for(int j = 0; j < 64; j++)
78  {
79  std::complex<double> out_sample = m_chan_est[j] * input_buffer[i].samples[j];
80  symbol.samples[j] = out_sample;
81  }
82  output_buffer.push_back(symbol);
83  }
84  }
85  }
86 
87 }
88 
89