资源简介
LEACH分簇算法matlab代码,手动输入方程中所需的参数即可运行
代码片段和文件信息
function [STATISTICS1FD1TD1AD1]=leach(IniEngNetSizeNoOfNodeNoOfRoundcluster_head_percentage)
xm=NetSize;%设置网络大小
ym=NetSize;
sink.x=0.5*xm;%设置基站坐标
sink.y=1.35*ym;
n=NoOfNode;%设置网络节点数
p=cluster_head_percentage;%设置簇首概率
Eo=IniEng;%Initial energy节点初始能量
%Eelec=Etx=Erx
ETX=50*0.000000001;%节点传输消耗能量,每bit
ERX=50*0.000000001;%节点接收消耗能量,每bit
%Transmit Amplifier types
Efs=10*0.000000000001;%耗散能量,每bit
Emp=0.0013*0.000000000001;%放大信号能耗,每bit
%Data Aggregation Energy
EDA=5*0.000000001;%数据融合能耗,每bit
a=0;
rmax=NoOfRound;%总轮数
do=sqrt(Efs/Emp);
do
for i=1:1:n %设置所有节点的X,Y坐标,初始能量,节点类型,簇首选举资格
S(i).xd=rand(11)*xm;
%XR(i)=S(i).xd;
S(i).yd=rand(11)*ym;
%YR(i)=S(i).yd;
S(i).G=0;
S(i).E=Eo*(1+rand*a);
%initially there are no cluster heads only nodes
S(i).type=‘N‘;
end
S(n+1).xd=sink.x;%设置基站的XY坐标
S(n+1).yd=sink.y;
countCHs=0;
cluster=1;
flag_first_dead=0;
flag_teenth_dead=0;
flag_all_dead=0;
dead=0;
first_dead=0;
teenth_dead=0;
all_dead=0;
allive=n;
%counter for bit transmitted to bases Station and to Cluster Heads
packets_TO_BS=0;
packets_TO_CH=0;
for r=0:1:rmax
r
if(mod(r round(1/p) )==0)
for i=1:1:n
S(i).G=0;
%S(i).cl=0;
end
end
dead=0;
for i=1:1:n
if (S(i).E<=0)
dead=dead+1;
if (dead==1)
if(flag_first_dead==0)
first_dead=r;%首个死亡节点出现的轮数
flag_first_dead=1;
end
end
if(dead==0.1*n)
if(flag_teenth_dead==0)
teenth_dead=r;%死亡节点数我x*10时的轮数(x=1--0.1*n)
flag_teenth_dead=1;
end
end
if(dead==n)
if(flag_all_dead==0)
all_dead=r;%所有节点全部死亡的轮数
flag_all_dead=1;
end
end
end
if S(i).E>0
S(i).type=‘N‘;
end
end
STATISTICS.DEAD(r+1)=dead;%第r+1轮时的死亡节点数
STATISTICS.ALLIVE(r+1)=allive-dead;%第r+1轮时的存活节点数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TotalNetworkEnergy=0;
for i=1:n
if S(i).E>0
TotalNetworkEnergy=TotalNetworkEnergy+S(i).E;
end
end
STATISTICS.TotalEnergy(r+1)=TotalNetworkEnergy;%第r+1轮时的网络总能量剩余
STATISTICS.AvgEnergy(r+1)=TotalNetworkEnergy/n;%第r+1轮时的节点平均量剩余
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
countCHs=0;%初始簇头数为0
cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ( (S(i).G)<=0)
if(temp_rand<= (p/(1-p*mod(rround(1/p)))))
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;%第r+1轮CH传输给BS的总数据包数
相关资源
- Pattern Recognition and Machine Learning(高清
- MATLAB 编程 第二版 Stephen J. Chapman 著
- 均值滤波和FFT频谱分析Matlab代码
- 《MATLAB扩展编程》代码
- HDB3码、AMI码的MATLAB实现
- 3点GPS定位MATLAB仿真
- MATLAB数字信号处理85个实用案例精讲入
- matlab从入门到精通pdf94795
- 欧拉放大论文及matlab代码
- 跳一跳辅助_matlab版本
- 全面详解LTE MATLAB建模、仿真与实现
- MIMO-OFDM无线通信技术及MATLAB实现_孙锴
- MATLAB Programming for Engineers 4th - Chapman
- matlab 各种谱分析对比
- 分数阶chen混沌matlab程序
- 基于粒子群算法的非合作博弈的matl
- MATLAB车流仿真 包括跟驰、延误
- matlab空间桁架计算程序
- 基于MATLAB的图像特征点匹配和筛选
- DMA-TVP-FAVAR
- GPS信号的码捕获matlab代码.7z
- 一维光子晶体MATLAB仿真代码吸收率折
- newmark法源程序
- 传统关联成像、计算鬼成像matlab
- pri传统分选算法
- 摆动滚子推杆盘形凸轮设计
- 医学图像重建作业matlab源码
- Matlab实现混沌系统的控制
- 检测疲劳驾驶
- Matlab锁相环仿真-Phase Locked Loop.rar
评论
共有 条评论