fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
frame_builder.cpp
Go to the documentation of this file.
1 
15 #include <arpa/inet.h>
16 #include <boost/crc.hpp>
17 
18 #include "frame_builder.h"
19 #include "interleaver.h"
20 #include "qam.h"
21 #include "ppdu.h"
22 #include "symbol_mapper.h"
23 #include "fft.h"
24 #include "preamble.h"
25 #include "rates.h"
26 #include "viterbi.h"
27 #include "parity.h"
28 #include "modulator.h"
29 #include "puncturer.h"
30 
31 
32 #define preamble_length 256
33 
34 namespace fun
35 {
41  m_ifft(64)
42  {
43  }
44 
53  std::vector<std::complex<double> > frame_builder::build_frame(std::vector<unsigned char> payload, Rate rate)
54  {
55  //Append header, scramble, code, interleave, & modulate
56  ppdu ppdu_frame(payload, rate);
57  std::vector<std::complex<double> > samples = ppdu_frame.encode();
58 
59  // Map the subcarriers and insert pilots
60  symbol_mapper mapper = symbol_mapper();
61  std::vector<std::complex<double> > mapped = mapper.map(samples);
62 
63  // Perform the IFFT
64  m_ifft.inverse(mapped);
65 
66  // Add the cyclic prefixes
67  std::vector<std::complex<double> > prefixed(mapped.size() * 80 / 64);
68  for(int x = 0; x < mapped.size() / 64; x++)
69  {
70  memcpy(&prefixed[x*80], &mapped[x*64+48], 16*sizeof(std::complex<double>));
71  memcpy(&prefixed[x*80+16], &mapped[x*64], 64*sizeof(std::complex<double>));
72  }
73 
74  // Prepend the preamble
75  std::vector<std::complex<double> > frame(prefixed.size() + 320);
76 
77  memcpy(&frame[0], &PREAMBLE_SAMPLES[0], 320 * sizeof(std::complex<double>));
78  memcpy(&frame[320], &prefixed[0], prefixed.size() * sizeof(std::complex<double>));
79 
80  // Return the samples
81  return frame;
82  }
83 }
84