资源简介
matlab运行环境下,基于pegasis和leach协议的无线路由算法,其中含有对比leach和deec算法,源码

代码片段和文件信息
clear
xm=100;
ym=100;
sink.x=0.5*xm;
sink.y=0.5*ym;
n=100
p=0.05;
P=0.05;
Eo=0.5;
%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;
a=1;
rmax=5000
do=sqrt(Efs/Emp);
Et=0;
for i=1:1:n
S1(i).xd=rand(11)*xm;
S2(i).xd=S1(i).xd;
S3(i).xd=S1(i).xd;
S4(i).xd=S3(i).xd;
XR4(i)=S4(i).xd;
XR3(i)=S3(i).xd;
XR2(i)=S2(i).xd;
XR1(i)=S1(i).xd;
S1(i).yd=rand(11)*ym;
S2(i).yd=S1(i).yd;
S3(i).yd=S1(i).yd;
S4(i).yd=S3(i).yd;
YR4(i)=S4(i).yd;
S4(i).G=0;
YR3(i)=S3(i).yd;
S3(i).G=0;
YR2(i)=S2(i).yd;
YR1(i)=S1(i).yd;
S1(i).G=0;
S2(i).G=0;
S1(i).E=Eo*(1+rand*a);
S2(i).E=S1(i).E;
S3(i).E=S1(i).E;
S4(i).E=S3(i).E;
E3(i)= S3(i).E;
E4(i)= S4(i).E;
Et=Et+E3(i);
%initially there are no cluster heads only nodes
S1(i).type=‘N‘;
S2(i).type=‘N‘;
S3(i).type=‘N‘;
S4(i).type=‘N‘;
end
S1(n+1).xd=sink.x;
S1(n+1).yd=sink.y;
S2(n+1).xd=sink.x;
S2(n+1).yd=sink.y;
countCHs1=0;
cluster1=1;
flag_first_dead1=0;
flag_teenth_dead1=0;
flag_all_dead1=0;
dead1=0;
first_dead1=0;
teenth_dead1=0;
all_dead1=0;
allive1=n;
%counter for bit transmitted to bases Station and to Cluster Heads
packets_TO_BS1=0;
packets_TO_CH1=0;
for r=0:1:rmax
r
if(mod(r round(1/p) )==0)
for i=1:1:n
S1(i).G=0;
S1(i).cl=0;
end
end
dead1=0;
for i=1:1:n
if (S1(i).E<=0)
dead1=dead1+1;
if (dead1==1)
if(flag_first_dead1==0)
first_dead1=r;
flag_first_dead1=1;
end
end
if(dead1==0.1*n)
if(flag_teenth_dead1==0)
teenth_dead1=r;
flag_teenth_dead1=1;
end
end
if(dead1==n)
if(flag_all_dead1==0)
all_dead1=r;
flag_all_dead1=1;
end
end
end
if S1(i).E>0
S1(i).type=‘N‘;
end
end
STATISTICS.DEAD1(r+1)=dead1;
STATISTICS.ALLIVE1(r+1)=allive1-dead1;
countCHs1=0;
cluster1=1;
for i=1:1:n
if(S1(i).E>0)
temp_rand=rand;
if ( (S1(i).G)<=0)
if(temp_rand<= (p/(1-p*mod(rround(1/p)))))
countCHs1=countCHs1+1;
packets_TO_BS1=packets_TO_BS1+1;
PACKETS_TO_BS1(r+1)=packets_TO_BS1;
S1(i).type=‘C‘;
S1(i).G=round(1/p)-1;
C1(cluster1).xd=S1(i).xd;
C1(cluster1).yd=S1(i).yd;
distance=sqrt( (S1(i).xd-(S1(n+1).xd) )^2 + (S1(i).yd-(S1(n+1).yd) )^2 );
C1(cluster1).distance=distance;
C1(cluster1).id=i;
X1(cluster1)=S1(i).xd;
Y1(clus
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2729 2009-11-09 15:34 pegasis.m
文件 20471 2012-04-14 21:56 leachvsdeec.m
----------- --------- ---------- ----- ----
23200 2
- 上一篇:matlab变分模态分解VMD
- 下一篇:moead优化算法
相关资源
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
评论
共有 条评论