💥💥💞💞欢迎来到本博客❤️❤️💥💥
🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。
⛳️座右铭:行百里者,半于九十。
📋📋📋本文目录如下:🎁🎁🎁
目录
💥1 概述
基于LEACH的无线传感器网络路由协议仿真
这个MATLAB程序模拟了基于LEACH的无线传感器网络路由协议的性能。该仿真包括随机网络生成,并允许对不同协议进行比较。
介绍
无线传感器网络(WSNs)在环境监测、监控和医疗等各种应用中起着至关重要的作用。LEACH(低能耗自适应聚类层次)是一种为WSNs设计的流行路由协议。该仿真程序旨在比较不同基于LEACH的路由协议,并使用随机网络生成方法评估它们的性能。
脚本列表如下:
CalcDistance.m:计算节点之间的距离。
CreateModel.m:创建网络模型。
CreateNetwork.m:生成随机网络。
DeadCounter.m:跟踪网络中的死节点。
Direct_Protocol.m:实现直接通信协议。
Direct_UsedEnergy.m:计算直接通信协议的能量消耗。
Leach.m:执行基于LEACH的路由协议。
Leach_Protocol.m:实现LEACH协议。
Leach_SelectCluster.m:在LEACH协议中选择簇头。
Leach_UsedEnergy.m:计算LEACH协议的能量消耗。
Main.m:编排仿真的主脚本。
Show.m:显示仿真结果。
ShowNetworks.m:可视化生成的网络。
Test.m:运行仿真并比较协议。
运行Main.m文件以开始仿真。
按照屏幕上的说明配置仿真参数。
仿真完成后,结果将显示或保存到文件中。
结果
仿真完成后,结果将显示或保存到文件中,具体取决于配置。结果可能包括网络寿命、能量消耗、数据包传输比例和网络覆盖等指标。这些指标可用于比较不同基于LEACH的路由协议的性能。
一、引言
- 无线传感器网络(WSN)是由大量具有特定功能的传感器节点通过自组织的无线通信方式形成的智能专用网络,能够实时检测、感知和采集网络所监控区域内的各种环境和监测对象的信息。
- 路由技术是WSN的核心技术之一,其性能和整个网络的性能密切相关。
- LEACH协议作为一种典型的聚类路由协议,通过将传感器节点分组并轮流担任簇头,实现了网络能量的均衡利用,有效地延长了网络寿命。
二、LEACH协议概述
- 核心思想:将传感器节点划分为若干个簇,每个簇由一个簇头节点负责数据收集和传输。簇头节点通过多跳方式将数据传输到汇聚节点。
- 簇头选举:每个节点根据预设的概率值(P)随机选择是否成为簇头。概率值P通常与节点的剩余能量相关,能量越高的节点,被选为簇头的概率越高。
- 簇成员加入:其他节点根据簇头的信号强度或其他指标,选择加入距离其最近的簇。
- 数据收集与聚合:簇成员将采集到的数据传输给所属簇头,簇头对收集到的数据进行聚合,并通过多跳方式将数据传输到汇聚节点。
- 簇头轮换:每个轮次结束后,将选择新的簇头节点,并重复上述步骤。
三、LEACH协议仿真研究
-
仿真目的:验证LEACH协议的性能优势,包括延长网络寿命、降低能量消耗和提高数据传输成功率。
-
仿真工具:MATLAB或NS2等仿真软件。
-
仿真步骤:
- 初始化网络参数,包括节点数量、节点位置、初始能量等。
- 根据LEACH协议进行簇头选举和簇成员加入。
- 模拟数据收集、聚合和传输过程。
- 记录每个节点的能量消耗和网络寿命。
- 分析数据传输成功率。
-
仿真结果:通过仿真,可以观察到LEACH协议能够有效地延长网络寿命,降低能量消耗,并提高数据传输成功率。与其他路由协议相比,LEACH协议在延长网络寿命方面具有显著优势。
四、LEACH协议的改进与LEACH-C协议
- 针对LEACH协议的缺点,可以从簇首选择、簇的形成等方面进行改进,形成LEACH-C协议。
- LEACH-C协议通过优化簇头选举机制和簇的形成过程,进一步节约了能量,平衡了能量消耗,延长了无线传感器网络的生存时间。
五、结论
- LEACH协议是一种有效的无线传感器网络路由协议,其能够有效地延长网络寿命、提高数据传输效率,并简化路由协议的实现。
- 通过仿真研究,验证了LEACH协议的性能优势,并为其改进提供了方向。
- LEACH-C协议作为LEACH协议的改进版,在性能上有了进一步提升,为无线传感器网络的应用提供了更可靠的支持。
📚2 运行结果
部分代码:
%Field Dimensions - x and y maximum (in meters)
xm=100;
ym=100;
%x and y Coordinates of the Sink
sink.x=0.5*xm;
sink.y=0.5*ym;
%Number of Nodes in the field
n=100
%Optimal Election Probability of a node
%to become cluster head
p=0.1;
%Energy Model (all values in Joules)
%Initial Energy
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;
%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.1;
%\alpha
a=1;
%maximum number of rounds
rmax=9999
%%%%%%%%%%%%%%%%%%%%%%%%% END OF PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%
%Computation of do
do=sqrt(Efs/Emp);
%Creation of the random Sensor Network
figure(1);
for i=1:1:n
S(i).xd=rand(1,1)*xm;
XR(i)=S(i).xd;
S(i).yd=rand(1,1)*ym;
YR(i)=S(i).yd;
S(i).G=0;
%initially there are no cluster heads only nodes
S(i).type='N';
temp_rnd0=i;
%Random Election of Normal Nodes
if (temp_rnd0>=m*n+1)
S(i).E=Eo;
S(i).ENERGY=0;
plot(S(i).xd,S(i).yd,'o');
hold on;
end
%Random Election of Advanced Nodes
if (temp_rnd0<m*n+1)
S(i).E=Eo*(1+a)
S(i).ENERGY=1;
plot(S(i).xd,S(i).yd,'+');
hold on;
end
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
plot(S(n+1).xd,S(n+1).yd,'x');
%First Iteration
figure(1);
%counter for CHs
countCHs=0;
%counter for CHs per round
rcountCHs=0;
cluster=1;
countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
for r=0:1:rmax
r
%Operation for epoch
if(mod(r, round(1/p) )==0)
for i=1:1:n
S(i).G=0;
S(i).cl=0;
end
end
hold off;
%Number of dead nodes
dead=0;
%Number of dead Advanced Nodes
dead_a=0;
%Number of dead Normal Nodes
dead_n=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
packets_TO_BS=0;
packets_TO_CH=0;
%counter for bit transmitted to Bases Station and to Cluster Heads
%per round
PACKETS_TO_CH(r+1)=0;
PACKETS_TO_BS(r+1)=0;
figure(1);
for i=1:1:n
%checking if there is a dead node
if (S(i).E<=0)
plot(S(i).xd,S(i).yd,'red .');
dead=dead+1;
if(S(i).ENERGY==1)
dead_a=dead_a+1;
end
if(S(i).ENERGY==0)
dead_n=dead_n+1;
end
hold on;
end
if S(i).E>0
S(i).type='N';
if (S(i).ENERGY==0)
plot(S(i).xd,S(i).yd,'o');
end
if (S(i).ENERGY==1)
plot(S(i).xd,S(i).yd,'+');
end
hold on;
end
end
plot(S(n+1).xd,S(n+1).yd,'x');
STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;
DEAD_N(r+1)=dead_n;
DEAD_A(r+1)=dead_a;
%When the first node dies
if (dead==1)
if(flag_first_dead==0)
first_dead=r
flag_first_dead=1;
end
end
countCHs=0;
cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ( (S(i).G)<=0)
%Election of Cluster Heads
if(temp_rand<= (p/(1-p*mod(r,round(1/p)))))
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
S(i).type='C';
S(i).G=round(1/p)-1;
C(cluster).xd=S(i).xd;
C(cluster).yd=S(i).yd;
plot(S(i).xd,S(i).yd,'k*');
distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 + (S(i).yd-(S(n+1).yd) )^2 );
C(cluster).distance=distance;
C(cluster).id=i;
X(cluster)=S(i).xd;
Y(cluster)=S(i).yd;
cluster=cluster+1;
%Calculation of Energy dissipated
distance;
if (distance>do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance ));
end
if (distance<=do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance * distance ));
end
end
end
end
end
STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;
%Election of Associated Cluster Head for Normal Nodes
for i=1:1:n
if ( S(i).type=='N' && S(i).E>0 )
if(cluster-1>=1)
min_dis=sqrt( (S(i).xd-S(n+1).xd)^2 + (S(i).yd-S(n+1).yd)^2 );
min_dis_cluster=1;
for c=1:1:cluster-1
temp=min(min_dis,sqrt( (S(i).xd-C(c).xd)^2 + (S(i).yd-C(c).yd)^2 ) );
if ( temp<min_dis )
min_dis=temp;
min_dis_cluster=c;
end
end
%Energy dissipated by associated Cluster Head
min_dis;
if (min_dis>do)
S(i).E=S(i).E- ( ETX*(4000) + Emp*4000*( min_dis * min_dis * min_dis * min_dis));
end
if (min_dis<=do)
S(i).E=S(i).E- ( ETX*(4000) + Efs*4000*( min_dis * min_dis));
end
%Energy dissipated
🎉3 参考文献
文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。
[1]李成岳,申铉京,陈海鹏,等.无线传感器网络中LEACH路由算法的研究与改进[J].传感技术学报, 2010, 23(8):5.DOI:10.3969/j.issn.1004-1699.2010.08.024.
[2]李芳芳,王靖.一种基于LEACH协议的无线传感器网络路由算法[J].传感技术学报, 2012, 25(10):7.DOI:10.3969/j.issn.1004-1699.2012.010.023.
[3]谢冬梅.无线传感器网络LEACH路由协议的研究[D].河海大学[2024-04-02].DOI:10.7666/d.y1030974.
[4] W.R.Heinzelman, A.P.Chandrakasan and H.Balakrishnan, "An application-specific protocol architecture for wireless microsensor networks" IEEE Transactions on Wireless Communications, 1(4):660-670,2002