A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
nist-error-rate-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 The Boeing Company
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Gary Pei <guangyu.pei@boeing.com>
19  */
20 #include "nist-error-rate-model.h"
21 #include "wifi-phy.h"
22 #include "ns3/log.h"
23 
24 NS_LOG_COMPONENT_DEFINE ("NistErrorRateModel");
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (NistErrorRateModel);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::NistErrorRateModel")
35  .AddConstructor<NistErrorRateModel> ()
36  ;
37  return tid;
38 }
39 
41 {
42 }
43 
44 double
46 {
47  double z = sqrt (snr);
48  double ber = 0.5 * erfc (z);
49  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
50  return ber;
51 }
52 double
54 {
55  double z = sqrt (snr / 2.0);
56  double ber = 0.5 * erfc (z);
57  NS_LOG_INFO ("qpsk snr=" << snr << " ber=" << ber);
58  return ber;
59 }
60 double
62 {
63  double z = sqrt (snr / (5.0 * 2.0));
64  double ber = 0.75 * 0.5 * erfc (z);
65  NS_LOG_INFO ("16-Qam" << " snr=" << snr << " ber=" << ber);
66  return ber;
67 }
68 double
70 {
71  double z = sqrt (snr / (21.0 * 2.0));
72  double ber = 7.0 / 12.0 * 0.5 * erfc (z);
73  NS_LOG_INFO ("64-Qam" << " snr=" << snr << " ber=" << ber);
74  return ber;
75 }
76 double
77 NistErrorRateModel::GetFecBpskBer (double snr, double nbits,
78  uint32_t bValue) const
79 {
80  double ber = GetBpskBer (snr);
81  if (ber == 0.0)
82  {
83  return 1.0;
84  }
85  double pe = CalculatePe (ber, bValue);
86  pe = std::min (pe, 1.0);
87  double pms = pow (1 - pe, nbits);
88  return pms;
89 }
90 double
91 NistErrorRateModel::GetFecQpskBer (double snr, double nbits,
92  uint32_t bValue) const
93 {
94  double ber = GetQpskBer (snr);
95  if (ber == 0.0)
96  {
97  return 1.0;
98  }
99  double pe = CalculatePe (ber, bValue);
100  pe = std::min (pe, 1.0);
101  double pms = pow (1 - pe, nbits);
102  return pms;
103 }
104 double
105 NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const
106 {
107  double D = sqrt (4.0 * p * (1.0 - p));
108  double pe = 1.0;
109  if (bValue == 1)
110  {
111  // code rate 1/2, use table 3.1.1
112  pe = 0.5 * ( 36.0 * pow (D, 10.0)
113  + 211.0 * pow (D, 12.0)
114  + 1404.0 * pow (D, 14.0)
115  + 11633.0 * pow (D, 16.0)
116  + 77433.0 * pow (D, 18.0)
117  + 502690.0 * pow (D, 20.0)
118  + 3322763.0 * pow (D, 22.0)
119  + 21292910.0 * pow (D, 24.0)
120  + 134365911.0 * pow (D, 26.0)
121  );
122  }
123  else if (bValue == 2)
124  {
125  // code rate 2/3, use table 3.1.2
126  pe = 1.0 / (2.0 * bValue) *
127  ( 3.0 * pow (D, 6.0)
128  + 70.0 * pow (D, 7.0)
129  + 285.0 * pow (D, 8.0)
130  + 1276.0 * pow (D, 9.0)
131  + 6160.0 * pow (D, 10.0)
132  + 27128.0 * pow (D, 11.0)
133  + 117019.0 * pow (D, 12.0)
134  + 498860.0 * pow (D, 13.0)
135  + 2103891.0 * pow (D, 14.0)
136  + 8784123.0 * pow (D, 15.0)
137  );
138  }
139  else if (bValue == 3)
140  {
141  // code rate 3/4, use table 3.1.2
142  pe = 1.0 / (2.0 * bValue) *
143  ( 42.0 * pow (D, 5.0)
144  + 201.0 * pow (D, 6.0)
145  + 1492.0 * pow (D, 7.0)
146  + 10469.0 * pow (D, 8.0)
147  + 62935.0 * pow (D, 9.0)
148  + 379644.0 * pow (D, 10.0)
149  + 2253373.0 * pow (D, 11.0)
150  + 13073811.0 * pow (D, 12.0)
151  + 75152755.0 * pow (D, 13.0)
152  + 428005675.0 * pow (D, 14.0)
153  );
154  }
155  else
156  {
157  NS_ASSERT (false);
158  }
159  return pe;
160 }
161 
162 double
163 NistErrorRateModel::GetFec16QamBer (double snr, uint32_t nbits,
164  uint32_t bValue) const
165 {
166  double ber = Get16QamBer (snr);
167  if (ber == 0.0)
168  {
169  return 1.0;
170  }
171  double pe = CalculatePe (ber, bValue);
172  pe = std::min (pe, 1.0);
173  double pms = pow (1 - pe, nbits);
174  return pms;
175 }
176 double
177 NistErrorRateModel::GetFec64QamBer (double snr, uint32_t nbits,
178  uint32_t bValue) const
179 {
180  double ber = Get64QamBer (snr);
181  if (ber == 0.0)
182  {
183  return 1.0;
184  }
185  double pe = CalculatePe (ber, bValue);
186  pe = std::min (pe, 1.0);
187  double pms = pow (1 - pe, nbits);
188  return pms;
189 }
190 double
191 NistErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
192 {
195  {
196  if (mode.GetConstellationSize () == 2)
197  {
198  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
199  {
200  return GetFecBpskBer (snr,
201  nbits,
202  1 // b value
203  );
204  }
205  else
206  {
207  return GetFecBpskBer (snr,
208  nbits,
209  3 // b value
210  );
211  }
212  }
213  else if (mode.GetConstellationSize () == 4)
214  {
215  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
216  {
217  return GetFecQpskBer (snr,
218  nbits,
219  1 // b value
220  );
221  }
222  else
223  {
224  return GetFecQpskBer (snr,
225  nbits,
226  3 // b value
227  );
228  }
229  }
230  else if (mode.GetConstellationSize () == 16)
231  {
232  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
233  {
234  return GetFec16QamBer (snr,
235  nbits,
236  1 // b value
237  );
238  }
239  else
240  {
241  return GetFec16QamBer (snr,
242  nbits,
243  3 // b value
244  );
245  }
246  }
247  else if (mode.GetConstellationSize () == 64)
248  {
249  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
250  {
251  return GetFec64QamBer (snr,
252  nbits,
253  2 // b value
254  );
255  }
256  else
257  {
258  return GetFec64QamBer (snr,
259  nbits,
260  3 // b value
261  );
262  }
263  }
264  }
265  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
266  {
267  switch (mode.GetDataRate ())
268  {
269  case 1000000:
271  case 2000000:
273  case 5500000:
275  case 11000000:
277  }
278  }
279  return 0;
280 }
281 
282 } // namespace ns3