ns3 802.11b PHY model

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 = &params;
 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 }

80211b.c

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‘

plot80211b

reference: http://www.nsnam.org/~pei/80211b.pdf

时间: 2024-10-23 18:07:15

ns3 802.11b PHY model的相关文章

802.11n与802.11b/g有什么区别

“802.11n和802.11b/g的区别是:802.11n是802.11b/g的升级版本,传输速度更快.802.11b,802.11g和802.11n是基于802.11无线传输协议的标准.802.11n是目前最先进的无线传输标准.” 对我们普通用户来讲,肯定是知道,最新的技术是最好的,802.11n速度是802.11g的12倍,传播信号的范围是是802.11g的4倍,当然价格也贵很多.对于三者的兼容性来讲,是没有问题的,802.11n技术与802.11b和802.11g技术所谈到的兼容不同于以

CentOS 6.6下 BCM4312 802.11b/g无线网卡驱动安装

安装基本环境: dell 1440 uname - r  2.6.32-504.el6.i686 lspci |grep Network  # BCM4312 lspci -n |grep 14e4 # 14e4:4315 ############################### hybrid-portsrc_x86_32-v5_100_82_38.tar.gz下载地址在 免费下载地址在 http://linux.linuxidc.com/ 用户名与密码都是www.linuxidc.com

Ubuntu上安装NS-3实践

ns3官网https://www.nsnam.org/wiki/Installation#Installation 安装: Ubuntu/Debian/Mint The following list of packages should be accurate for Ubuntu 19.04 release; other releases or other Debian-based systems may slightly vary. Ubuntu 16.04 LTS release is p

802.11协议精读12:初探协议性能

序言 在初始的802.11协议版本之后,陆续更新的802.11e,以及802.11n以及更新的802.11技术,其都是基于改善当前802.11协议的缺陷不断进行改进的.为了理解这些改进,我们首先要理解802.11存在的一些问题,其中一个主要的问题就是性能问题. 本文我们先简单介绍802.11中一个常见问题,即路由器的宣称速率不等于实际速率的问题,然后我们具体分析一下这个宣称速率(即物理层速率)的计算方法.在后面一篇文章中,我们会介绍用数学方法对该吞吐量具体进行估计的方法,即Bianchi模型.

802.11基础

名词解释: ACL: 访问控制列表. OKC(Opportunistic Key Caching): OKC,也叫OPC(Opportunistic PMK Caching),是微软定义的一套标准,并不在802.11标准中.不过多数厂商都支持这种方式,也成为了一种事实标准. PMKSA: pairwise master key security association. PMK安全关联. aaa服务器:authentication authorization accounting. ISM:in

802.11 帧封装细节

802.11帧主要有三类: 数据帧——好比 802.11 的驮马,负责在工作站之间传输数据. 控制帧——控制帧通常与数据帧搭配使用, 负责区域的清空.信道的取得以及载波监听的维护,并于收到数据时予以正面的应答,借此促进工作站间数据传输的可靠性. 管理帧——管理帧负责监督, 主要用来加入或退出无线网络, 以及处理基站之间连接的转移事宜. 4.1 数据帧 数据帧会将上层协议的数据置于帧主体加以传递.会用到哪些位,取决于该数据帧所属的类型. 一种区分方式:竞争式服务和免竞争服务两种数据帧 另一种区分方

wpa_supplicant 和 802.11g WPA 认证的配置

# cd /etc/init.d# ln -s net.lo net.eth0 默认的接口名是 wlan0,让它开机时自动 up:cp /etc/init.d/net.lo /etc/init.d/net.wlan0 ifconfig wlan0 up 根据接入点设置编辑 /etc/wpa_supplicant/wpa_supplicant.conf: ctrl_interface=/var/run/wpa_supplicantctrl_interface_group=wheelupdate_c

IEEE 802

IEEE 802 委员会 又称为 LMSC(LAN /MAN Standards Committee, 局域网/城域网标准委员会) 研究 局域网和城域网 的 物理层和MAC层 中定义的服务和协议,对应 OSI网络参考模型的 物理层 和 数据链路层 IEEE 802系列标准 是IEEE 802 LAN/MAN 标准委员会制定的局域网.城域网技术标准. 其中最广泛使用的有 以太网.令牌环.无线局域网 等.这一系列标准中的每一个子标准都由委员会中的一个专门工作组负责. IEEE 802现有标准 IEE

802.11 (b/g/a/n/ac)

Ref: https://wenku.baidu.com/view/5b6fa01fdd88d0d232d46a15.html ,https://www.douban.com/note/580574488/ 802.11 a/b/g/n/ac 都是由802.11 发展而来的. 不同的后缀代表着不同的物理层标准工作频段和不同的传输速率,也就是说它们的物理层和传输速度不同. 协议 频率 信号  最大传输速率 802.11 2.4Ghz FHSS 或 DSSS 2Mbps 802.11a 5GHz O