A Discrete-Event Network Simulator
API
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  * Authors: Gary Pei <guangyu.pei@boeing.com>
19  * Sébastien Deronne <sebastien.deronne@gmail.com>
20  */
21 
22 #include <cmath>
23 #include "nist-error-rate-model.h"
24 #include "wifi-phy.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("NistErrorRateModel");
30 
31 NS_OBJECT_ENSURE_REGISTERED (NistErrorRateModel);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::NistErrorRateModel")
38  .SetGroupName ("Wifi")
39  .AddConstructor<NistErrorRateModel> ()
40  ;
41  return tid;
42 }
43 
45 {
46 }
47 
48 double
50 {
51  double z = std::sqrt (snr);
52  double ber = 0.5 * erfc (z);
53  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
54  return ber;
55 }
56 double
58 {
59  double z = std::sqrt (snr / 2.0);
60  double ber = 0.5 * erfc (z);
61  NS_LOG_INFO ("qpsk snr=" << snr << " ber=" << ber);
62  return ber;
63 }
64 double
66 {
67  double z = std::sqrt (snr / (5.0 * 2.0));
68  double ber = 0.75 * 0.5 * erfc (z);
69  NS_LOG_INFO ("16-Qam" << " snr=" << snr << " ber=" << ber);
70  return ber;
71 }
72 double
74 {
75  double z = std::sqrt (snr / (21.0 * 2.0));
76  double ber = 7.0 / 12.0 * 0.5 * erfc (z);
77  NS_LOG_INFO ("64-Qam" << " snr=" << snr << " ber=" << ber);
78  return ber;
79 }
80 double
81 NistErrorRateModel::GetFecBpskBer (double snr, uint32_t nbits,
82  uint32_t bValue) const
83 {
84  double ber = GetBpskBer (snr);
85  if (ber == 0.0)
86  {
87  return 1.0;
88  }
89  double pe = CalculatePe (ber, bValue);
90  pe = std::min (pe, 1.0);
91  double pms = std::pow (1 - pe, (double)nbits);
92  return pms;
93 }
94 double
95 NistErrorRateModel::GetFecQpskBer (double snr, uint32_t nbits,
96  uint32_t bValue) const
97 {
98  double ber = GetQpskBer (snr);
99  if (ber == 0.0)
100  {
101  return 1.0;
102  }
103  double pe = CalculatePe (ber, bValue);
104  pe = std::min (pe, 1.0);
105  double pms = std::pow (1 - pe, (double)nbits);
106  return pms;
107 }
108 double
109 NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const
110 {
111  double D = std::sqrt (4.0 * p * (1.0 - p));
112  double pe = 1.0;
113  if (bValue == 1)
114  {
115  // code rate 1/2, use table 3.1.1
116  pe = 0.5 * ( 36.0 * std::pow (D, 10)
117  + 211.0 * std::pow (D, 12)
118  + 1404.0 * std::pow (D, 14)
119  + 11633.0 * std::pow (D, 16)
120  + 77433.0 * std::pow (D, 18)
121  + 502690.0 * std::pow (D, 20)
122  + 3322763.0 * std::pow (D, 22)
123  + 21292910.0 * std::pow (D, 24)
124  + 134365911.0 * std::pow (D, 26)
125  );
126  }
127  else if (bValue == 2)
128  {
129  // code rate 2/3, use table 3.1.2
130  pe = 1.0 / (2.0 * bValue) *
131  ( 3.0 * std::pow (D, 6)
132  + 70.0 * std::pow (D, 7)
133  + 285.0 * std::pow (D, 8)
134  + 1276.0 * std::pow (D, 9)
135  + 6160.0 * std::pow (D, 10)
136  + 27128.0 * std::pow (D, 11)
137  + 117019.0 * std::pow (D, 12)
138  + 498860.0 * std::pow (D, 13)
139  + 2103891.0 * std::pow (D, 14)
140  + 8784123.0 * std::pow (D, 15)
141  );
142  }
143  else if (bValue == 3)
144  {
145  // code rate 3/4, use table 3.1.2
146  pe = 1.0 / (2.0 * bValue) *
147  ( 42.0 * std::pow (D, 5)
148  + 201.0 * std::pow (D, 6)
149  + 1492.0 * std::pow (D, 7)
150  + 10469.0 * std::pow (D, 8)
151  + 62935.0 * std::pow (D, 9)
152  + 379644.0 * std::pow (D, 10)
153  + 2253373.0 * std::pow (D, 11)
154  + 13073811.0 * std::pow (D, 12)
155  + 75152755.0 * std::pow (D, 13)
156  + 428005675.0 * std::pow (D, 14)
157  );
158  }
159  else if (bValue == 5)
160  {
161  // code rate 5/6, use table V from D. Haccoun and G. Begin, "High-Rate Punctured Convolutional Codes
162  // for Viterbi Sequential Decoding", IEEE Transactions on Communications, Vol. 32, Issue 3, pp.315-319.
163  pe = 1.0 / (2.0 * bValue) *
164  ( 92.0 * std::pow (D, 4.0)
165  + 528.0 * std::pow (D, 5.0)
166  + 8694.0 * std::pow (D, 6.0)
167  + 79453.0 * std::pow (D, 7.0)
168  + 792114.0 * std::pow (D, 8.0)
169  + 7375573.0 * std::pow (D, 9.0)
170  + 67884974.0 * std::pow (D, 10.0)
171  + 610875423.0 * std::pow (D, 11.0)
172  + 5427275376.0 * std::pow (D, 12.0)
173  + 47664215639.0 * std::pow (D, 13.0)
174  );
175  }
176  else
177  {
178  NS_ASSERT (false);
179  }
180  return pe;
181 }
182 
183 double
184 NistErrorRateModel::GetFec16QamBer (double snr, uint32_t nbits,
185  uint32_t bValue) const
186 {
187  double ber = Get16QamBer (snr);
188  if (ber == 0.0)
189  {
190  return 1.0;
191  }
192  double pe = CalculatePe (ber, bValue);
193  pe = std::min (pe, 1.0);
194  double pms = std::pow (1 - pe, static_cast<double> (nbits));
195  return pms;
196 }
197 double
198 NistErrorRateModel::GetFec64QamBer (double snr, uint32_t nbits,
199  uint32_t bValue) const
200 {
201  double ber = Get64QamBer (snr);
202  if (ber == 0.0)
203  {
204  return 1.0;
205  }
206  double pe = CalculatePe (ber, bValue);
207  pe = std::min (pe, 1.0);
208  double pms = std::pow (1 - pe, static_cast<double> (nbits));
209  return pms;
210 }
211 double
212 NistErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
213 {
216  {
217  if (mode.GetConstellationSize () == 2)
218  {
219  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
220  {
221  return GetFecBpskBer (snr,
222  nbits,
223  1 // b value
224  );
225  }
226  else
227  {
228  return GetFecBpskBer (snr,
229  nbits,
230  3 // b value
231  );
232  }
233  }
234  else if (mode.GetConstellationSize () == 4)
235  {
236  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
237  {
238  return GetFecQpskBer (snr,
239  nbits,
240  1 // b value
241  );
242  }
243  else
244  {
245  return GetFecQpskBer (snr,
246  nbits,
247  3 // b value
248  );
249  }
250  }
251  else if (mode.GetConstellationSize () == 16)
252  {
253  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
254  {
255  return GetFec16QamBer (snr,
256  nbits,
257  1 // b value
258  );
259  }
260  else
261  {
262  return GetFec16QamBer (snr,
263  nbits,
264  3 // b value
265  );
266  }
267  }
268  else if (mode.GetConstellationSize () == 64)
269  {
270  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
271  {
272  return GetFec64QamBer (snr,
273  nbits,
274  2 // b value
275  );
276  }
277  else if (mode.GetCodeRate () == WIFI_CODE_RATE_5_6)
278  {
279  return GetFec64QamBer (snr,
280  nbits,
281  5 // b value
282  );
283  }
284  else
285  {
286  return GetFec64QamBer (snr,
287  nbits,
288  3 // b value
289  );
290  }
291  }
292  }
293  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
294  {
295  switch (mode.GetDataRate ())
296  {
297  case 1000000:
299  case 2000000:
301  case 5500000:
303  case 11000000:
305  }
306  }
307  return 0;
308 }
309 
310 } // namespace ns3
double GetQpskBer(double snr) const
Return BER of QPSK at the given SNR.
static double GetDsssDqpskCck11SuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK for 11Mbps data rate.
static TypeId GetTypeId(void)
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:52
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:115
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
static double GetDsssDqpskSuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
double GetFec64QamBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of QAM64 at the given SNR after applying FEC.
double GetFec16QamBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of QAM16 at the given SNR after applying FEC.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:93
the interface for Wifi's error models
double CalculatePe(double p, uint32_t bValue) const
Return the coded BER for the given p and b.
enum WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:85
double Get16QamBer(double snr) const
Return BER of QAM16 at the given SNR.
HT PHY (Clause 20)
Definition: wifi-mode.h:56
A model for the error rate for different modulations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetConstellationSize(void) const
Definition: wifi-mode.cc:91
double GetFecQpskBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of QPSK at the given SNR after applying FEC.
double Get64QamBer(double snr) const
Return BER of QAM64 at the given SNR.
static double GetDsssDqpskCck5_5SuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK for 5.5Mbps data rate.
OFDM PHY (Clause 17)
Definition: wifi-mode.h:54
double GetFecBpskBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of BPSK at the given SNR after applying FEC.
static double GetDsssDbpskSuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential BPSK.
a unique identifier for an interface.
Definition: type-id.h:57
uint64_t GetDataRate(void) const
Definition: wifi-mode.cc:79
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:46
virtual double GetChunkSuccessRate(WifiMode mode, double snr, uint32_t nbits) const
A pure virtual method that must be implemented in the subclass.
double GetBpskBer(double snr) const
Return BER of BPSK at the given SNR.