fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
test_sim.cpp File Reference

Simulates the building of packets and sending them through the receive chain. More...

#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/program_options.hpp>
#include "usrp.h"
#include "frame_builder.h"
#include "receiver_chain.h"

Go to the source code of this file.

Functions

void test_sim ()
 
int main (int argc, char *argv[])
 

Variables

double freq = 5.26e9
 
double sample_rate = 5e6
 
double tx_gain = 30
 
double rx_gain = 30
 
double amp = 0.5
 
Rate phy_rate = RATE_3_4_QAM16
 

Detailed Description

Simulates the building of packets and sending them through the receive chain.

This file is used to simulate building packets with the frame_builder class and then sending them through the receive chain.

Definition in file test_sim.cpp.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file test_sim.cpp.

References test_sim().

30  {
31 
32  std::cout << "Running Simulation..." << std::endl;
33  test_sim();
34 
35  return 0;
36 }
void test_sim ( )

This function builds some packets using the frame builder and sends them through the receiver chain. This function does NOT use the transmitter and receiver classes.

Definition at line 43 of file test_sim.cpp.

References fun::frame_builder::build_frame(), phy_rate, and fun::receiver_chain::process_samples().

Referenced by main().

44 {
45 
46  frame_builder * fb = new frame_builder();
48 
49  std::string data("I'm a little tea pot, short and stout.....here is my handle.....blah blah blah.....this rhyme sucks!");
50  int repeat = 15;
51 
52  std::vector<unsigned char> payload(data.length()*repeat); //Payload = 1500 bytes
53  for(int x = 0; x < repeat; x++) memcpy(&payload[x*data.length()], &data[0], data.length());
54 
55  // Build a frame
56  std::vector<std::complex<double>> samples = fb->build_frame(payload, phy_rate);
57 
58  int pad_length = samples.size()*1000;
59 
60  // Concatenate num_frames frames together
61  int num_frames = 100;
62  std::cout << "Transmitting " << num_frames << " frames" << std::endl;
63  std::vector<std::complex<double>> samples_con(samples.size() * num_frames + pad_length);
64  for(int x = 0; x < num_frames; x++)
65  {
66  memcpy(&samples_con[x*samples.size()], &samples[0], samples.size() * sizeof(std::complex<double>));
67  }
68 
69  //Pad the end with 0's to flush receive chain
70  std::vector<std::complex<double> > zeros(pad_length);
71  memcpy(&samples_con[num_frames*samples.size()], &zeros[0], zeros.size()*sizeof(std::complex<double>));
72 
73  boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
74 
75  // Run the samples through the receiver chain
76 
77  int chunk_size = 4096;
78 
79  int count = 0;
80  for(int x = 0; x < samples_con.size(); x += chunk_size)
81  {
82  int start = x;
83  int end = x + chunk_size;
84  if(end > samples_con.size()) end = samples_con.size();
85  std::vector<std::complex<double> > chunk(&samples_con[start], &samples_con[end]);
86 
87  std::vector<std::vector<unsigned char> > rec_frames = receiver->process_samples(chunk);
88  count += rec_frames.size();
89 
90  if(rec_frames.size()){
91  for(int i = 0; i < rec_frames.size(); i++){
92  for(int j = 0; j < rec_frames[i].size(); j++)
93  std::cout << rec_frames[i][j];
94  std::cout << std::endl << std::endl;
95  }
96  }
97  }
98 
99  boost::posix_time::time_duration elapsed = boost::posix_time::microsec_clock::local_time() - start;
100 
101  printf("Received %i packets\n", count);
102 
103  printf("Time elapsed: %f\n", elapsed.total_microseconds() / 1000.0);
104 }

Variable Documentation

double amp = 0.5

Definition at line 24 of file test_sim.cpp.

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

double freq = 5.26e9

Definition at line 20 of file test_sim.cpp.

Rate phy_rate = RATE_3_4_QAM16

Definition at line 28 of file test_sim.cpp.

Referenced by main(), and test_sim().

double rx_gain = 30

Definition at line 23 of file test_sim.cpp.

double sample_rate = 5e6

Definition at line 21 of file test_sim.cpp.

double tx_gain = 30

Definition at line 22 of file test_sim.cpp.

Referenced by main().