A Discrete-Event Network Simulator
API
80211b.c
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 /*
22  * This program is used to generate plots found in the paper
23  * G. Pei and Tom Henderson, "Validation of ns-3 802.11b PHY model",
24  * available online at http://www.nsnam.org/~pei/80211b.pdf
25  *
26  * It can be compiled as a C program and relies on a library installation of
27  * the GNU Scientific Library (gsl). To compile:
28  * gcc 80211b.c -o 80211b -lm -lgsl -lgslcblas
29  *
30  * The executable output should be redirected into a text file 80211b.txt
31  * ./80211b > 80211b.txt
32  *
33  * Then gnuplot can load the associated plot file which references 80211b.txt:
34  * gnuplot 80211b.plt
35  */
36 
37 #include "math.h"
38 #include "stdlib.h"
39 #include "stdio.h"
40 #include <gsl/gsl_math.h>
41 #include <gsl/gsl_integration.h>
42 #include <gsl/gsl_cdf.h>
43 #include <gsl/gsl_sf_bessel.h>
44 #define min(a,b) ((a) < (b) ? (a) : (b))
45 #define max(a,b) ((a) > (b) ? (a) : (b))
46 #define WLAN_SIR_perfect 10.0 // if SIR > 10dB, perfect reception
47 #define WLAN_SIR_impossible 0.1 // if SIR < -10dB, impossible to receive
48 
49 typedef struct fn_parameter_t
50 {
51  double beta;
52  double n;
54 
55 double QFunction (double x)
56 {
57  return 0.5 * erfc (x / sqrt (2.0));
58 }
59 
60 double f (double x, void * params)
61 {
62  double beta = ((fn_parameters *) params)->beta;
63  double n = ((fn_parameters *) params)->n;
64  double f = pow ( 2 * gsl_cdf_ugaussian_P (x + beta) - 1, n - 1) * exp (-x * x / 2.0) / sqrt (2.0 * M_PI);
65  return f;
66 }
67 
68 double p_e2 (double e2)
69 {
70  double sep;
71  double error;
72  fn_parameters params;
73  params.beta = sqrt (2.0 * e2);
74  params.n = 8.0;
75  gsl_integration_workspace* w = gsl_integration_workspace_alloc (1000);
76  gsl_function F;
77  F.function = &f;
78  F.params = &params;
79  gsl_integration_qagiu (&F, -params.beta, 0, 1e-7, 1000, w, &sep, &error);
80  gsl_integration_workspace_free (w);
81  if (error == 0.0)
82  {
83  sep = 1.0;
84  }
85  return 1.0 - sep;
86 }
87 
88 double p_e1 (double e1)
89 {
90  return 1.0 - pow ( 1.0 - p_e2 (e1 / 2.0), 2.0);
91 }
92 
93 double DbToNoneDb (double x)
94 {
95  return pow (10.0, x / 10.0);
96 }
97 
98 double NoneDbToDb (double x)
99 {
100  return 10.0 * log10 (x);
101 }
102 
103 double DQPSKFunction (double x)
104 {
105  double pi = acos (-1.0);
106  return ( (sqrt (2.0) + 1.0) / sqrt (8.0 * pi * sqrt (2.0))) * (1.0 / sqrt (x)) * exp ( -(2.0 - sqrt (2.0)) * x);
107 }
108 
109 double Get80211bDsssDbpskBerIeee (double EcNc)
110 {
111  double ber;
112  if (EcNc > WLAN_SIR_perfect)
113  {
114  ber = 0;
115  }
116  else if (EcNc < WLAN_SIR_impossible)
117  {
118  ber = 0.5;
119  }
120  else
121  {
122  ber = min (QFunction (sqrt (11.0 * EcNc)),0.5);
123  }
124  return ber;
125 }
126 
127 double Get80211bDsssDbpskBer (double sinr)
128 {
129  double EbN0 = sinr * 22000000.0 / 1000000.0;
130  double ber = 0.5 * exp (-EbN0);
131  return ber;
132 }
133 
134 double Get80211bDsssDqpskBerIeee (double EcNc)
135 {
136  double ber;
137  if (EcNc > WLAN_SIR_perfect)
138  {
139  ber = 0;
140  }
141  else if (EcNc < WLAN_SIR_impossible)
142  {
143  ber = 0.5;
144  }
145  else
146  {
147  ber = min (QFunction (sqrt (5.5 * EcNc)),0.5);
148  }
149  return ber;
150 }
151 
152 double Get80211bDsssDqpskBer (double sinr)
153 {
154 // 2 bits per symbol, 1 MSPS
155  double EbN0 = sinr * 22000000.0 / 1000000.0 / 2.0;
156  double ber = DQPSKFunction (EbN0);
157  return ber;
158 }
159 
161 {
162  double ber;
163  if (EcNc > WLAN_SIR_perfect)
164  {
165  ber = 0.0;
166  }
167  else if (EcNc < WLAN_SIR_impossible)
168  {
169  ber = 0.5;
170  }
171  else
172  {
173  double pew = 14.0 * QFunction (sqrt (EcNc * 8.0)) + QFunction (sqrt (EcNc * 16.0));
174  pew = min (pew, 0.99999);
175  ber = 8.0 / 15.0 * pew;
176  }
177  return ber;
178 }
179 
180 double Get80211bDsssDqpskCCK11BerIeee (double EcNc)
181 {
182  double ber;
183  if (EcNc > WLAN_SIR_perfect)
184  {
185  ber = 0.0;
186  }
187  else if (EcNc < WLAN_SIR_impossible)
188  {
189  ber = 0.5;
190  }
191  else
192  {
193  double pew = 24.0 * QFunction (sqrt (EcNc * 4.0)) + 16.0 * QFunction (sqrt (EcNc * 6.0)) + 174.0 * QFunction (sqrt (EcNc * 8.0)) + 16.0 * QFunction (sqrt (EcNc * 10.0)) + 24.0 * QFunction (sqrt (EcNc * 12.0)) + QFunction (sqrt (EcNc * 16.0));
194  pew = min (pew, 0.99999);
195  ber = 128.0 / 255.0 * pew;
196  }
197  return ber;
198 }
199 
200 int main (int argc, char * argv[])
201 {
202  double rss, sinr;
203  double totalPkt = 200.0;
204 //double noise = 1.552058; // (dB) this noise figure value corresponds to
205  // -99 dBm noise floor reported in CMU paper
206  double noise = 7; // (dB) this noise figure value corresponds to the
207  // default in YansWifiPhy, and matches CMU testbed results
208  double EcNc, EbN01, EbN02, EbN05, EbN011;
209  double ieee1,ieee2,ieee5,ieee11;
210  double numBits = (1024. + 40. + 14.) * 8.;
211  double dbpsk,dqpsk,cck16,cck256,sepcck16,sepcck256;
212  noise = DbToNoneDb (noise) * 1.3803e-23 * 290.0 * 22000000;
213  for (rss = -102.0; rss <= -80.0; rss += 0.1)
214  {
215  sinr = DbToNoneDb (rss) / 1000.0 / noise;
216  EcNc = sinr * 22000000.0 / 11000000.0; // IEEE sir
217  EbN01 = sinr * 22000000.0 / 1000000.0;
218  // 2 bits per symbol, 1 MSPS
219  EbN02 = sinr * 22000000.0 / 1000000.0 / 2.0;
220  EbN05 = sinr * 22000000.0 / 1375000.0 / 4.0;
221  EbN011 = sinr * 22000000.0 / 1375000.0 / 8.0;
222  // 1=rss, 2=EcNc, 3=EbN01, 4=EbN02, 5=EBN05, 6=EbN011
223  printf ("%g %g %g %g %g %g ", rss, NoneDbToDb (EcNc),
224  NoneDbToDb (EbN01),NoneDbToDb (EbN02),
225  NoneDbToDb (EbN05),NoneDbToDb (EbN011));
226  ieee1 = Get80211bDsssDbpskBerIeee (EcNc);
227  ieee2 = Get80211bDsssDqpskBerIeee (EcNc);
228  ieee5 = Get80211bDsssDqpskCCK5_5BerIeee (EcNc);
229  ieee11 = Get80211bDsssDqpskCCK11BerIeee (EcNc);
230  // 7=ber_ieee1, 8=ber_ieee2, 9=ber_ieee5, 10=ber_ieee11
231  printf (" %g %g %g %g ", ieee1, ieee2,ieee5,ieee11);
232  ieee1 = totalPkt * pow (1 - ieee1, numBits);
233  ieee2 = totalPkt * pow (1 - ieee2, numBits);
234  ieee5 = totalPkt * pow (1 - ieee5, numBits);
235  ieee11 = totalPkt * pow (1 - ieee11, numBits);
236  // 11=pkt_ieee1, 12=pkt_ieee2, 13=pkt_ieee5, 14=pkt_ieee11
237  printf (" %g %g %g %g ", ieee1, ieee2,ieee5,ieee11);
238  dbpsk = Get80211bDsssDbpskBer (sinr);
239  dqpsk = Get80211bDsssDqpskBer (sinr);
240  cck16 = max (0, 8.0 / 15.0 * p_e2 (4.0 * EbN05 / 2.0));
241  cck256 = max (0, 128.0 / 255.0 * p_e1 (8.0 * EbN011 / 2.0));
242  // 15=ber_dbpsk, 16=ber_dqpsk, 17=ber_cck16, 18=ber_cck256
243  printf (" %g %g %g %g ", dbpsk, dqpsk,cck16,cck256);
244  dbpsk = totalPkt * pow (1 - dbpsk,numBits);
245  dqpsk = totalPkt * pow (1 - dqpsk,numBits);
246  sepcck16 = p_e2 (4.0 * EbN05 / 2.0);
247  sepcck256 = p_e1 (8.0 * EbN011 / 2.0);
248  cck16 = totalPkt * pow (1.0 - sepcck16,numBits / 4.0);
249  cck256 = totalPkt * pow (1.0 - sepcck256,numBits / 8.0);
250  // 19=pkt_dbpsk, 20=pkt_dqpsk, 21=pkt_cck16, 22=pkt_cck256
251  printf (" %g %g %g %g ", dbpsk, dqpsk,cck16,cck256);
252  // 23=sinr
253  printf (" %g \n",NoneDbToDb (sinr));
254  }
255  return 0;
256 }
Custom version of log2() to deal with Bug 1467.
double p_e2(double e2)
Definition: 80211b.c:68
double Get80211bDsssDbpskBer(double sinr)
Definition: 80211b.c:127
#define min(a, b)
Definition: 80211b.c:44
double beta
Definition: 80211b.c:51
double Get80211bDsssDqpskCCK11BerIeee(double EcNc)
Definition: 80211b.c:180
double n
Definition: 80211b.c:52
double QFunction(double x)
Definition: 80211b.c:55
double Get80211bDsssDqpskBer(double sinr)
Definition: 80211b.c:152
#define max(a, b)
Definition: 80211b.c:45
double NoneDbToDb(double x)
Definition: 80211b.c:98
double Get80211bDsssDqpskBerIeee(double EcNc)
Definition: 80211b.c:134
double f(double x, void *params)
Definition: 80211b.c:60
double p_e1(double e1)
Definition: 80211b.c:88
double Get80211bDsssDqpskCCK5_5BerIeee(double EcNc)
Definition: 80211b.c:160
double DbToNoneDb(double x)
Definition: 80211b.c:93
#define WLAN_SIR_perfect
Definition: 80211b.c:46
double Get80211bDsssDbpskBerIeee(double EcNc)
Definition: 80211b.c:109
double DQPSKFunction(double x)
Definition: 80211b.c:103
#define WLAN_SIR_impossible
Definition: 80211b.c:47