A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
22 #include "dsss-error-rate-model.h"
23 #include <cmath>
24 
25 NS_LOG_COMPONENT_DEFINE ("DsssErrorRateModel");
26 
27 namespace ns3 {
28 
29 #ifndef ENABLE_GSL
30 const double DsssErrorRateModel::WLAN_SIR_PERFECT = 10.0;
32 #endif
33 
34 double
36 {
37  return ((std::sqrt (2.0) + 1.0) / std::sqrt (8.0 * 3.1415926 * std::sqrt (2.0)))
38  * (1.0 / std::sqrt (x)) * std::exp ( -(2.0 - std::sqrt (2.0)) * x);
39 }
40 
41 double
42 DsssErrorRateModel::GetDsssDbpskSuccessRate (double sinr, uint32_t nbits)
43 {
44  double EbN0 = sinr * 22000000.0 / 1000000.0; // 1 bit per symbol with 1 MSPS
45  double ber = 0.5 * std::exp (-EbN0);
46  return std::pow ((1.0 - ber), static_cast<double> (nbits));
47 }
48 
49 double
50 DsssErrorRateModel::GetDsssDqpskSuccessRate (double sinr,uint32_t nbits)
51 {
52  double EbN0 = sinr * 22000000.0 / 1000000.0 / 2.0; // 2 bits per symbol, 1 MSPS
53  double ber = DqpskFunction (EbN0);
54  return std::pow ((1.0 - ber), static_cast<double> (nbits));
55 }
56 
57 double
59 {
60 #ifdef ENABLE_GSL
61  // symbol error probability
62  double EbN0 = sinr * 22000000.0 / 1375000.0 / 4.0;
63  double sep = SymbolErrorProb16Cck (4.0 * EbN0 / 2.0);
64  return std::pow (1.0 - sep,nbits / 4.0);
65 #else
66  NS_LOG_WARN ("Running a 802.11b CCK Matlab model less accurate than GSL model");
67  // The matlab model
68  double ber;
69  if (sinr > WLAN_SIR_PERFECT)
70  {
71  ber = 0.0;
72  }
73  else if (sinr < WLAN_SIR_IMPOSSIBLE)
74  {
75  ber = 0.5;
76  }
77  else
78  {
79  // fitprops.coeff from matlab berfit
80  double a1 = 5.3681634344056195e-001;
81  double a2 = 3.3092430025608586e-003;
82  double a3 = 4.1654372361004000e-001;
83  double a4 = 1.0288981434358866e+000;
84  ber = a1 * std::exp (-std::pow ((sinr - a2) / a3, a4));
85  }
86  return std::pow ((1.0 - ber), static_cast<double> (nbits));
87 #endif
88 }
89 
90 double
92 {
93 #ifdef ENABLE_GSL
94  // symbol error probability
95  double EbN0 = sinr * 22000000.0 / 1375000.0 / 8.0;
96  double sep = SymbolErrorProb256Cck (8.0 * EbN0 / 2.0);
97  return std::pow (1.0 - sep, nbits / 8.0);
98 #else
99  NS_LOG_WARN ("Running a 802.11b CCK Matlab model less accurate than GSL model");
100  // The matlab model
101  double ber;
102  if (sinr > WLAN_SIR_PERFECT)
103  {
104  ber = 0.0;
105  }
106  else if (sinr < WLAN_SIR_IMPOSSIBLE)
107  {
108  ber = 0.5;
109  }
110  else
111  {
112  // fitprops.coeff from matlab berfit
113  double a1 = 7.9056742265333456e-003;
114  double a2 = -1.8397449399176360e-001;
115  double a3 = 1.0740689468707241e+000;
116  double a4 = 1.0523316904502553e+000;
117  double a5 = 3.0552298746496687e-001;
118  double a6 = 2.2032715128698435e+000;
119  ber = (a1 * sinr * sinr + a2 * sinr + a3) / (sinr * sinr * sinr + a4 * sinr * sinr + a5 * sinr + a6);
120  }
121  return std::pow ((1.0 - ber), static_cast<double> (nbits));
122 #endif
123 }
124 
125 #ifdef ENABLE_GSL
126 double
127 IntegralFunction (double x, void *params)
128 {
129  double beta = ((FunctionParameters *) params)->beta;
130  double n = ((FunctionParameters *) params)->n;
131  double IntegralFunction = std::pow (2 * gsl_cdf_ugaussian_P (x + beta) - 1, n - 1)
132  * std::exp (-x * x / 2.0) / std::sqrt (2.0 * M_PI);
133  return IntegralFunction;
134 }
135 
136 double
137 DsssErrorRateModel::SymbolErrorProb16Cck (double e2)
138 {
139  double sep;
140  double error;
141 
142  FunctionParameters params;
143  params.beta = std::sqrt (2.0 * e2);
144  params.n = 8.0;
145 
146  gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
147 
148  gsl_function F;
149  F.function = &IntegralFunction;
150  F.params = &params;
151 
152  gsl_integration_qagiu (&F,-params.beta, 0, 1e-7, 1000, w, &sep, &error);
153  gsl_integration_workspace_free (w);
154  if (error == 0.0)
155  {
156  sep = 1.0;
157  }
158 
159  return 1.0 - sep;
160 }
161 
162 double DsssErrorRateModel::SymbolErrorProb256Cck (double e1)
163 {
164  return 1.0 - std::pow (1.0 - SymbolErrorProb16Cck (e1 / 2.0), 2.0);
165 }
166 
167 #endif
168 
169 } // namespace ns3