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 "ns3/log.h"
23 #include "nist-error-rate-model.h"
24 #include "dsss-error-rate-model.h"
25 #include "wifi-phy.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  NS_LOG_FUNCTION (this << snr);
52  double z = std::sqrt (snr);
53  double ber = 0.5 * erfc (z);
54  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
55  return ber;
56 }
57 
58 double
60 {
61  NS_LOG_FUNCTION (this << snr);
62  double z = std::sqrt (snr / 2.0);
63  double ber = 0.5 * erfc (z);
64  NS_LOG_INFO ("qpsk snr=" << snr << " ber=" << ber);
65  return ber;
66 }
67 
68 double
70 {
71  NS_LOG_FUNCTION (this << snr);
72  double z = std::sqrt (snr / (5.0 * 2.0));
73  double ber = 0.75 * 0.5 * erfc (z);
74  NS_LOG_INFO ("16-Qam" << " snr=" << snr << " ber=" << ber);
75  return ber;
76 }
77 
78 double
80 {
81  NS_LOG_FUNCTION (this << snr);
82  double z = std::sqrt (snr / (21.0 * 2.0));
83  double ber = 7.0 / 12.0 * 0.5 * erfc (z);
84  NS_LOG_INFO ("64-Qam" << " snr=" << snr << " ber=" << ber);
85  return ber;
86 }
87 
88 double
90 {
91  NS_LOG_FUNCTION (this << snr);
92  double z = std::sqrt (snr / (85.0 * 2.0));
93  double ber = 15.0 / 32.0 * 0.5 * erfc (z);
94  NS_LOG_INFO ("256-Qam" << " snr=" << snr << " ber=" << ber);
95  return ber;
96 }
97 
98 double
100 {
101  NS_LOG_FUNCTION (this << snr);
102  double z = std::sqrt (snr / (341.0 * 2.0));
103  double ber = 31.0 / 160.0 * 0.5 * erfc (z);
104  NS_LOG_INFO ("1024-Qam" << " snr=" << snr << " ber=" << ber);
105  return ber;
106 }
107 
108 double
109 NistErrorRateModel::GetFecBpskBer (double snr, uint64_t nbits,
110  uint32_t bValue) const
111 {
112  NS_LOG_FUNCTION (this << snr << nbits << bValue);
113  double ber = GetBpskBer (snr);
114  if (ber == 0.0)
115  {
116  return 1.0;
117  }
118  double pe = CalculatePe (ber, bValue);
119  pe = std::min (pe, 1.0);
120  double pms = std::pow (1 - pe, nbits);
121  return pms;
122 }
123 
124 double
125 NistErrorRateModel::GetFecQpskBer (double snr, uint64_t nbits,
126  uint32_t bValue) const
127 {
128  NS_LOG_FUNCTION (this << snr << nbits << bValue);
129  double ber = GetQpskBer (snr);
130  if (ber == 0.0)
131  {
132  return 1.0;
133  }
134  double pe = CalculatePe (ber, bValue);
135  pe = std::min (pe, 1.0);
136  double pms = std::pow (1 - pe, nbits);
137  return pms;
138 }
139 
140 double
141 NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const
142 {
143  NS_LOG_FUNCTION (this << p << bValue);
144  double D = std::sqrt (4.0 * p * (1.0 - p));
145  double pe = 1.0;
146  if (bValue == 1)
147  {
148  //code rate 1/2, use table 3.1.1
149  pe = 0.5 * (36.0 * std::pow (D, 10)
150  + 211.0 * std::pow (D, 12)
151  + 1404.0 * std::pow (D, 14)
152  + 11633.0 * std::pow (D, 16)
153  + 77433.0 * std::pow (D, 18)
154  + 502690.0 * std::pow (D, 20)
155  + 3322763.0 * std::pow (D, 22)
156  + 21292910.0 * std::pow (D, 24)
157  + 134365911.0 * std::pow (D, 26));
158  }
159  else if (bValue == 2)
160  {
161  //code rate 2/3, use table 3.1.2
162  pe = 1.0 / (2.0 * bValue) *
163  (3.0 * std::pow (D, 6)
164  + 70.0 * std::pow (D, 7)
165  + 285.0 * std::pow (D, 8)
166  + 1276.0 * std::pow (D, 9)
167  + 6160.0 * std::pow (D, 10)
168  + 27128.0 * std::pow (D, 11)
169  + 117019.0 * std::pow (D, 12)
170  + 498860.0 * std::pow (D, 13)
171  + 2103891.0 * std::pow (D, 14)
172  + 8784123.0 * std::pow (D, 15));
173  }
174  else if (bValue == 3)
175  {
176  //code rate 3/4, use table 3.1.2
177  pe = 1.0 / (2.0 * bValue) *
178  (42.0 * std::pow (D, 5)
179  + 201.0 * std::pow (D, 6)
180  + 1492.0 * std::pow (D, 7)
181  + 10469.0 * std::pow (D, 8)
182  + 62935.0 * std::pow (D, 9)
183  + 379644.0 * std::pow (D, 10)
184  + 2253373.0 * std::pow (D, 11)
185  + 13073811.0 * std::pow (D, 12)
186  + 75152755.0 * std::pow (D, 13)
187  + 428005675.0 * std::pow (D, 14));
188  }
189  else if (bValue == 5)
190  {
191  //code rate 5/6, use table V from D. Haccoun and G. Begin, "High-Rate Punctured Convolutional Codes
192  //for Viterbi Sequential Decoding", IEEE Transactions on Communications, Vol. 32, Issue 3, pp.315-319.
193  pe = 1.0 / (2.0 * bValue) *
194  (92.0 * std::pow (D, 4.0)
195  + 528.0 * std::pow (D, 5.0)
196  + 8694.0 * std::pow (D, 6.0)
197  + 79453.0 * std::pow (D, 7.0)
198  + 792114.0 * std::pow (D, 8.0)
199  + 7375573.0 * std::pow (D, 9.0)
200  + 67884974.0 * std::pow (D, 10.0)
201  + 610875423.0 * std::pow (D, 11.0)
202  + 5427275376.0 * std::pow (D, 12.0)
203  + 47664215639.0 * std::pow (D, 13.0));
204  }
205  else
206  {
207  NS_ASSERT (false);
208  }
209  return pe;
210 }
211 
212 double
213 NistErrorRateModel::GetFec16QamBer (double snr, uint64_t nbits,
214  uint32_t bValue) const
215 {
216  NS_LOG_FUNCTION (this << snr << nbits << bValue);
217  double ber = Get16QamBer (snr);
218  if (ber == 0.0)
219  {
220  return 1.0;
221  }
222  double pe = CalculatePe (ber, bValue);
223  pe = std::min (pe, 1.0);
224  double pms = std::pow (1 - pe, nbits);
225  return pms;
226 }
227 
228 double
229 NistErrorRateModel::GetFec64QamBer (double snr, uint64_t nbits,
230  uint32_t bValue) const
231 {
232  NS_LOG_FUNCTION (this << snr << nbits << bValue);
233  double ber = Get64QamBer (snr);
234  if (ber == 0.0)
235  {
236  return 1.0;
237  }
238  double pe = CalculatePe (ber, bValue);
239  pe = std::min (pe, 1.0);
240  double pms = std::pow (1 - pe, nbits);
241  return pms;
242 }
243 
244 double
245 NistErrorRateModel::GetFec256QamBer (double snr, uint64_t nbits,
246  uint32_t bValue) const
247 {
248  NS_LOG_FUNCTION (this << snr << nbits << bValue);
249  double ber = Get256QamBer (snr);
250  if (ber == 0.0)
251  {
252  return 1.0;
253  }
254  double pe = CalculatePe (ber, bValue);
255  pe = std::min (pe, 1.0);
256  double pms = std::pow (1 - pe, nbits);
257  return pms;
258 }
259 
260 double
261 NistErrorRateModel::GetFec1024QamBer (double snr, uint64_t nbits,
262  uint32_t bValue) const
263 {
264  NS_LOG_FUNCTION (this << snr << nbits << bValue);
265  double ber = Get1024QamBer (snr);
266  if (ber == 0.0)
267  {
268  return 1.0;
269  }
270  double pe = CalculatePe (ber, bValue);
271  pe = std::min (pe, 1.0);
272  double pms = std::pow (1 - pe, nbits);
273  return pms;
274 }
275 
276 double
277 NistErrorRateModel::GetChunkSuccessRate (WifiMode mode, WifiTxVector txVector, double snr, uint64_t nbits) const
278 {
279  NS_LOG_FUNCTION (this << mode << txVector.GetMode () << snr << nbits);
285  {
286  if (mode.GetConstellationSize () == 2)
287  {
288  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
289  {
290  return GetFecBpskBer (snr,
291  nbits,
292  1); //b value
293  }
294  else
295  {
296  return GetFecBpskBer (snr,
297  nbits,
298  3); //b value
299  }
300  }
301  else if (mode.GetConstellationSize () == 4)
302  {
303  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
304  {
305  return GetFecQpskBer (snr,
306  nbits,
307  1); //b value
308  }
309  else
310  {
311  return GetFecQpskBer (snr,
312  nbits,
313  3); //b value
314  }
315  }
316  else if (mode.GetConstellationSize () == 16)
317  {
318  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
319  {
320  return GetFec16QamBer (snr,
321  nbits,
322  1); //b value
323  }
324  else
325  {
326  return GetFec16QamBer (snr,
327  nbits,
328  3); //b value
329  }
330  }
331  else if (mode.GetConstellationSize () == 64)
332  {
333  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
334  {
335  return GetFec64QamBer (snr,
336  nbits,
337  2); //b value
338  }
339  else if (mode.GetCodeRate () == WIFI_CODE_RATE_5_6)
340  {
341  return GetFec64QamBer (snr,
342  nbits,
343  5); //b value
344  }
345  else
346  {
347  return GetFec64QamBer (snr,
348  nbits,
349  3); //b value
350  }
351  }
352  else if (mode.GetConstellationSize () == 256)
353  {
354  if (mode.GetCodeRate () == WIFI_CODE_RATE_5_6)
355  {
356  return GetFec256QamBer (snr,
357  nbits,
358  5 // b value
359  );
360  }
361  else
362  {
363  return GetFec256QamBer (snr,
364  nbits,
365  3 // b value
366  );
367  }
368  }
369  else if (mode.GetConstellationSize () == 1024)
370  {
371  if (mode.GetCodeRate () == WIFI_CODE_RATE_5_6)
372  {
373  return GetFec1024QamBer (snr,
374  nbits,
375  5 // b value
376  );
377  }
378  else
379  {
380  return GetFec1024QamBer (snr,
381  nbits,
382  3 // b value
383  );
384  }
385  }
386  }
388  {
389  switch (mode.GetDataRate (20))
390  {
391  case 1000000:
393  case 2000000:
395  case 5500000:
397  case 11000000:
399  default:
400  NS_ASSERT ("undefined DSSS/HR-DSSS datarate");
401  }
402  }
403  return 0;
404 }
405 
406 } //namespace ns3
double Get64QamBer(double snr) const
Return BER of QAM64 at the given SNR.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:54
double GetFecQpskBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of QPSK at the given SNR after applying FEC.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
double GetFec16QamBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of QAM16 at the given SNR after applying FEC.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
#define min(a, b)
Definition: 80211b.c:42
#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:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
VHT PHY (Clause 22)
Definition: wifi-mode.h:60
HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:48
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
static double GetDsssDbpskSuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential BPSK.
the interface for Wifi&#39;s error models
double GetFec1024QamBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of QAM1024 at the given SNR after applying FEC.
double GetFecBpskBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of BPSK at the given SNR after applying FEC.
WifiMode GetMode(void) const
HT PHY (Clause 20)
Definition: wifi-mode.h:58
double Get256QamBer(double snr) const
Return BER of QAM256 at the given SNR.
double Get16QamBer(double snr) const
Return BER of QAM16 at the given SNR.
A model for the error rate for different modulations.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:500
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double GetFec64QamBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of QAM64 at the given SNR after applying FEC.
static double GetDsssDqpskCck5_5SuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK for 5.5Mbps data rate.
uint16_t GetConstellationSize(void) const
Definition: wifi-mode.cc:406
double GetFec256QamBer(double snr, uint64_t nbits, uint32_t bValue) const
Return BER of QAM256 at the given SNR after applying FEC.
double GetQpskBer(double snr) const
Return BER of QPSK at the given SNR.
OFDM PHY (Clause 17)
Definition: wifi-mode.h:56
double CalculatePe(double p, uint32_t bValue) const
Return the coded BER for the given p and b.
double Get1024QamBer(double snr) const
Return BER of QAM1024 at the given SNR.
double GetChunkSuccessRate(WifiMode mode, WifiTxVector txVector, double snr, uint64_t nbits) const
A pure virtual method that must be implemented in the subclass.
static double GetDsssDqpskSuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK.
WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:330
double GetBpskBer(double snr) const
Return BER of BPSK at the given SNR.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
HE PHY (Clause 26)
Definition: wifi-mode.h:62
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
DSSS PHY (Clause 15)
Definition: wifi-mode.h:46
static double GetDsssDqpskCck11SuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK for 11Mbps data rate.