一种用于提高无线传感器网络寿命的改进LEACH协议(Matlab代码实现)

    目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码

💥1 概述

无线传感器网络具有网络灵活性强、网络规模可变等优点,广泛应用于军事、工业等领域。无线传感器网络的基本网络路由协议可以分为平面路由协议和层次路由协议。由于平面路由协议需要维护大的路由表和占用更多的存储空间,因此它们不适合于大规模网络,因此分层路由协议试图通过将节点安排在簇或树结构中,使一些节点在很近的距离内传输到一个节点,并将其用于让这些节点将此信息转发到基站。LEACH是一种比较成熟的具有代表性的经典分层路由算法。其他分层路由协议如pegasis、teen等在LEACH上得到了改进,因此LEACH更具代表性。本文主要研究LEACH算法,在降低功耗的基础上进行了改进,有效提高无线传感器的网络寿命​。​

📚2 运行结果

主函数部分代码:

close all;
clear;
clc;
%%%%%%%%%%%%%%%%%%%% Network Establishment Parameters %%%%%%%%%%%%%%%%%%%%
%%% Area of Operation %%%
% Field Dimensions in meters %
xm=100;
ym=100;
x=0; % added for better display results of the plot
y=0; % added for better display results of the plot
% Number of Nodes in the field %
n=100;
% Number of Dead Nodes in the beggining %
dead_nodes=0;
% Coordinates of the Sink (location is predetermined in this simulation) %
sinkx=50;
sinky=200;
%%% Energy Values %%%
% Initial Energy of a Node (in Joules) % 
Eo=2; % units in Joules
% Energy required to run circuity (both for transmitter and receiver) %
Eelec=50*10^(-9); % units in Joules/bit
ETx=50*10^(-9); % units in Joules/bit
ERx=50*10^(-9); % units in Joules/bit
% Transmit Amplifier Types %
Eamp=100*10^(-12); % units in Joules/bit/m^2 (amount of energy spent by the amplifier to transmit the bits)
% Data Aggregation Energy %
EDA=5*10^(-9); % units in Joules/bit
% Size of data package %
k=4000; % units in bits
% Suggested percentage of cluster head %
p=0.05; % a 5 percent of the total amount of nodes used in the network is proposed to give good results
% Number of Clusters %
No=p*n; 
% Round of Operation %
rnd=0;
% Current Number of operating Nodes %
operating_nodes=n;
transmissions=0;
temp_val=0;
flag1stdead=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%% End of Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%
            %%% Creation of the Wireless Sensor Network %%%
% Plotting the WSN %
for i=1:n
    
    SN(i).id=i;  % sensor's ID number
    SN(i).x=rand(1,1)*xm;  % X-axis coordinates of sensor node
    SN(i).y=rand(1,1)*ym;  % Y-axis coordinates of sensor node
    SN(i).E=Eo;     % nodes energy levels (initially set to be equal to "Eo"
    SN(i).role=0;   % node acts as normal if the value is '
0
', if elected as a cluster head it  gets the value '
1
' (initially all nodes are normal)
    SN(i).cluster=0;  % the cluster which a node belongs to
    SN(i).cond=1;  % States the current condition of the node. when the node is operational its value is =1 and when dead =0
    SN(i).rop=0;  % number of rounds node was operational
    SN(i).rleft=0;  % rounds left for node to become available for Cluster Head election
    SN(i).dtch=0;  % nodes distance from the cluster head of the cluster in which he belongs
    SN(i).dts=0;    % nodes distance from the sink
    SN(i).tel=0;  % states how many times the node was elected as a Cluster Head
    SN(i).rn=0;     % round node got elected as cluster head
    SN(i).chid=0;   % node ID of the cluster head which the "i" normal node belongs to
    
    hold on;
    figure(1)
    plot(x,y,xm,ym,SN(i).x,SN(i).y,'
ob
',sinkx,sinky,'
*r
');
    title '
Wireless Sensor Network
';
    xlabel '
(m)
';
    ylabel '
(m)
';
    
end
 
                      %%%%%% Set-Up Phase %%%%%% 
                      
             
while operating_nodes>0
        
    % Displays Current Round %     
    rnd     
    %transmissions
  % Threshold Value %
  t=(p/(1-p*(mod(rnd,1/p))));
    
    % Re-election Value %
    tleft=mod(rnd,1/p);
 
  % Reseting Previous Amount Of Cluster Heads In the Network %
  CLheads=0;
    
    % Reseting Previous Amount Of Energy Consumed In the Network on the Previous Round %
    energy=0;
 
        
        
% Cluster Heads Election %
    
        for i=1:n
            SN(i).cluster=0;    % reseting cluster in which the node belongs to
            SN(i).role=0;       % reseting node role
            SN(i).chid=0;       % reseting cluster head id
            if SN(i).rleft>0
               SN(i).rleft=SN(i).rleft-1;
            end

🎉3 参考文献

[1]倪文亚. 无线传感器网络Leach路由协议的研究与改进[D].华东理工大学,2015.

部分理论引用网络文献,若有侵权联系博主删除。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值