基于LEACH和HEED的WSN路由协议研究与改进(Matlab代码实现)

    目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码


💥1 概述

无线传感器网络(Wireless Sensor Networks,WSN)作为一种新兴的信息获取技术,被誉为21世纪将影响世界的十大技术之首,以其广泛的应用,受到人们的重视。无线传感器网络通过撒播具有无线通信能力的传感器节点在监测区域,来感知、收集、处理监测区域的物理信息,并把信息反馈给控制台。由于低功耗、低成本、分布式和自组织的特点,无线传感器网络被广泛的应用于在军事、航空、防爆、救灾、环境、医疗、保健、家居、工业、商业等领域。在无线传感器网络的应用中,成千上万的传感器节点被散布在人迹罕至的监测区域,传感器节点通常是通过电池来进行供电的,传感器节点部署完成后很难进行电池的更换,一旦节点能量耗尽,将会失去作用,过多的节点失效会导致网络瘫痪,因此节点能量显得弥足珍贵。所以,研究高效、节能,能延长网络生命周期的网络协议非常重要。

📚2 运行结果

 

 

 

🎉3 参考文献

[1]杨梦宁,杨丹,黄超.无线传感器网络中改进的HEED分簇算法[J].重庆大学学报,2012,35(08):101-106.

👨‍💻4 Matlab代码

主函数部分代码:

% Clean memory and command window
clear,clc,close all

%% Parameters
N = 100;             % Number of nodes
W = 200;             % length of the network
L = 200;             % width of the network
Ei = 2;              % Initial energy of each node (joules)
CHpl = 3000;         % Packet size for cluster head per round (bits)

p = 5/100;           % desired percentage of cluster heads
R = 50;              % Range for cluster
pMin = 10^-4;        % Lowest possible CH_prop

num_rounds = 2000;   % Max Number of simulated rounds
NonCHpl = 200;       % Packet size for normal node per round (bits)
Tsetup = 4;          % average Time in seconds taken in setup phase
Tss = 10;            % average Time in seconds taken in steady state phase
Etrans = 1.0000e-05; % Energy for transmitting one bit 
Erec = 1.0000e-05;   % Energy for receiving one bit 
Eagg = 1.0000e-07;   % Data aggregation energy
Efs = 0.3400e-9;     % Energy of free space model amplifier
% Position of sink
SX = W/2; SY = L/2;


%% First Leach algorithm %%%%%%%%%%%%%%%%%%%%%%%%%%

% 1st row: states of being a CH, 1:never been CH, 0:has been CH 
% 2nd: x-position, 3rd: y-position
net = [ones(1,N);rand([1,N])*W;rand([1,N])*L];

% Preallocation for energy calculations
E = Ei*ones(1,N);          % Energy left in each node
EH = zeros(1,num_rounds); 
% Preallocation for dead nodes calculations
Ecrit = 0;                 % Critical energy left in node to call it alive
Ncrit = fix((95/100)*N);   % Critical number for dead nodes to stop simulation
Dead = false(1,N);         % Status of all nodes 0:Alive 1:Dead
DeadH = zeros(1,num_rounds);
% Preallocation for Bits sent calculations
BitsH = zeros(1,num_rounds);
figure('Position',[34 30 792 613]);

% Simulating for each round
for r=1:num_rounds % iterating on each round
    
    %%%% Choosing Clusters heads %%%%
    [net(1,:),CH] = Leach_algo(net(1,:),Dead,p,r);
    tmp = find(CH);
    for i=1:N
        if isempty(net(2,CH))
            
        else
            [~,aa]=min(sqrt((net(2,CH) - net(2,i)).^2 + (net(3,CH) - net(3,i)).^2));
            net(1,i) = tmp(aa);
        end
    end

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值