A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * Author: Gary Pei <guangyu.pei@boeing.com>
19  */
20 
21 #include <cmath>
22 #include "nist-error-rate-model.h"
23 #include "wifi-phy.h"
24 #include "ns3/log.h"
25 
26 NS_LOG_COMPONENT_DEFINE ("NistErrorRateModel");
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (NistErrorRateModel)
31  ;
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::NistErrorRateModel")
38  .AddConstructor<NistErrorRateModel> ()
39  ;
40  return tid;
41 }
42 
44 {
45 }
46 
47 double
49 {
50  double z = std::sqrt (snr);
51  double ber = 0.5 * erfc (z);
52  NS_LOG_INFO ("bpsk snr=" << snr << " ber=" << ber);
53  return ber;
54 }
55 double
57 {
58  double z = std::sqrt (snr / 2.0);
59  double ber = 0.5 * erfc (z);
60  NS_LOG_INFO ("qpsk snr=" << snr << " ber=" << ber);
61  return ber;
62 }
63 double
65 {
66  double z = std::sqrt (snr / (5.0 * 2.0));
67  double ber = 0.75 * 0.5 * erfc (z);
68  NS_LOG_INFO ("16-Qam" << " snr=" << snr << " ber=" << ber);
69  return ber;
70 }
71 double
73 {
74  double z = std::sqrt (snr / (21.0 * 2.0));
75  double ber = 7.0 / 12.0 * 0.5 * erfc (z);
76  NS_LOG_INFO ("64-Qam" << " snr=" << snr << " ber=" << ber);
77  return ber;
78 }
79 double
80 NistErrorRateModel::GetFecBpskBer (double snr, double nbits,
81  uint32_t bValue) const
82 {
83  double ber = GetBpskBer (snr);
84  if (ber == 0.0)
85  {
86  return 1.0;
87  }
88  double pe = CalculatePe (ber, bValue);
89  pe = std::min (pe, 1.0);
90  double pms = std::pow (1 - pe, nbits);
91  return pms;
92 }
93 double
94 NistErrorRateModel::GetFecQpskBer (double snr, double nbits,
95  uint32_t bValue) const
96 {
97  double ber = GetQpskBer (snr);
98  if (ber == 0.0)
99  {
100  return 1.0;
101  }
102  double pe = CalculatePe (ber, bValue);
103  pe = std::min (pe, 1.0);
104  double pms = std::pow (1 - pe, nbits);
105  return pms;
106 }
107 double
108 NistErrorRateModel::CalculatePe (double p, uint32_t bValue) const
109 {
110  double D = std::sqrt (4.0 * p * (1.0 - p));
111  double pe = 1.0;
112  if (bValue == 1)
113  {
114  // code rate 1/2, use table 3.1.1
115  pe = 0.5 * ( 36.0 * std::pow (D, 10.0)
116  + 211.0 * std::pow (D, 12.0)
117  + 1404.0 * std::pow (D, 14.0)
118  + 11633.0 * std::pow (D, 16.0)
119  + 77433.0 * std::pow (D, 18.0)
120  + 502690.0 * std::pow (D, 20.0)
121  + 3322763.0 * std::pow (D, 22.0)
122  + 21292910.0 * std::pow (D, 24.0)
123  + 134365911.0 * std::pow (D, 26.0)
124  );
125  }
126  else if (bValue == 2)
127  {
128  // code rate 2/3, use table 3.1.2
129  pe = 1.0 / (2.0 * bValue) *
130  ( 3.0 * std::pow (D, 6.0)
131  + 70.0 * std::pow (D, 7.0)
132  + 285.0 * std::pow (D, 8.0)
133  + 1276.0 * std::pow (D, 9.0)
134  + 6160.0 * std::pow (D, 10.0)
135  + 27128.0 * std::pow (D, 11.0)
136  + 117019.0 * std::pow (D, 12.0)
137  + 498860.0 * std::pow (D, 13.0)
138  + 2103891.0 * std::pow (D, 14.0)
139  + 8784123.0 * std::pow (D, 15.0)
140  );
141  }
142  else if (bValue == 3)
143  {
144  // code rate 3/4, use table 3.1.2
145  pe = 1.0 / (2.0 * bValue) *
146  ( 42.0 * std::pow (D, 5.0)
147  + 201.0 * std::pow (D, 6.0)
148  + 1492.0 * std::pow (D, 7.0)
149  + 10469.0 * std::pow (D, 8.0)
150  + 62935.0 * std::pow (D, 9.0)
151  + 379644.0 * std::pow (D, 10.0)
152  + 2253373.0 * std::pow (D, 11.0)
153  + 13073811.0 * std::pow (D, 12.0)
154  + 75152755.0 * std::pow (D, 13.0)
155  + 428005675.0 * std::pow (D, 14.0)
156  );
157  }
158  else
159  {
160  NS_ASSERT (false);
161  }
162  return pe;
163 }
164 
165 double
166 NistErrorRateModel::GetFec16QamBer (double snr, uint32_t nbits,
167  uint32_t bValue) const
168 {
169  double ber = Get16QamBer (snr);
170  if (ber == 0.0)
171  {
172  return 1.0;
173  }
174  double pe = CalculatePe (ber, bValue);
175  pe = std::min (pe, 1.0);
176  double pms = std::pow (1 - pe, static_cast<double> (nbits));
177  return pms;
178 }
179 double
180 NistErrorRateModel::GetFec64QamBer (double snr, uint32_t nbits,
181  uint32_t bValue) const
182 {
183  double ber = Get64QamBer (snr);
184  if (ber == 0.0)
185  {
186  return 1.0;
187  }
188  double pe = CalculatePe (ber, bValue);
189  pe = std::min (pe, 1.0);
190  double pms = std::pow (1 - pe, static_cast<double> (nbits));
191  return pms;
192 }
193 double
194 NistErrorRateModel::GetChunkSuccessRate (WifiMode mode, double snr, uint32_t nbits) const
195 {
198  {
199  if (mode.GetConstellationSize () == 2)
200  {
201  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
202  {
203  return GetFecBpskBer (snr,
204  nbits,
205  1 // b value
206  );
207  }
208  else
209  {
210  return GetFecBpskBer (snr,
211  nbits,
212  3 // b value
213  );
214  }
215  }
216  else if (mode.GetConstellationSize () == 4)
217  {
218  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
219  {
220  return GetFecQpskBer (snr,
221  nbits,
222  1 // b value
223  );
224  }
225  else
226  {
227  return GetFecQpskBer (snr,
228  nbits,
229  3 // b value
230  );
231  }
232  }
233  else if (mode.GetConstellationSize () == 16)
234  {
235  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
236  {
237  return GetFec16QamBer (snr,
238  nbits,
239  1 // b value
240  );
241  }
242  else
243  {
244  return GetFec16QamBer (snr,
245  nbits,
246  3 // b value
247  );
248  }
249  }
250  else if (mode.GetConstellationSize () == 64)
251  {
252  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
253  {
254  return GetFec64QamBer (snr,
255  nbits,
256  2 // b value
257  );
258  }
259  else
260  {
261  return GetFec64QamBer (snr,
262  nbits,
263  3 // b value
264  );
265  }
266  }
267  }
268  else if (mode.GetModulationClass () == WIFI_MOD_CLASS_DSSS)
269  {
270  switch (mode.GetDataRate ())
271  {
272  case 1000000:
274  case 2000000:
276  case 5500000:
278  case 11000000:
280  }
281  }
282  return 0;
283 }
284 
285 } // namespace ns3
double GetQpskBer(double snr) const
Return BER of QPSK at the given SNR.
static double GetDsssDqpskCck11SuccessRate(double sinr, uint32_t nbits)
Return the chunk success rate of the differential encoded QPSK for 11Mbps data rate.
static TypeId GetTypeId(void)
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:52
enum WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:115
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
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
double GetFec64QamBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of QAM64 at the given SNR after applying FEC.
double GetFec16QamBer(double snr, uint32_t nbits, uint32_t bValue) const
Return BER of QAM16 at the given SNR after applying FEC.
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
NS_LOG_COMPONENT_DEFINE("NistErrorRateModel")
double CalculatePe(double p, uint32_t bValue) const
Return the coded BER for the given p and b.
double GetFecBpskBer(double snr, double nbits, uint32_t bValue) const
Return BER of BPSK at the given SNR after applying FEC.
enum WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:85
double Get16QamBer(double snr) const
Return BER of QAM16 at the given SNR.
HT PHY (Clause 20)
Definition: wifi-mode.h:56
uint8_t GetConstellationSize(void) const
Definition: wifi-mode.cc:91
double Get64QamBer(double snr) const
Return BER of QAM64 at the given SNR.
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 GetFecQpskBer(double snr, double nbits, uint32_t bValue) const
Return BER of QPSK at the given SNR after applying FEC.
OFDM PHY (Clause 17)
Definition: wifi-mode.h:54
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
virtual double GetChunkSuccessRate(WifiMode mode, double snr, uint32_t nbits) const
A pure virtual method that must be implemented in the subclass.
double GetBpskBer(double snr) const
Return BER of BPSK at the given SNR.