A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nist-error-rate-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Gary Pei <guangyu.pei@boeing.com>
7 * Sébastien Deronne <sebastien.deronne@gmail.com>
8 */
9
11
12#include "wifi-tx-vector.h"
13
14#include "ns3/log.h"
15
16#include <bitset>
17#include <cmath>
18
19namespace ns3
20{
21
22NS_LOG_COMPONENT_DEFINE("NistErrorRateModel");
23
24NS_OBJECT_ENSURE_REGISTERED(NistErrorRateModel);
25
26TypeId
28{
29 static TypeId tid = TypeId("ns3::NistErrorRateModel")
31 .SetGroupName("Wifi")
32 .AddConstructor<NistErrorRateModel>();
33 return tid;
34}
35
39
40double
42{
43 NS_LOG_FUNCTION(this << snr);
44 double z = std::sqrt(snr);
45 double ber = 0.5 * erfc(z);
46 NS_LOG_INFO("bpsk snr=" << snr << " ber=" << ber);
47 return ber;
48}
49
50double
52{
53 NS_LOG_FUNCTION(this << snr);
54 double z = std::sqrt(snr / 2.0);
55 double ber = 0.5 * erfc(z);
56 NS_LOG_INFO("qpsk snr=" << snr << " ber=" << ber);
57 return ber;
58}
59
60double
61NistErrorRateModel::GetQamBer(uint16_t constellationSize, double snr) const
62{
63 NS_LOG_FUNCTION(this << constellationSize << snr);
64 NS_ASSERT(std::bitset<16>(constellationSize).count() ==
65 1); // constellationSize has to be a power of 2
66 double z = std::sqrt(snr / ((2 * (constellationSize - 1)) / 3));
67 uint8_t bitsPerSymbol = std::sqrt(constellationSize);
68 double ber = ((bitsPerSymbol - 1) / (bitsPerSymbol * std::log2(bitsPerSymbol))) * erfc(z);
69 NS_LOG_INFO(constellationSize << "-QAM: snr=" << snr << " ber=" << ber);
70 return ber;
71}
72
73double
74NistErrorRateModel::GetFecBpskBer(double snr, uint64_t nbits, uint8_t bValue) const
75{
76 NS_LOG_FUNCTION(this << snr << nbits << +bValue);
77 double ber = GetBpskBer(snr);
78 if (ber == 0.0)
79 {
80 return 1.0;
81 }
82 double pe = CalculatePe(ber, bValue);
83 pe = std::min(pe, 1.0);
84 double pms = std::pow(1 - pe, nbits);
85 return pms;
86}
87
88double
89NistErrorRateModel::GetFecQpskBer(double snr, uint64_t nbits, uint8_t bValue) const
90{
91 NS_LOG_FUNCTION(this << snr << nbits << +bValue);
92 double ber = GetQpskBer(snr);
93 if (ber == 0.0)
94 {
95 return 1.0;
96 }
97 double pe = CalculatePe(ber, bValue);
98 pe = std::min(pe, 1.0);
99 double pms = std::pow(1 - pe, nbits);
100 return pms;
101}
102
103double
104NistErrorRateModel::CalculatePe(double p, uint8_t bValue) const
105{
106 NS_LOG_FUNCTION(this << p << +bValue);
107 double D = std::sqrt(4.0 * p * (1.0 - p));
108 double pe = 1.0;
109 if (bValue == 1)
110 {
111 // code rate 1/2, use table 3.1.1
112 pe = 0.5 * (36.0 * std::pow(D, 10) + 211.0 * std::pow(D, 12) + 1404.0 * std::pow(D, 14) +
113 11633.0 * std::pow(D, 16) + 77433.0 * std::pow(D, 18) +
114 502690.0 * std::pow(D, 20) + 3322763.0 * std::pow(D, 22) +
115 21292910.0 * std::pow(D, 24) + 134365911.0 * std::pow(D, 26));
116 }
117 else if (bValue == 2)
118 {
119 // code rate 2/3, use table 3.1.2
120 pe = 1.0 / (2.0 * bValue) *
121 (3.0 * std::pow(D, 6) + 70.0 * std::pow(D, 7) + 285.0 * std::pow(D, 8) +
122 1276.0 * std::pow(D, 9) + 6160.0 * std::pow(D, 10) + 27128.0 * std::pow(D, 11) +
123 117019.0 * std::pow(D, 12) + 498860.0 * std::pow(D, 13) +
124 2103891.0 * std::pow(D, 14) + 8784123.0 * std::pow(D, 15));
125 }
126 else if (bValue == 3)
127 {
128 // code rate 3/4, use table 3.1.2
129 pe = 1.0 / (2.0 * bValue) *
130 (42.0 * std::pow(D, 5) + 201.0 * std::pow(D, 6) + 1492.0 * std::pow(D, 7) +
131 10469.0 * std::pow(D, 8) + 62935.0 * std::pow(D, 9) + 379644.0 * std::pow(D, 10) +
132 2253373.0 * std::pow(D, 11) + 13073811.0 * std::pow(D, 12) +
133 75152755.0 * std::pow(D, 13) + 428005675.0 * std::pow(D, 14));
134 }
135 else if (bValue == 5)
136 {
137 // code rate 5/6, use table V from D. Haccoun and G. Begin, "High-Rate Punctured
138 // Convolutional Codes for Viterbi Sequential Decoding", IEEE Transactions on
139 // Communications, Vol. 32, Issue 3, pp.315-319.
140 pe = 1.0 / (2.0 * bValue) *
141 (92.0 * std::pow(D, 4.0) + 528.0 * std::pow(D, 5.0) + 8694.0 * std::pow(D, 6.0) +
142 79453.0 * std::pow(D, 7.0) + 792114.0 * std::pow(D, 8.0) +
143 7375573.0 * std::pow(D, 9.0) + 67884974.0 * std::pow(D, 10.0) +
144 610875423.0 * std::pow(D, 11.0) + 5427275376.0 * std::pow(D, 12.0) +
145 47664215639.0 * std::pow(D, 13.0));
146 }
147 else
148 {
149 NS_ASSERT(false);
150 }
151 return pe;
152}
153
154double
155NistErrorRateModel::GetFecQamBer(uint16_t constellationSize,
156 double snr,
157 uint64_t nbits,
158 uint8_t bValue) const
159{
160 NS_LOG_FUNCTION(this << constellationSize << snr << nbits << +bValue);
161 double ber = GetQamBer(constellationSize, snr);
162 if (ber == 0.0)
163 {
164 return 1.0;
165 }
166 double pe = CalculatePe(ber, bValue);
167 pe = std::min(pe, 1.0);
168 double pms = std::pow(1 - pe, nbits);
169 return pms;
170}
171
172uint8_t
174{
175 switch (codeRate)
176 {
178 return 3;
180 return 2;
182 return 1;
184 return 5;
186 default:
187 NS_FATAL_ERROR("Unknown code rate");
188 break;
189 }
190 return 0;
191}
192
193double
195 const WifiTxVector& txVector,
196 double snr,
197 uint64_t nbits,
198 uint8_t numRxAntennas,
199 WifiPpduField field,
200 uint16_t staId) const
201{
202 NS_LOG_FUNCTION(this << mode << snr << nbits << +numRxAntennas << field << staId);
204 {
205 if (mode.GetConstellationSize() == 2)
206 {
207 return GetFecBpskBer(snr, nbits, GetBValue(mode.GetCodeRate()));
208 }
209 else if (mode.GetConstellationSize() == 4)
210 {
211 return GetFecQpskBer(snr, nbits, GetBValue(mode.GetCodeRate()));
212 }
213 else
214 {
216 snr,
217 nbits,
218 GetBValue(mode.GetCodeRate()));
219 }
220 }
221 return 0;
222}
223
224} // namespace ns3
the interface for Wifi's error models
A model for the error rate for different modulations.
static TypeId GetTypeId()
Get the type ID.
double GetQamBer(uint16_t constellationSize, double snr) const
Return BER of QAM for a given constellation size at the given SNR.
double GetBpskBer(double snr) const
Return BER of BPSK at the given SNR.
double GetFecBpskBer(double snr, uint64_t nbits, uint8_t bValue) const
Return BER of BPSK at the given SNR after applying FEC.
double CalculatePe(double p, uint8_t bValue) const
Return the coded BER for the given p and b.
double GetFecQpskBer(double snr, uint64_t nbits, uint8_t bValue) const
Return BER of QPSK at the given SNR after applying FEC.
double GetFecQamBer(uint16_t constellationSize, double snr, uint64_t nbits, uint8_t bValue) const
Return BER of QAM for a given constellation size at the given SNR after applying FEC.
uint8_t GetBValue(WifiCodeRate codeRate) const
Return the bValue such that coding rate = bValue / (bValue + 1).
double DoGetChunkSuccessRate(WifiMode mode, const WifiTxVector &txVector, double snr, uint64_t nbits, uint8_t numRxAntennas, WifiPpduField field, uint16_t staId) const override
A pure virtual method that must be implemented in the subclass.
double GetQpskBer(double snr) const
Return BER of QPSK at the given SNR.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
represent a single transmission mode
Definition wifi-mode.h:40
uint16_t GetConstellationSize() const
Definition wifi-mode.cc:130
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
WifiCodeRate GetCodeRate() const
Definition wifi-mode.cc:123
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
WifiPpduField
The type of PPDU field (grouped for convenience)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
@ WIFI_CODE_RATE_2_3
2/3 coding rate
@ WIFI_CODE_RATE_1_2
1/2 coding rate
@ WIFI_CODE_RATE_3_4
3/4 coding rate
@ WIFI_CODE_RATE_UNDEFINED
undefined coding rate
@ WIFI_CODE_RATE_5_6
5/6 coding rate