A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
nist-error-rate-model.cc
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 
21 #include <cmath>
22 #include "nist-error-rate-model.h"
23 #include "wifi-phy.h"
24 #include "ns3/log.h"
25 
26 NS_LOG_COMPONENT_DEFINE ("NistErrorRateModel");
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (NistErrorRateModel);
31 
32 TypeId
33 NistErrorRateModel::GetTypeId (void)
34 {
35  static TypeId tid = TypeId ("ns3::NistErrorRateModel")
36  .SetParent<ErrorRateModel> ()
37  .AddConstructor<NistErrorRateModel> ()
38  ;
39  return tid;
40 }
41 
42 NistErrorRateModel::NistErrorRateModel ()
43 {
44 }
45 
46 double
47 NistErrorRateModel::GetBpskBer (double snr) const
48 {
49  double z = std::sqrt (snr);
50  double ber = 0.5 * erfc (z);
51  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
52  return ber;
53 }
54 double
55 NistErrorRateModel::GetQpskBer (double snr) const
56 {
57  double z = std::sqrt (snr / 2.0);
58  double ber = 0.5 * erfc (z);
59  NS_LOG_INFO ("qpsk snr=" << snr << " ber=" << ber);
60  return ber;
61 }
62 double
63 NistErrorRateModel::Get16QamBer (double snr) const
64 {
65  double z = std::sqrt (snr / (5.0 * 2.0));
66  double ber = 0.75 * 0.5 * erfc (z);
67  NS_LOG_INFO ("16-Qam" << " snr=" << snr << " ber=" << ber);
68  return ber;
69 }
70 double
71 NistErrorRateModel::Get64QamBer (double snr) const
72 {
73  double z = std::sqrt (snr / (21.0 * 2.0));
74  double ber = 7.0 / 12.0 * 0.5 * erfc (z);
75  NS_LOG_INFO ("64-Qam" << " snr=" << snr << " ber=" << ber);
76  return ber;
77 }
78 double
79 NistErrorRateModel::GetFecBpskBer (double snr, double nbits,
80  uint32_t bValue) const
81 {
82  double ber = GetBpskBer (snr);
83  if (ber == 0.0)
84  {
85  return 1.0;
86  }
87  double pe = CalculatePe (ber, bValue);
88  pe = std::min (pe, 1.0);
89  double pms = std::pow (1 - pe, nbits);
90  return pms;
91 }
92 double
93 NistErrorRateModel::GetFecQpskBer (double snr, double nbits,
94  uint32_t bValue) const
95 {
96  double ber = GetQpskBer (snr);
97  if (ber == 0.0)
98  {
99  return 1.0;
100  }
101  double pe = CalculatePe (ber, bValue);
102  pe = std::min (pe, 1.0);
103  double pms = std::pow (1 - pe, nbits);
104  return pms;
105 }
106 double
107 NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const
108 {
109  double D = std::sqrt (4.0 * p * (1.0 - p));
110  double pe = 1.0;
111  if (bValue == 1)
112  {
113  // code rate 1/2, use table 3.1.1
114  pe = 0.5 * ( 36.0 * std::pow (D, 10.0)
115  + 211.0 * std::pow (D, 12.0)
116  + 1404.0 * std::pow (D, 14.0)
117  + 11633.0 * std::pow (D, 16.0)
118  + 77433.0 * std::pow (D, 18.0)
119  + 502690.0 * std::pow (D, 20.0)
120  + 3322763.0 * std::pow (D, 22.0)
121  + 21292910.0 * std::pow (D, 24.0)
122  + 134365911.0 * std::pow (D, 26.0)
123  );
124  }
125  else if (bValue == 2)
126  {
127  // code rate 2/3, use table 3.1.2
128  pe = 1.0 / (2.0 * bValue) *
129  ( 3.0 * std::pow (D, 6.0)
130  + 70.0 * std::pow (D, 7.0)
131  + 285.0 * std::pow (D, 8.0)
132  + 1276.0 * std::pow (D, 9.0)
133  + 6160.0 * std::pow (D, 10.0)
134  + 27128.0 * std::pow (D, 11.0)
135  + 117019.0 * std::pow (D, 12.0)
136  + 498860.0 * std::pow (D, 13.0)
137  + 2103891.0 * std::pow (D, 14.0)
138  + 8784123.0 * std::pow (D, 15.0)
139  );
140  }
141  else if (bValue == 3)
142  {
143  // code rate 3/4, use table 3.1.2
144  pe = 1.0 / (2.0 * bValue) *
145  ( 42.0 * std::pow (D, 5.0)
146  + 201.0 * std::pow (D, 6.0)
147  + 1492.0 * std::pow (D, 7.0)
148  + 10469.0 * std::pow (D, 8.0)
149  + 62935.0 * std::pow (D, 9.0)
150  + 379644.0 * std::pow (D, 10.0)
151  + 2253373.0 * std::pow (D, 11.0)
152  + 13073811.0 * std::pow (D, 12.0)
153  + 75152755.0 * std::pow (D, 13.0)
154  + 428005675.0 * std::pow (D, 14.0)
155  );
156  }
157  else
158  {
159  NS_ASSERT (false);
160  }
161  return pe;
162 }
163 
164 double
165 NistErrorRateModel::GetFec16QamBer (double snr, uint32_t nbits,
166  uint32_t bValue) const
167 {
168  double ber = Get16QamBer (snr);
169  if (ber == 0.0)
170  {
171  return 1.0;
172  }
173  double pe = CalculatePe (ber, bValue);
174  pe = std::min (pe, 1.0);
175  double pms = std::pow (1 - pe, static_cast<double> (nbits));
176  return pms;
177 }
178 double
179 NistErrorRateModel::GetFec64QamBer (double snr, uint32_t nbits,
180  uint32_t bValue) const
181 {
182  double ber = Get64QamBer (snr);
183  if (ber == 0.0)
184  {
185  return 1.0;
186  }
187  double pe = CalculatePe (ber, bValue);
188  pe = std::min (pe, 1.0);
189  double pms = std::pow (1 - pe, static_cast<double> (nbits));
190  return pms;
191 }
192 double
193 NistErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
194 {
195  if (mode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM
196  || mode.GetModulationClass () == WIFI_MOD_CLASS_OFDM)
197  {
198  if (mode.GetConstellationSize () == 2)
199  {
200  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
201  {
202  return GetFecBpskBer (snr,
203  nbits,
204  1 // b value
205  );
206  }
207  else
208  {
209  return GetFecBpskBer (snr,
210  nbits,
211  3 // b value
212  );
213  }
214  }
215  else if (mode.GetConstellationSize () == 4)
216  {
217  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
218  {
219  return GetFecQpskBer (snr,
220  nbits,
221  1 // b value
222  );
223  }
224  else
225  {
226  return GetFecQpskBer (snr,
227  nbits,
228  3 // b value
229  );
230  }
231  }
232  else if (mode.GetConstellationSize () == 16)
233  {
234  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
235  {
236  return GetFec16QamBer (snr,
237  nbits,
238  1 // b value
239  );
240  }
241  else
242  {
243  return GetFec16QamBer (snr,
244  nbits,
245  3 // b value
246  );
247  }
248  }
249  else if (mode.GetConstellationSize () == 64)
250  {
251  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
252  {
253  return GetFec64QamBer (snr,
254  nbits,
255  2 // b value
256  );
257  }
258  else
259  {
260  return GetFec64QamBer (snr,
261  nbits,
262  3 // b value
263  );
264  }
265  }
266  }
267  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
268  {
269  switch (mode.GetDataRate ())
270  {
271  case 1000000:
272  return DsssErrorRateModel::GetDsssDbpskSuccessRate (snr, nbits);
273  case 2000000:
274  return DsssErrorRateModel::GetDsssDqpskSuccessRate (snr, nbits);
275  case 5500000:
276  return DsssErrorRateModel::GetDsssDqpskCck5_5SuccessRate (snr, nbits);
277  case 11000000:
278  return DsssErrorRateModel::GetDsssDqpskCck11SuccessRate (snr, nbits);
279  }
280  }
281  return 0;
282 }
283 
284 } // namespace ns3
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264