fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
puncturer.cpp
Go to the documentation of this file.
1 
10 #include <cmath>
11 
12 #include "puncturer.h"
13 
14 namespace fun
15 {
16 
24  std::vector<unsigned char> puncturer::puncture(std::vector<unsigned char> data, RateParams rate_params)
25  {
26  // Puncture the data
27  int count, index;
28  switch(rate_params.rate)
29  {
30  // Nothing to do
32  return data;
33  break;
34 
35  // Puncture from 1/2 to 3/4
37  {
38  count = round(data.size() * rate_params.rel_rate);
39  std::vector<unsigned char> punc_buff_34(count);
40  index = 0;
41  for(int x = 0; x < data.size(); x += 6)
42  {
43  punc_buff_34[index++] = data[x + 0];
44  punc_buff_34[index++] = data[x + 1];
45  punc_buff_34[index++] = data[x + 3];
46  punc_buff_34[index++] = data[x + 5];
47  }
48  return punc_buff_34;
49  }
50  break;
51 
52  // Puncture from 1/2 to 2/3
54  {
55  count = round(data.size() * rate_params.rel_rate);
56  std::vector<unsigned char> punc_buff_23(count);
57  index = 0;
58  for(int x = 0; x < data.size(); x += 4)
59  {
60  punc_buff_23[index++] = data[x + 0];
61  punc_buff_23[index++] = data[x + 2];
62  punc_buff_23[index++] = data[x + 3];
63  }
64  return punc_buff_23;
65  }
66  break;
67  }
68  }
69 
78  std::vector<unsigned char> puncturer::depuncture(std::vector<unsigned char> data, RateParams rate_params)
79  {
80  int sym_buffer_index = 0;
81  int psc = 0;
82  switch(rate_params.rate)
83  {
84  // Nothing to do
86  return data;
87  break;
88 
89  // De-puncture from 3/4 to 1/2 coding rate
91  {
92  psc = round(data.size() / rate_params.rel_rate);
93  std::vector<unsigned char> sym_buffer34(psc);
94  for(int x = 0; x < data.size(); x += 4)
95  {
96  sym_buffer34[sym_buffer_index++] = data[x + 0];
97  sym_buffer34[sym_buffer_index++] = data[x + 1];
98  sym_buffer34[sym_buffer_index++] = 127;
99  sym_buffer34[sym_buffer_index++] = data[x + 2];
100  sym_buffer34[sym_buffer_index++] = 127;
101  sym_buffer34[sym_buffer_index++] = data[x + 3];
102  }
103  return sym_buffer34;
104  break;
105  }
106 
107  // De-ouncture from 2/3 to 1/2 coding rate
109  {
110  psc = round(data.size() / rate_params.rel_rate);
111  std::vector<unsigned char> sym_buffer23(psc);
112  for(int x = 0; x < data.size(); x += 3)
113  {
114  sym_buffer23[sym_buffer_index++] = data[x + 0];
115  sym_buffer23[sym_buffer_index++] = 127;
116  sym_buffer23[sym_buffer_index++] = data[x + 1];
117  sym_buffer23[sym_buffer_index++] = data[x + 2];
118  }
119  return sym_buffer23;
120  break;
121  }
122  }
123  }
124 
125 }
126