A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  */
20 
21 #include <cmath>
22 
23 #include "yans-error-rate-model.h"
24 #include "wifi-phy.h"
25 #include "ns3/log.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("YansErrorRateModel");
28 
29 namespace ns3 {
30 
31 NS_OBJECT_ENSURE_REGISTERED (YansErrorRateModel)
32  ;
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.0);
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 {
181  {
182  if (mode.GetConstellationSize () == 2)
183  {
184  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
185  {
186  return GetFecBpskBer (snr,
187  nbits,
188  mode.GetBandwidth (), // signal spread
189  mode.GetPhyRate (), // phy rate
190  10, // dFree
191  11 // adFree
192  );
193  }
194  else
195  {
196  return GetFecBpskBer (snr,
197  nbits,
198  mode.GetBandwidth (), // signal spread
199  mode.GetPhyRate (), // phy rate
200  5, // dFree
201  8 // adFree
202  );
203  }
204  }
205  else if (mode.GetConstellationSize () == 4)
206  {
207  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
208  {
209  return GetFecQamBer (snr,
210  nbits,
211  mode.GetBandwidth (), // signal spread
212  mode.GetPhyRate (), // phy rate
213  4, // m
214  10, // dFree
215  11, // adFree
216  0 // adFreePlusOne
217  );
218  }
219  else
220  {
221  return GetFecQamBer (snr,
222  nbits,
223  mode.GetBandwidth (), // signal spread
224  mode.GetPhyRate (), // phy rate
225  4, // m
226  5, // dFree
227  8, // adFree
228  31 // adFreePlusOne
229  );
230  }
231  }
232  else if (mode.GetConstellationSize () == 16)
233  {
234  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
235  {
236  return GetFecQamBer (snr,
237  nbits,
238  mode.GetBandwidth (), // signal spread
239  mode.GetPhyRate (), // phy rate
240  16, // m
241  10, // dFree
242  11, // adFree
243  0 // adFreePlusOne
244  );
245  }
246  else
247  {
248  return GetFecQamBer (snr,
249  nbits,
250  mode.GetBandwidth (), // signal spread
251  mode.GetPhyRate (), // phy rate
252  16, // m
253  5, // dFree
254  8, // adFree
255  31 // adFreePlusOne
256  );
257  }
258  }
259  else if (mode.GetConstellationSize () == 64)
260  {
261  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
262  {
263  return GetFecQamBer (snr,
264  nbits,
265  mode.GetBandwidth (), // signal spread
266  mode.GetPhyRate (), // phy rate
267  64, // m
268  6, // dFree
269  1, // adFree
270  16 // adFreePlusOne
271  );
272  }
273  else
274  {
275  return GetFecQamBer (snr,
276  nbits,
277  mode.GetBandwidth (), // signal spread
278  mode.GetPhyRate (), // phy rate
279  64, // m
280  5, // dFree
281  8, // adFree
282  31 // adFreePlusOne
283  );
284  }
285  }
286  }
287  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
288  {
289  switch (mode.GetDataRate ())
290  {
291  case 1000000:
293  case 2000000:
295  case 5500000:
297  case 11000000:
299  }
300  }
301  return 0;
302 }
303 
304 } // 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
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:115
#define NS_ASSERT(condition)
Definition: assert.h:64
double CalculatePdOdd(double ber, unsigned int d) const
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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)
Definition: log.h:298
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
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
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
NS_LOG_COMPONENT_DEFINE("YansErrorRateModel")
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:49
uint64_t GetDataRate(void) const
Definition: wifi-mode.cc:79
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:46