标签:style blog http io color ar os sp for
I use the ubuntu and do not install the chinse input.
The Code: c file requires gnu gsl library, it can be installed easily because many tutorial.
Although the code style is poor, it can be clear for you to read and can be copy to your edit tool.
gcc -Wall -I/usr/local/include -c 80211b.c
gcc -Wall -L/usr/local/lib 80211b.o lgsl 0lgslcblas -lm -o 80211b
./80211b >80211b.txt
1 // Copyright 2009, The Boeing Company 2 3 #include "math.h" 4 #include "stdlib.h" 5 #include "stdio.h" 6 7 #include <gsl/gsl_math.h> 8 #include <gsl/gsl_integration.h> 9 #include <gsl/gsl_cdf.h> 10 #include <gsl/gsl_sf_bessel.h> 11 12 #define min(a,b) ((a)<(b) ? (a) : (b)) 13 #define max(a,b) ((a)>(b) ? (a) : (b)) 14 //page 67 802.15 that pdf kanghl 15 #define WLAN_SIR_perfect 10.0 // if SIR > 10dB, perfect reception 16 #define WLAN_SIR_impossible 0.1 // if SIR < -10dB, impossible to receive 17 18 typedef struct fn_parameter_t 19 { 20 double beta; 21 double n; 22 }fn_parameters; 23 24 double QFunction (double x) 25 { 26 return 0.5 * erfc(x/sqrt(2.0)); 27 } 28 //not understand 29 double f(double x, void *params) 30 { 31 double beta = ((fn_parameters *) params)->beta; 32 double n = ((fn_parameters *) params)->n; 33 double f = pow( 2*gsl_cdf_ugaussian_P (x+ beta) - 1, n-1) 34 * exp (-x*x/2.0) / sqrt (2.0 * M_PI); 35 36 return f; 37 } 38 39 double p_e2(double e2) 40 { 41 double sep; 42 double error; 43 44 fn_parameters params; 45 params.beta = sqrt (2.0*e2); 46 params.n = 8.0; 47 48 gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000); 49 50 gsl_function F; 51 F.function = &f; 52 F.params = ¶ms; 53 54 gsl_integration_qagiu(&F,-params.beta, 55 0, 1e-7, 1000, w, &sep, &error); 56 gsl_integration_workspace_free (w); 57 if (error == 0.0) sep = 1.0; 58 59 return 1.0 - sep; 60 } 61 62 double p_e1(double e1) 63 { 64 return 1.0 - pow( 1.0 - p_e2 (e1/2.0), 2.0); 65 } 66 67 68 double DbToNoneDb (double x) 69 { 70 return pow(10.0, x/10.0); 71 } 72 73 double NoneDbToDb (double x) 74 { 75 return 10.0 * log10 (x) ; 76 } 77 78 double DQPSKFunction (double x) 79 { 80 double pi = acos (-1.0); 81 return ( (sqrt(2.0) + 1.0) / sqrt(8.0*pi*sqrt(2.0))) 82 *(1.0/sqrt(x)) 83 *exp( - (2.0 - sqrt(2.0)) * x) ; 84 } 85 //P1MBPS-SYMBOL BER=SER 86 double Get80211bDsssDbpskBerIeee(double EcNc) 87 { 88 double ber; 89 if(EcNc > WLAN_SIR_perfect) ber = 0; 90 else if(EcNc < WLAN_SIR_impossible) ber = 0.5; 91 else 92 ber = min(QFunction(sqrt(11.0*EcNc)),0.5); 93 return ber; 94 } 95 96 double Get80211bDsssDbpskBer(double sinr) 97 { 98 double EbN0 = sinr * 22000000.0 / 1000000.0; 99 double ber = 0.5 * exp(-EbN0); 100 return ber; 101 } 102 103 double Get80211bDsssDqpskBerIeee(double EcNc) 104 { 105 double ber; 106 if (EcNc > WLAN_SIR_perfect) ber = 0; 107 else if(EcNc < WLAN_SIR_impossible) ber = 0.5; 108 else 109 ber = min(QFunction(sqrt(5.5*EcNc)),0.5); 110 return ber; 111 } 112 113 double Get80211bDsssDqpskBer(double sinr) 114 { 115 // 2 bits per symbol, 1 MSPS 116 double EbN0 = sinr * 22000000.0 / 1000000.0 / 2.0; 117 double ber = DQPSKFunction(EbN0); 118 return ber; 119 } 120 121 double Get80211bDsssDqpskCCK5_5BerIeee(double EcNc) 122 { 123 double ber; 124 if(EcNc > WLAN_SIR_perfect) ber = 0.0 ; 125 else if(EcNc < WLAN_SIR_impossible) ber = 0.5; 126 else 127 { 128 double pew = 14.0*QFunction(sqrt(EcNc*8.0)) + QFunction(sqrt(EcNc*16.0)); 129 pew = min(pew, 0.99999); 130 ber = 8.0/15.0 * pew; 131 } 132 return ber; 133 } 134 135 double Get80211bDsssDqpskCCK11BerIeee(double EcNc) 136 { 137 double ber; 138 if(EcNc > WLAN_SIR_perfect) ber = 0.0 ; 139 else if(EcNc < WLAN_SIR_impossible) ber = 0.5; 140 else 141 { 142 double pew = 24.0*QFunction(sqrt(EcNc*4.0)) + 143 16.0*QFunction(sqrt(EcNc*6.0)) + 144 174.0*QFunction(sqrt(EcNc*8.0)) + 145 16.0*QFunction(sqrt(EcNc*10.0)) + 146 24.0*QFunction(sqrt(EcNc*12.0)) + 147 QFunction(sqrt(EcNc*16.0)); 148 pew = min(pew, 0.99999); 149 ber = 128.0/255.0 * pew; 150 } 151 return ber; 152 } 153 154 int main (int argc, char *argv[]) 155 { 156 double rss, sinr; 157 double totalPkt = 200.0; 158 //double noise = 1.552058; 159 double noise = 7; 160 double EcNc, EbN01, EbN02, EbN05, EbN011; 161 double ieee1,ieee2,ieee5,ieee11; 162 double numBits = (1024. + 40. + 14.) * 8.; 163 double dbpsk,dqpsk,cck16,cck256,sepcck16,sepcck256; 164 165 noise = DbToNoneDb(noise) * 1.3803e-23 * 290.0 * 22000000; 166 for (rss=-102.0; rss <= -80.0; rss += 0.1) 167 { 168 sinr = DbToNoneDb(rss)/1000.0/noise; 169 EcNc = sinr * 22000000.0 / 11000000.0; // IEEE sir 170 EbN01 = sinr * 22000000.0 / 1000000.0; 171 // 2 bits per symbol, 1 MSPS 172 EbN02 = sinr * 22000000.0 / 1000000.0 / 2.0; 173 EbN05 = sinr * 22000000.0 / 1375000.0 / 4.0; 174 EbN011 = sinr * 22000000.0 / 1375000.0 / 8.0; 175 // 1=rss, 2=EcNc, 3=EbN01, 4=EbN02, 5=EBN05, 6=EbN011 176 printf("%g %g %g %g %g %g ", rss, NoneDbToDb(EcNc), 177 NoneDbToDb(EbN01),NoneDbToDb(EbN02), 178 NoneDbToDb(EbN05),NoneDbToDb(EbN011)); 179 180 ieee1 = Get80211bDsssDbpskBerIeee (EcNc); 181 ieee2 = Get80211bDsssDqpskBerIeee (EcNc); 182 ieee5 = Get80211bDsssDqpskCCK5_5BerIeee (EcNc); 183 ieee11 = Get80211bDsssDqpskCCK11BerIeee (EcNc); 184 // 7=ber_ieee1, 8=ber_ieee2, 9=ber_ieee5, 10=ber_ieee11 185 printf(" %g %g %g %g ", ieee1, ieee2,ieee5,ieee11); 186 187 ieee1 = totalPkt*pow(1-ieee1, numBits); 188 ieee2 = totalPkt*pow(1-ieee2, numBits); 189 ieee5 = totalPkt*pow(1-ieee5, numBits); 190 ieee11 = totalPkt*pow(1-ieee11, numBits); 191 // 11=pkt_ieee1, 12=pkt_ieee2, 13=pkt_ieee5, 14=pkt_ieee11 192 printf(" %g %g %g %g ", ieee1, ieee2,ieee5,ieee11); 193 194 dbpsk = Get80211bDsssDbpskBer (sinr); 195 dqpsk = Get80211bDsssDqpskBer (sinr); 196 cck16 = max(0, 8.0/15.0*p_e2(4.0*EbN05/2.0)); 197 cck256 = max(0, 128.0/255.0*p_e1(8.0*EbN011/2.0)); 198 // 15=ber_dbpsk, 16=ber_dqpsk, 17=ber_cck16, 18=ber_cck256 199 printf(" %g %g %g %g ", dbpsk, dqpsk,cck16,cck256); 200 201 dbpsk = totalPkt*pow(1-dbpsk,numBits); 202 dqpsk = totalPkt*pow(1-dqpsk,numBits); 203 sepcck16 = p_e2(4.0*EbN05/2.0); 204 sepcck256 = p_e1(8.0*EbN011/2.0); 205 cck16 = totalPkt*pow(1.0-sepcck16,numBits/4.0); 206 cck256 = totalPkt*pow(1.0-sepcck256,numBits/8.0); 207 // 19=pkt_dbpsk, 20=pkt_dqpsk, 21=pkt_cck16, 22=pkt_cck256 208 printf(" %g %g %g %g ", dbpsk, dqpsk,cck16,cck256); 209 // 23=sinr 210 printf(" %g \n",NoneDbToDb(sinr)); 211 } 212 return 0; 213 }
gnuplot code
1 set term postscript eps color enh "Times-BoldItalic" 2 set output ‘80211b.ieee.pkt.eps‘ 3 set xlabel "RSS (dBm)" 4 set ylabel "Packet Received" 5 set yrange [0:200] 6 set xrange [-102:-83] 7 plot "80211b.txt" using 1:11 title ‘1M IEEE‘, 8 "80211b.txt" using 1:12 title ‘2M IEEE‘, 9 "80211b.txt" using 1:13 title ‘5.5M IEEE‘, 10 "80211b.txt" using 1:14 title ‘11M IEEE‘ 11 set term postscript eps color enh "Times-BoldItalic" 12 set output ‘80211b.ns3.pkt.eps‘ 13 set xlabel "RSS (dBm)" 14 set ylabel "Packet Received" 15 set yrange [0:200] 16 set xrange [-102:-83] 17 plot "80211b.txt" using 1:19 title ‘1M DBPSK‘, 18 "80211b.txt" using 1:20 title ‘2M DQPSK‘, 19 "80211b.txt" using 1:21 title ‘5.5M CCK16‘, 20 "80211b.txt" using 1:22 title ‘11M CCK256‘ 21 set term postscript eps color enh "Times-BoldItalic" 22 set output ‘80211b.ieee.sir.eps‘ 23 set xlabel "SIR" 24 set ylabel "BER" 25 set yrange [10e-9:1] 26 set xrange [-2:10] 27 set logscale y 28 plot "80211b.txt" using 2:7 title ‘1M IEEE‘, 29 "80211b.txt" using 2:8 title ‘2M IEEE‘, 30 "80211b.txt" using 2:9 title ‘5.5M IEEE‘, 31 "80211b.txt" using 2:10 title ‘11M IEEE‘
reference: http://www.nsnam.org/~pei/80211b.pdf
标签:style blog http io color ar os sp for
原文地址:http://www.cnblogs.com/khldragon/p/4093729.html