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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Sébastien Deronne <sebastien.deronne@gmail.com>
20  */
21 
22 #include <cmath>
23 
24 #include "yans-error-rate-model.h"
25 #include "wifi-phy.h"
26 #include "ns3/log.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("YansErrorRateModel");
31 
32 NS_OBJECT_ENSURE_REGISTERED (YansErrorRateModel);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::YansErrorRateModel")
39  .SetGroupName ("Wifi")
40  .AddConstructor<YansErrorRateModel> ()
41  ;
42  return tid;
43 }
44 
46 {
47 }
48 
49 double
50 YansErrorRateModel::Log2 (double val) const
51 {
52  return std::log (val) / std::log (2.0);
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 double
64 YansErrorRateModel::GetQamBer (double snr, unsigned int m, uint32_t signalSpread, uint32_t phyRate) const
65 {
66  double EbNo = snr * signalSpread / phyRate;
67  double z = std::sqrt ((1.5 * Log2 (m) * EbNo) / (m - 1.0));
68  double z1 = ((1.0 - 1.0 / std::sqrt (m)) * erfc (z));
69  double z2 = 1 - std::pow ((1 - z1), 2);
70  double ber = z2 / Log2 (m);
71  NS_LOG_INFO ("Qam m=" << m << " rate=" << phyRate << " snr=" << snr << " ber=" << ber);
72  return ber;
73 }
74 uint32_t
76 {
77  uint32_t fact = 1;
78  while (k > 0)
79  {
80  fact *= k;
81  k--;
82  }
83  return fact;
84 }
85 double
86 YansErrorRateModel::Binomial (uint32_t k, double p, uint32_t n) const
87 {
88  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));
89  return retval;
90 }
91 double
92 YansErrorRateModel::CalculatePdOdd (double ber, unsigned int d) const
93 {
94  NS_ASSERT ((d % 2) == 1);
95  unsigned int dstart = (d + 1) / 2;
96  unsigned int dend = d;
97  double pd = 0;
98 
99  for (unsigned int i = dstart; i < dend; i++)
100  {
101  pd += Binomial (i, ber, d);
102  }
103  return pd;
104 }
105 double
106 YansErrorRateModel::CalculatePdEven (double ber, unsigned int d) const
107 {
108  NS_ASSERT ((d % 2) == 0);
109  unsigned int dstart = d / 2 + 1;
110  unsigned int dend = d;
111  double pd = 0;
112 
113  for (unsigned int i = dstart; i < dend; i++)
114  {
115  pd += Binomial (i, ber, d);
116  }
117  pd += 0.5 * Binomial (d / 2, ber, d);
118 
119  return pd;
120 }
121 
122 double
123 YansErrorRateModel::CalculatePd (double ber, unsigned int d) const
124 {
125  double pd;
126  if ((d % 2) == 0)
127  {
128  pd = CalculatePdEven (ber, d);
129  }
130  else
131  {
132  pd = CalculatePdOdd (ber, d);
133  }
134  return pd;
135 }
136 
137 double
138 YansErrorRateModel::GetFecBpskBer (double snr, double nbits,
139  uint32_t signalSpread, uint32_t phyRate,
140  uint32_t dFree, uint32_t adFree) const
141 {
142  double ber = GetBpskBer (snr, signalSpread, phyRate);
143  if (ber == 0.0)
144  {
145  return 1.0;
146  }
147  double pd = CalculatePd (ber, dFree);
148  double pmu = adFree * pd;
149  pmu = std::min (pmu, 1.0);
150  double pms = std::pow (1 - pmu, nbits);
151  return pms;
152 }
153 
154 double
155 YansErrorRateModel::GetFecQamBer (double snr, uint32_t nbits,
156  uint32_t signalSpread,
157  uint32_t phyRate,
158  uint32_t m, uint32_t dFree,
159  uint32_t adFree, uint32_t adFreePlusOne) const
160 {
161  double ber = GetQamBer (snr, m, signalSpread, phyRate);
162  if (ber == 0.0)
163  {
164  return 1.0;
165  }
166  /* first term */
167  double pd = CalculatePd (ber, dFree);
168  double pmu = adFree * pd;
169  /* second term */
170  pd = CalculatePd (ber, dFree + 1);
171  pmu += adFreePlusOne * pd;
172  pmu = std::min (pmu, 1.0);
173  double pms = std::pow (1 - pmu, static_cast<double> (nbits));
174  return pms;
175 }
176 
177 double
178 YansErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
179 {
183  {
184  if (mode.GetConstellationSize () == 2)
185  {
186  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
187  {
188  return GetFecBpskBer (snr,
189  nbits,
190  mode.GetBandwidth (), // signal spread
191  mode.GetPhyRate (), // phy rate
192  10, // dFree
193  11 // adFree
194  );
195  }
196  else
197  {
198  return GetFecBpskBer (snr,
199  nbits,
200  mode.GetBandwidth (), // signal spread
201  mode.GetPhyRate (), // phy rate
202  5, // dFree
203  8 // adFree
204  );
205  }
206  }
207  else if (mode.GetConstellationSize () == 4)
208  {
209  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
210  {
211  return GetFecQamBer (snr,
212  nbits,
213  mode.GetBandwidth (), // signal spread
214  mode.GetPhyRate (), // phy rate
215  4, // m
216  10, // dFree
217  11, // adFree
218  0 // adFreePlusOne
219  );
220  }
221  else
222  {
223  return GetFecQamBer (snr,
224  nbits,
225  mode.GetBandwidth (), // signal spread
226  mode.GetPhyRate (), // phy rate
227  4, // m
228  5, // dFree
229  8, // adFree
230  31 // adFreePlusOne
231  );
232  }
233  }
234  else if (mode.GetConstellationSize () == 16)
235  {
236  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
237  {
238  return GetFecQamBer (snr,
239  nbits,
240  mode.GetBandwidth (), // signal spread
241  mode.GetPhyRate (), // phy rate
242  16, // m
243  10, // dFree
244  11, // adFree
245  0 // adFreePlusOne
246  );
247  }
248  else
249  {
250  return GetFecQamBer (snr,
251  nbits,
252  mode.GetBandwidth (), // signal spread
253  mode.GetPhyRate (), // phy rate
254  16, // m
255  5, // dFree
256  8, // adFree
257  31 // adFreePlusOne
258  );
259  }
260  }
261  else if (mode.GetConstellationSize () == 64)
262  {
263  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
264  {
265  return GetFecQamBer (snr,
266  nbits,
267  mode.GetBandwidth (), // signal spread
268  mode.GetPhyRate (), // phy rate
269  64, // m
270  6, // dFree
271  1, // adFree
272  16 // adFreePlusOne
273  );
274  }
275  if (mode.GetCodeRate () == WIFI_CODE_RATE_5_6)
276  {
277  //Table B.32 in Pâl Frenger et al., "Multi-rate Convolutional Codes".
278  return GetFecQamBer (snr,
279  nbits,
280  mode.GetBandwidth (), // signal spread
281  mode.GetPhyRate (), // phy rate
282  64, // m
283  4, // dFree
284  14, // adFree
285  69 // adFreePlusOne
286  );
287  }
288  else
289  {
290  return GetFecQamBer (snr,
291  nbits,
292  mode.GetBandwidth (), // signal spread
293  mode.GetPhyRate (), // phy rate
294  64, // m
295  5, // dFree
296  8, // adFree
297  31 // adFreePlusOne
298  );
299  }
300  }
301  }
302  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
303  {
304  switch (mode.GetDataRate ())
305  {
306  case 1000000:
308  case 2000000:
310  case 5500000:
312  case 11000000:
314  }
315  }
316  return 0;
317 }
318 
319 } // 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:52
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
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
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.
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
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 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
Model the error rate for different modulations.
enum WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:85
HT PHY (Clause 20)
Definition: wifi-mode.h:56
virtual double GetChunkSuccessRate(WifiMode mode, double snr, uint32_t nbits) const
A pure virtual method that must be implemented in the subclass.
uint32_t GetBandwidth(void) const
Definition: wifi-mode.cc:67
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t GetConstellationSize(void) const
Definition: wifi-mode.cc:91
uint64_t GetPhyRate(void) const
Definition: wifi-mode.cc:73
double Log2(double val) const
Return the logarithm of the given value to base 2.
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:54
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: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