fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
frame_detector.cpp
Go to the documentation of this file.
1 
8 #include <cstring>
9 #include <iostream>
10 
11 #include "frame_detector.h"
12 
13 namespace fun
14 {
24  block("frame_detector"),
25  m_power_acc(STS_LENGTH),
26  m_corr_acc(STS_LENGTH),
27  m_carryover(STS_LENGTH, 0),
28  m_plateau_length(0),
29  m_plateau_flag(false)
30  {
31  }
32 
42  {
43  if(input_buffer.size() == 0) return;
44  output_buffer.resize(input_buffer.size());
45 
46  // Step through the samples
47  for(int x = 0; x < input_buffer.size(); x++)
48  {
49  output_buffer[x].tag = NONE;
50 
51  // Get the delayed samples
52  std::complex<double> delayed;
53  if(x < STS_LENGTH) delayed = m_carryover[x];
54  else delayed = input_buffer[x-STS_LENGTH];
55 
56  // Update the correlation accumulators
57  m_corr_acc.add(input_buffer[x] * std::conj(delayed));
58 
59  // Update the power accumulator
60  m_power_acc.add(std::norm(input_buffer[x]));
61 
62  // Calculate the normalized correlations
63  double corr = std::abs(m_corr_acc.sum) / m_power_acc.sum;
64 
65  if(corr > PLATEAU_THRESHOLD)
66  {
69  {
70  output_buffer[x].tag = STS_START;
71  m_plateau_flag = true;
72  }
73  }
74  else
75  {
76  if(m_plateau_flag)
77  {
78  output_buffer[x].tag = STS_END;
79  m_plateau_flag = false;
80  }
81  m_plateau_length = 0;
82  }
83 
84  // Pass through the sample
85  output_buffer[x].sample = input_buffer[x];
86  }
87 
88  // Carryover the last 16 output samples
89  memcpy(&m_carryover[0],
91  STS_LENGTH * sizeof(std::complex<double>));
92  }
93 
94 }
95 
96