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  .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 double
54 YansErrorRateModel::GetBpskBer (double snr, uint32_t signalSpread, uint32_t phyRate) const
55 {
56  double EbNo = snr * signalSpread / phyRate;
57  double z = std::sqrt (EbNo);
58  double ber = 0.5 * erfc (z);
59  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
60  return ber;
61 }
62 double
63 YansErrorRateModel::GetQamBer (double snr, unsigned int m, uint32_t signalSpread, uint32_t phyRate) const
64 {
65  double EbNo = snr * signalSpread / phyRate;
66  double z = std::sqrt ((1.5 * Log2 (m) * EbNo) / (m - 1.0));
67  double z1 = ((1.0 - 1.0 / std::sqrt (m)) * erfc (z));
68  double z2 = 1 - std::pow ((1 - z1), 2);
69  double ber = z2 / Log2 (m);
70  NS_LOG_INFO ("Qam m=" << m << " rate=" << phyRate << " snr=" << snr << " ber=" << ber);
71  return ber;
72 }
73 uint32_t
75 {
76  uint32_t fact = 1;
77  while (k > 0)
78  {
79  fact *= k;
80  k--;
81  }
82  return fact;
83 }
84 double
85 YansErrorRateModel::Binomial (uint32_t k, double p, uint32_t n) const
86 {
87  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));
88  return retval;
89 }
90 double
91 YansErrorRateModel::CalculatePdOdd (double ber, unsigned int d) const
92 {
93  NS_ASSERT ((d % 2) == 1);
94  unsigned int dstart = (d + 1) / 2;
95  unsigned int dend = d;
96  double pd = 0;
97 
98  for (unsigned int i = dstart; i < dend; i++)
99  {
100  pd += Binomial (i, ber, d);
101  }
102  return pd;
103 }
104 double
105 YansErrorRateModel::CalculatePdEven (double ber, unsigned int d) const
106 {
107  NS_ASSERT ((d % 2) == 0);
108  unsigned int dstart = d / 2 + 1;
109  unsigned int dend = d;
110  double pd = 0;
111 
112  for (unsigned int i = dstart; i < dend; i++)
113  {
114  pd += Binomial (i, ber, d);
115  }
116  pd += 0.5 * Binomial (d / 2, ber, d);
117 
118  return pd;
119 }
120 
121 double
122 YansErrorRateModel::CalculatePd (double ber, unsigned int d) const
123 {
124  double pd;
125  if ((d % 2) == 0)
126  {
127  pd = CalculatePdEven (ber, d);
128  }
129  else
130  {
131  pd = CalculatePdOdd (ber, d);
132  }
133  return pd;
134 }
135 
136 double
137 YansErrorRateModel::GetFecBpskBer (double snr, double nbits,
138  uint32_t signalSpread, uint32_t phyRate,
139  uint32_t dFree, uint32_t adFree) const
140 {
141  double ber = GetBpskBer (snr, signalSpread, phyRate);
142  if (ber == 0.0)
143  {
144  return 1.0;
145  }
146  double pd = CalculatePd (ber, dFree);
147  double pmu = adFree * pd;
148  pmu = std::min (pmu, 1.0);
149  double pms = std::pow (1 - pmu, nbits);
150  return pms;
151 }
152 
153 double
154 YansErrorRateModel::GetFecQamBer (double snr, uint32_t nbits,
155  uint32_t signalSpread,
156  uint32_t phyRate,
157  uint32_t m, uint32_t dFree,
158  uint32_t adFree, uint32_t adFreePlusOne) const
159 {
160  double ber = GetQamBer (snr, m, signalSpread, phyRate);
161  if (ber == 0.0)
162  {
163  return 1.0;
164  }
165  /* first term */
166  double pd = CalculatePd (ber, dFree);
167  double pmu = adFree * pd;
168  /* second term */
169  pd = CalculatePd (ber, dFree + 1);
170  pmu += adFreePlusOne * pd;
171  pmu = std::min (pmu, 1.0);
172  double pms = std::pow (1 - pmu, static_cast<double> (nbits));
173  return pms;
174 }
175 
176 double
177 YansErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
178 {
182  {
183  if (mode.GetConstellationSize () == 2)
184  {
185  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
186  {
187  return GetFecBpskBer (snr,
188  nbits,
189  mode.GetBandwidth (), // signal spread
190  mode.GetPhyRate (), // phy rate
191  10, // dFree
192  11 // adFree
193  );
194  }
195  else
196  {
197  return GetFecBpskBer (snr,
198  nbits,
199  mode.GetBandwidth (), // signal spread
200  mode.GetPhyRate (), // phy rate
201  5, // dFree
202  8 // adFree
203  );
204  }
205  }
206  else if (mode.GetConstellationSize () == 4)
207  {
208  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
209  {
210  return GetFecQamBer (snr,
211  nbits,
212  mode.GetBandwidth (), // signal spread
213  mode.GetPhyRate (), // phy rate
214  4, // m
215  10, // dFree
216  11, // adFree
217  0 // adFreePlusOne
218  );
219  }
220  else
221  {
222  return GetFecQamBer (snr,
223  nbits,
224  mode.GetBandwidth (), // signal spread
225  mode.GetPhyRate (), // phy rate
226  4, // m
227  5, // dFree
228  8, // adFree
229  31 // adFreePlusOne
230  );
231  }
232  }
233  else if (mode.GetConstellationSize () == 16)
234  {
235  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
236  {
237  return GetFecQamBer (snr,
238  nbits,
239  mode.GetBandwidth (), // signal spread
240  mode.GetPhyRate (), // phy rate
241  16, // m
242  10, // dFree
243  11, // adFree
244  0 // adFreePlusOne
245  );
246  }
247  else
248  {
249  return GetFecQamBer (snr,
250  nbits,
251  mode.GetBandwidth (), // signal spread
252  mode.GetPhyRate (), // phy rate
253  16, // m
254  5, // dFree
255  8, // adFree
256  31 // adFreePlusOne
257  );
258  }
259  }
260  else if (mode.GetConstellationSize () == 64)
261  {
262  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
263  {
264  return GetFecQamBer (snr,
265  nbits,
266  mode.GetBandwidth (), // signal spread
267  mode.GetPhyRate (), // phy rate
268  64, // m
269  6, // dFree
270  1, // adFree
271  16 // adFreePlusOne
272  );
273  }
274  if (mode.GetCodeRate () == 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  mode.GetBandwidth (), // signal spread
280  mode.GetPhyRate (), // phy rate
281  64, // m
282  4, // dFree
283  14, // adFree
284  69 // adFreePlusOne
285  );
286  }
287  else
288  {
289  return GetFecQamBer (snr,
290  nbits,
291  mode.GetBandwidth (), // signal spread
292  mode.GetPhyRate (), // phy rate
293  64, // m
294  5, // dFree
295  8, // adFree
296  31 // adFreePlusOne
297  );
298  }
299  }
300  }
301  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
302  {
303  switch (mode.GetDataRate ())
304  {
305  case 1000000:
307  case 2000000:
309  case 5500000:
311  case 11000000:
313  }
314  }
315  return 0;
316 }
317 
318 } // 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:61
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
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:51
uint64_t GetDataRate(void) const
Definition: wifi-mode.cc:79
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:46