A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsss-error-rate-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 The Boeing Company
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Gary Pei <guangyu.pei@boeing.com>
18 */
19
21
22#include "ns3/log.h"
23
24#include <cmath>
25
26#ifdef HAVE_GSL
27#include <gsl/gsl_cdf.h>
28#include <gsl/gsl_integration.h>
29#include <gsl/gsl_math.h>
30#include <gsl/gsl_sf_bessel.h>
31#endif
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("DsssErrorRateModel");
37
38#ifndef HAVE_GSL
39const double DsssErrorRateModel::WLAN_SIR_PERFECT = 10.0;
41#endif
42
43double
45{
47 return ((M_SQRT2 + 1.0) / std::sqrt(8.0 * M_PI * M_SQRT2)) * (1.0 / std::sqrt(x)) *
48 std::exp(-(2.0 - M_SQRT2) * x);
49}
50
51double
53{
55 double EbN0 = sinr * 22000000.0 / 1000000.0; // 1 bit per symbol with 1 MSPS
56 double ber = 0.5 * std::exp(-EbN0);
57 return std::pow((1.0 - ber), static_cast<double>(nbits));
58}
59
60double
62{
64 double EbN0 = sinr * 22000000.0 / 1000000.0 / 2.0; // 2 bits per symbol, 1 MSPS
65 double ber = DqpskFunction(EbN0);
66 return std::pow((1.0 - ber), static_cast<double>(nbits));
67}
68
69double
71{
73#ifdef HAVE_GSL
74 // symbol error probability
75 double EbN0 = sinr * 22000000.0 / 1375000.0 / 4.0;
76 double sep = SymbolErrorProb16Cck(4.0 * EbN0 / 2.0);
77 return std::min(1.0, std::pow(1.0 - sep, nbits / 4.0));
78#else
79 NS_LOG_WARN("Running a 802.11b CCK Matlab model less accurate than GSL model");
80 // The Matlab model
81 double ber;
82 if (sinr > WLAN_SIR_PERFECT)
83 {
84 ber = 0.0;
85 }
86 else if (sinr < WLAN_SIR_IMPOSSIBLE)
87 {
88 ber = 0.5;
89 }
90 else
91 {
92 // fitprops.coeff from Matlab berfit
93 double a1 = 5.3681634344056195e-001;
94 double a2 = 3.3092430025608586e-003;
95 double a3 = 4.1654372361004000e-001;
96 double a4 = 1.0288981434358866e+000;
97 ber = a1 * std::exp(-std::pow((sinr - a2) / a3, a4));
98 }
99 return std::min(1.0, std::pow((1.0 - ber), static_cast<double>(nbits)));
100#endif
101}
102
103double
105{
107#ifdef HAVE_GSL
108 NS_LOG_DEBUG("GSL enabled ");
109 // symbol error probability
110 double EbN0 = sinr * 22000000.0 / 1375000.0 / 8.0;
111 double sep = SymbolErrorProb256Cck(8.0 * EbN0 / 2.0);
112 return std::min(1.0, std::pow(1.0 - sep, nbits / 8.0));
113#else
114 NS_LOG_WARN("Running a 802.11b CCK Matlab model less accurate than GSL model");
115 // The Matlab model
116 double ber;
117 if (sinr > WLAN_SIR_PERFECT)
118 {
119 ber = 0.0;
120 }
121 else if (sinr < WLAN_SIR_IMPOSSIBLE)
122 {
123 ber = 0.5;
124 }
125 else
126 {
127 // fitprops.coeff from Matlab berfit
128 double a1 = 7.9056742265333456e-003;
129 double a2 = -1.8397449399176360e-001;
130 double a3 = 1.0740689468707241e+000;
131 double a4 = 1.0523316904502553e+000;
132 double a5 = 3.0552298746496687e-001;
133 double a6 = 2.2032715128698435e+000;
134 ber = (a1 * sinr * sinr + a2 * sinr + a3) /
135 (sinr * sinr * sinr + a4 * sinr * sinr + a5 * sinr + a6);
136 }
137 return std::min(1.0, std::pow((1.0 - ber), static_cast<double>(nbits)));
138#endif
139}
140
141#ifdef HAVE_GSL
142double
143IntegralFunction(double x, void* params)
144{
145 double beta = ((FunctionParameters*)params)->beta;
146 double n = ((FunctionParameters*)params)->n;
147 double IntegralFunction = std::pow(2 * gsl_cdf_ugaussian_P(x + beta) - 1, n - 1) *
148 std::exp(-x * x / 2.0) / std::sqrt(2.0 * M_PI);
149 return IntegralFunction;
150}
151
152double
153DsssErrorRateModel::SymbolErrorProb16Cck(double e2)
154{
155 double sep;
156 double error;
157
158 FunctionParameters params;
159 params.beta = std::sqrt(2.0 * e2);
160 params.n = 8.0;
161
162 gsl_integration_workspace* w = gsl_integration_workspace_alloc(1000);
163
164 gsl_function F;
165 F.function = &IntegralFunction;
166 F.params = &params;
167
168 gsl_integration_qagiu(&F, -params.beta, 0, 1e-7, 1000, w, &sep, &error);
169 gsl_integration_workspace_free(w);
170 if (error == 0.0)
171 {
172 sep = 1.0;
173 }
174
175 return 1.0 - sep;
176}
177
178double
179DsssErrorRateModel::SymbolErrorProb256Cck(double e1)
180{
181 return 1.0 - std::pow(1.0 - SymbolErrorProb16Cck(e1 / 2.0), 2.0);
182}
183
184#endif
185
186} // namespace ns3
static double GetDsssDqpskSuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK.
static const double WLAN_SIR_PERFECT
WLAN perfect.
static double GetDsssDbpskSuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential BPSK.
static double GetDsssDqpskCck5_5SuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK for 5.5Mbps data rate.
static double GetDsssDqpskCck11SuccessRate(double sinr, uint64_t nbits)
Return the chunk success rate of the differential encoded QPSK for 11Mbps data rate.
static const double WLAN_SIR_IMPOSSIBLE
WLAN impossible.
static double DqpskFunction(double x)
A function DQPSK.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
Every class exported by the ns3 library is enclosed in the ns3 namespace.