A Discrete-Event Network Simulator
API
yans-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) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Sébastien Deronne <sebastien.deronne@gmail.com>
20  */
21 
22 #include <cmath>
23 #include "yans-error-rate-model.h"
24 #include "wifi-phy.h"
25 #include "ns3/log.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("YansErrorRateModel");
30 
31 NS_OBJECT_ENSURE_REGISTERED (YansErrorRateModel);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::YansErrorRateModel")
38  .SetGroupName ("Wifi")
39  .AddConstructor<YansErrorRateModel> ()
40  ;
41  return tid;
42 }
43 
45 {
46 }
47 
48 double
49 YansErrorRateModel::Log2 (double val) const
50 {
51  return std::log (val) / std::log (2.0);
52 }
53 
54 double
55 YansErrorRateModel::GetBpskBer (double snr, uint32_t signalSpread, uint32_t phyRate) const
56 {
57  double EbNo = snr * signalSpread / phyRate;
58  double z = std::sqrt (EbNo);
59  double ber = 0.5 * erfc (z);
60  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
61  return ber;
62 }
63 
64 double
65 YansErrorRateModel::GetQamBer (double snr, unsigned int m, uint32_t signalSpread, uint32_t phyRate) const
66 {
67  double EbNo = snr * signalSpread / phyRate;
68  double z = std::sqrt ((1.5 * Log2 (m) * EbNo) / (m - 1.0));
69  double z1 = ((1.0 - 1.0 / std::sqrt (m)) * erfc (z));
70  double z2 = 1 - std::pow ((1 - z1), 2);
71  double ber = z2 / Log2 (m);
72  NS_LOG_INFO ("Qam m=" << m << " rate=" << phyRate << " snr=" << snr << " ber=" << ber);
73  return ber;
74 }
75 
76 uint32_t
78 {
79  uint32_t fact = 1;
80  while (k > 0)
81  {
82  fact *= k;
83  k--;
84  }
85  return fact;
86 }
87 
88 double
89 YansErrorRateModel::Binomial (uint32_t k, double p, uint32_t n) const
90 {
91  double retval = Factorial (n) / (Factorial (k) * Factorial (n - k)) * std::pow (p, static_cast<double> (k)) * std::pow (1 - p, static_cast<double> (n - k));
92  return retval;
93 }
94 
95 double
96 YansErrorRateModel::CalculatePdOdd (double ber, unsigned int d) const
97 {
98  NS_ASSERT ((d % 2) == 1);
99  unsigned int dstart = (d + 1) / 2;
100  unsigned int dend = d;
101  double pd = 0;
102 
103  for (unsigned int i = dstart; i < dend; i++)
104  {
105  pd += Binomial (i, ber, d);
106  }
107  return pd;
108 }
109 
110 double
111 YansErrorRateModel::CalculatePdEven (double ber, unsigned int d) const
112 {
113  NS_ASSERT ((d % 2) == 0);
114  unsigned int dstart = d / 2 + 1;
115  unsigned int dend = d;
116  double pd = 0;
117 
118  for (unsigned int i = dstart; i < dend; i++)
119  {
120  pd += Binomial (i, ber, d);
121  }
122  pd += 0.5 * Binomial (d / 2, ber, d);
123 
124  return pd;
125 }
126 
127 double
128 YansErrorRateModel::CalculatePd (double ber, unsigned int d) const
129 {
130  double pd;
131  if ((d % 2) == 0)
132  {
133  pd = CalculatePdEven (ber, d);
134  }
135  else
136  {
137  pd = CalculatePdOdd (ber, d);
138  }
139  return pd;
140 }
141 
142 double
143 YansErrorRateModel::GetFecBpskBer (double snr, double nbits,
144  uint32_t signalSpread, uint32_t phyRate,
145  uint32_t dFree, uint32_t adFree) const
146 {
147  double ber = GetBpskBer (snr, signalSpread, phyRate);
148  if (ber == 0.0)
149  {
150  return 1.0;
151  }
152  double pd = CalculatePd (ber, dFree);
153  double pmu = adFree * pd;
154  pmu = std::min (pmu, 1.0);
155  double pms = std::pow (1 - pmu, nbits);
156  return pms;
157 }
158 
159 double
160 YansErrorRateModel::GetFecQamBer (double snr, uint32_t nbits,
161  uint32_t signalSpread,
162  uint32_t phyRate,
163  uint32_t m, uint32_t dFree,
164  uint32_t adFree, uint32_t adFreePlusOne) const
165 {
166  double ber = GetQamBer (snr, m, signalSpread, phyRate);
167  if (ber == 0.0)
168  {
169  return 1.0;
170  }
171  /* first term */
172  double pd = CalculatePd (ber, dFree);
173  double pmu = adFree * pd;
174  /* second term */
175  pd = CalculatePd (ber, dFree + 1);
176  pmu += adFreePlusOne * pd;
177  pmu = std::min (pmu, 1.0);
178  double pms = std::pow (1 - pmu, static_cast<double> (nbits));
179  return pms;
180 }
181 
182 double
183 YansErrorRateModel::GetChunkSuccessRate (WifiMode mode, WifiTxVector txVector, double snr, uint32_t nbits) const
184 {
189  {
190  if (mode.GetConstellationSize (1) == 2)
191  {
192  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_1_2)
193  {
194  return GetFecBpskBer (snr,
195  nbits,
196  txVector.GetChannelWidth () * 1000000, //signal spread
197  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
198  10, //dFree
199  11); //adFree
200  }
201  else
202  {
203  return GetFecBpskBer (snr,
204  nbits,
205  txVector.GetChannelWidth () * 1000000, //signal spread
206  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
207  5, //dFree
208  8); //adFree
209  }
210  }
211  else if (mode.GetConstellationSize (1) == 4)
212  {
213  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_1_2)
214  {
215  return GetFecQamBer (snr,
216  nbits,
217  txVector.GetChannelWidth () * 1000000, //signal spread
218  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
219  4, //m
220  10, //dFree
221  11, //adFree
222  0); //adFreePlusOne
223  }
224  else
225  {
226  return GetFecQamBer (snr,
227  nbits,
228  txVector.GetChannelWidth () * 1000000, //signal spread
229  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
230  4, //m
231  5, //dFree
232  8, //adFree
233  31); //adFreePlusOne
234  }
235  }
236  else if (mode.GetConstellationSize (1) == 16)
237  {
238  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_1_2)
239  {
240  return GetFecQamBer (snr,
241  nbits,
242  txVector.GetChannelWidth () * 1000000, //signal spread
243  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
244  16, //m
245  10, //dFree
246  11, //adFree
247  0); //adFreePlusOne
248  }
249  else
250  {
251  return GetFecQamBer (snr,
252  nbits,
253  txVector.GetChannelWidth () * 1000000, //signal spread
254  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
255  16, //m
256  5, //dFree
257  8, //adFree
258  31); //adFreePlusOne
259  }
260  }
261  else if (mode.GetConstellationSize (1) == 64)
262  {
263  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_2_3)
264  {
265  return GetFecQamBer (snr,
266  nbits,
267  txVector.GetChannelWidth () * 1000000, //signal spread
268  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
269  64, //m
270  6, //dFree
271  1, //adFree
272  16); //adFreePlusOne
273  }
274  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_5_6)
275  {
276  //Table B.32 in Pâl Frenger et al., "Multi-rate Convolutional Codes".
277  return GetFecQamBer (snr,
278  nbits,
279  txVector.GetChannelWidth () * 1000000, //signal spread
280  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
281  64, //m
282  4, //dFree
283  14, //adFree
284  69); //adFreePlusOne
285  }
286  else
287  {
288  return GetFecQamBer (snr,
289  nbits,
290  txVector.GetChannelWidth () * 1000000, //signal spread
291  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), //phy rate
292  64, //m
293  5, //dFree
294  8, //adFree
295  31); //adFreePlusOne
296  }
297  }
298  else if (mode.GetConstellationSize (1) == 256)
299  {
300  if (mode.GetCodeRate (1) == WIFI_CODE_RATE_5_6)
301  {
302  return GetFecQamBer (snr,
303  nbits,
304  txVector.GetChannelWidth () * 1000000, // signal spread
305  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), // phy rate
306  256, // m
307  4, // dFree
308  14, // adFree
309  69 // adFreePlusOne
310  );
311  }
312  else
313  {
314  return GetFecQamBer (snr,
315  nbits,
316  txVector.GetChannelWidth () * 1000000, // signal spread
317  mode.GetPhyRate (txVector.GetChannelWidth (), txVector.IsShortGuardInterval (), 1), // phy rate
318  256, // m
319  5, // dFree
320  8, // adFree
321  31 // adFreePlusOne
322  );
323  }
324  }
325  }
327  {
328  switch (mode.GetDataRate (20, 0, 1))
329  {
330  case 1000000:
332  case 2000000:
334  case 5500000:
336  case 11000000:
338  default:
339  NS_ASSERT ("undefined DSSS/HR-DSSS datarate");
340  }
341  }
342  return 0;
343 }
344 
345 } //namespace ns3
static TypeId GetTypeId(void)
double CalculatePdEven(double ber, unsigned int d) const
static double GetDsssDqpskCck11SuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK for 11Mbps data rate.
double CalculatePd(double ber, unsigned int d) const
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:56
enum WifiCodeRate GetCodeRate(uint8_t nss) const
Definition: wifi-mode.cc:227
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
double GetFecBpskBer(double snr, double nbits, uint32_t signalSpread, uint32_t phyRate, uint32_t dFree, uint32_t adFree) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
uint16_t GetConstellationSize(uint8_t nss) const
Definition: wifi-mode.cc:282
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:375
#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
double CalculatePdOdd(double ber, unsigned int d) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
double GetQamBer(double snr, unsigned int m, uint32_t signalSpread, uint32_t phyRate) const
Return BER of QAM-m with the given parameters.
bool IsShortGuardInterval(void) const
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
VHT PHY (Clause 22)
Definition: wifi-mode.h:62
HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:50
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
the interface for Wifi's error models
double GetFecQamBer(double snr, uint32_t nbits, uint32_t signalSpread, uint32_t phyRate, uint32_t m, uint32_t dfree, uint32_t adFree, uint32_t adFreePlusOne) const
uint64_t GetPhyRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
Definition: wifi-mode.cc:73
Model the error rate for different modulations.
uint32_t GetChannelWidth(void) const
HT PHY (Clause 20)
Definition: wifi-mode.h:60
virtual double GetChunkSuccessRate(WifiMode mode, WifiTxVector txVector, double snr, uint32_t nbits) const
A pure virtual method that must be implemented in the subclass.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double Log2(double val) const
Return the logarithm of the given value to base 2.
uint64_t GetDataRate(uint32_t channelWidth, bool isShortGuardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
uint32_t Factorial(uint32_t k) const
Return k!
static double GetDsssDqpskCck5_5SuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK for 5.5Mbps data rate.
double GetBpskBer(double snr, uint32_t signalSpread, uint32_t phyRate) const
Return BER of BPSK with the given parameters.
OFDM PHY (Clause 17)
Definition: wifi-mode.h:58
double Binomial(uint32_t k, double p, uint32_t n) const
Return Binomial distribution for a given k, p, and n.
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
DSSS PHY (Clause 15)
Definition: wifi-mode.h:48