A Discrete-Event Network Simulator
API
dsss-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 "ns3/log.h"
23#include <cmath>
24
25namespace ns3 {
26
27NS_LOG_COMPONENT_DEFINE ("DsssErrorRateModel");
28
29#ifndef HAVE_GSL
30const double DsssErrorRateModel::WLAN_SIR_PERFECT = 10.0;
32#endif
33
34double
36{
38 return ((std::sqrt (2.0) + 1.0) / std::sqrt (8.0 * M_PI * std::sqrt (2.0)))
39 * (1.0 / std::sqrt (x)) * std::exp ( -(2.0 - std::sqrt (2.0)) * x);
40}
41
42double
44{
46 double EbN0 = sinr * 22000000.0 / 1000000.0; //1 bit per symbol with 1 MSPS
47 double ber = 0.5 * std::exp (-EbN0);
48 return std::pow ((1.0 - ber), static_cast<double> (nbits));
49}
50
51double
53{
55 double EbN0 = sinr * 22000000.0 / 1000000.0 / 2.0; //2 bits per symbol, 1 MSPS
56 double ber = DqpskFunction (EbN0);
57 return std::pow ((1.0 - ber), static_cast<double> (nbits));
58}
59
60double
62{
64#ifdef HAVE_GSL
65 //symbol error probability
66 double EbN0 = sinr * 22000000.0 / 1375000.0 / 4.0;
67 double sep = SymbolErrorProb16Cck (4.0 * EbN0 / 2.0);
68 return std::min (1.0, std::pow (1.0 - sep, nbits / 4.0));
69#else
70 NS_LOG_WARN ("Running a 802.11b CCK Matlab model less accurate than GSL model");
71 //The Matlab model
72 double ber;
73 if (sinr > WLAN_SIR_PERFECT)
74 {
75 ber = 0.0;
76 }
77 else if (sinr < WLAN_SIR_IMPOSSIBLE)
78 {
79 ber = 0.5;
80 }
81 else
82 {
83 //fitprops.coeff from Matlab berfit
84 double a1 = 5.3681634344056195e-001;
85 double a2 = 3.3092430025608586e-003;
86 double a3 = 4.1654372361004000e-001;
87 double a4 = 1.0288981434358866e+000;
88 ber = a1 * std::exp (-std::pow ((sinr - a2) / a3, a4));
89 }
90 return std::min (1.0, std::pow ((1.0 - ber), static_cast<double> (nbits)));
91#endif
92}
93
94double
96{
98#ifdef HAVE_GSL
99 NS_LOG_DEBUG ("GSL enabled ");
100 //symbol error probability
101 double EbN0 = sinr * 22000000.0 / 1375000.0 / 8.0;
102 double sep = SymbolErrorProb256Cck (8.0 * EbN0 / 2.0);
103 return std::min (1.0, std::pow (1.0 - sep, nbits / 8.0));
104#else
105 NS_LOG_WARN ("Running a 802.11b CCK Matlab model less accurate than GSL model");
106 //The Matlab model
107 double ber;
108 if (sinr > WLAN_SIR_PERFECT)
109 {
110 ber = 0.0;
111 }
112 else if (sinr < WLAN_SIR_IMPOSSIBLE)
113 {
114 ber = 0.5;
115 }
116 else
117 {
118 //fitprops.coeff from Matlab berfit
119 double a1 = 7.9056742265333456e-003;
120 double a2 = -1.8397449399176360e-001;
121 double a3 = 1.0740689468707241e+000;
122 double a4 = 1.0523316904502553e+000;
123 double a5 = 3.0552298746496687e-001;
124 double a6 = 2.2032715128698435e+000;
125 ber = (a1 * sinr * sinr + a2 * sinr + a3) / (sinr * sinr * sinr + a4 * sinr * sinr + a5 * sinr + a6);
126 }
127 return std::min (1.0, std::pow ((1.0 - ber), static_cast<double> (nbits)));
128#endif
129}
130
131#ifdef HAVE_GSL
132double
133IntegralFunction (double x, void *params)
134{
135 double beta = ((FunctionParameters *) params)->beta;
136 double n = ((FunctionParameters *) params)->n;
137 double IntegralFunction = std::pow (2 * gsl_cdf_ugaussian_P (x + beta) - 1, n - 1)
138 * std::exp (-x * x / 2.0) / std::sqrt (2.0 * M_PI);
139 return IntegralFunction;
140}
141
142double
143DsssErrorRateModel::SymbolErrorProb16Cck (double e2)
144{
145 double sep;
146 double error;
147
148 FunctionParameters params;
149 params.beta = std::sqrt (2.0 * e2);
150 params.n = 8.0;
151
152 gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
153
154 gsl_function F;
155 F.function = &IntegralFunction;
156 F.params = &params;
157
158 gsl_integration_qagiu (&F,-params.beta, 0, 1e-7, 1000, w, &sep, &error);
159 gsl_integration_workspace_free (w);
160 if (error == 0.0)
161 {
162 sep = 1.0;
163 }
164
165 return 1.0 - sep;
166}
167
168double DsssErrorRateModel::SymbolErrorProb256Cck (double e1)
169{
170 return 1.0 - std::pow (1.0 - SymbolErrorProb16Cck (e1 / 2.0), 2.0);
171}
172
173#endif
174
175} //namespace ns3
#define min(a, b)
Definition: 80211b.c:42
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:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:265
Every class exported by the ns3 library is enclosed in the ns3 namespace.
list x
Random number samples.