LEACH 算法MATLAB仿真及其改进
LEACH算法仿真结果

仿真一:在100*100的区域内随机生成100个节点(matlab仿真代码: clear;xm=100;%x轴范围ym=100;%y轴范围sink.x=0.5*xm;%基站x轴 50sink.y=0.5*ym;%基站y轴 50n=100;E0=0.02;for i=1:1:nS(i).xd=rand(1,1)*xm;S(i).yd=rand(1,1)*ym;S(i).G=0;%每一周期结束此变量为0S(i).E=E0;%设置初始能量为E0S(i).type='N';%节点类型为普通plot(S(i).xd,S(i).yd,'o');hold on;end%设置SINK节点的坐标S(n+1).xd=sink.x;S(n+1).yd=sink.y;plot(S(n+1).xd,S(n+1).yd,'*');%绘制基站节点仿真结果图片:(‘O’代表随机散布的节点,‘*’代表SINK节点)仿真二:LEACH 分簇效果图(matlab 代码见附件)仿真结果:(p=0.1) 1、簇头个数14.01020304050607080901002、簇头个数:113、簇头个数:1201020304050607080901004、簇头个数:10102030405060708090100(p=0.05) 1、簇头=61020304050607080901002、簇头=73、簇头=124、簇头=81020304050607080901005、0102030405060708090100102030405060708090100xyLEACH 分簇算法成簇效果图仿真三:LEACH 分簇算法第一个节点死亡的轮数10203040506070809010001020304050607080901001020304050607080901000102030405060708090100第一死亡节点出现的分布及轮数xy0102030405060708090100xy经过matlab 仿真,LEACH 分簇算法在第一个节点死亡时,已经运行的轮数分别为: 122、143、125、149、122、72.仿真四:20%的节点死亡时分布及轮数1、yx 2、yxy0102030405060708090100x轮数:196、207、205、181.。
LEACH协议的MATLAIB仿真代码

Matlab Code for LEACH NodeNums = 100; % thenum of nodeAreaR = 100 ; % the area of simulateNodeTranR=10; % the transit RadiusElec=50 * 10^(-9); %Eamp=100*10^(-12);Bx=50; % The Postion of BaseationBy=175;MaxInteral =700; % the leach simulate timePch=0.05; % the desired percentage of cluster headsInitEn=0.5; % the init energy of all nodeTr=30;TDMA=100;Kbit=2000; % the bits of a node transmiting a packet every time BandWitch = 1*10.^(6); % Channel BandwitchTOS_LOCAL_ADDRESS = 0;for i=1:(MaxInteral)AliveNode(i)=NodeNums;AmountData(i)=0;endsym alldata;alldata=0;LAECH = zeros(1,MaxInteral);LAENO = zeros(1,MaxInteral);for i=1:1:NodeNumsEnNode(i)=InitEn; % the init energy of all nodeStateNode(i)=1; % the State of all node 1: alive 0:deadClusterHeads(i)=0; % the Set of Cluster Head ,1: cluster head 0 :node Rounds=0; % the roundendThreshold=0; % the threshold of node becoming a cluster-head Node.x=AreaR*rand(1,NodeNums); % the position of nodeNode.y=AreaR*rand(1,NodeNums);Node.c=zeros(1,NodeNums);Node.d=zeros(1,NodeNums);Node.l=zeros(1,NodeNums);Node.csize=zeros(1,NodeNums);Node.initclEn=zeros(1,NodeNums);% for i=1:NodeNums% Node.c(i)=0; % the Cluster head of node% Node.d(i)=0; % the distance between cluster head and node % Node.l(i)=Kbit; % the length of node i transmit packet% Node.csize(i)=0;% endfor Rounds = 1:MaxInteral% the Setup phase of clusterNode.csize=Node.csize-Node.csize;Node.d=Node.d-Node.d;Node.c=Node.c-Node.c;for i =1:NodeNumsThreshold=Pch/(1-Pch*(mod(Rounds-1,1/Pch)));if StateNode(i)==1 % if node is aliveif ClusterHeads(i) ==1ClusterHeads(i)=0;elseif rand(1,1)<ThresholdClusterHeads(i)=1;Node.c(i)=TOS_LOCAL_ADDRESS;Node.initclEn(i)=EnNode(i);else ClusetHeads(i)=0;Node.initclEn(i)=EnNode(i);endendendif sum(ClusterHeads)==0continue;endEntranPCH = Elec * Kbit+ Eamp*Kbit*((Tr.^2+Tr.^2)); % The expended engergy by new Cluster head advertising that it is new cluster headfor i=1:NodeNumsif ClusterHeads(i) ==1if EnNode(i) >= EntranPCHEnNode(i) = EnNode(i) - EntranPCH ;elseStateNode(i)=0;endendendfor i=1:NodeNumsif StateNode(i)==1 % if node is aliveif ClusterHeads(i) ~=1 % the node is not cluster headfor j=1:NodeNumsif ClusterHeads(j) ==1dist = ((Node.x(i)-Node.x(j)).^2)+((Node.y(i)-Node.y(j)).^2); % the distance.^2% if dist < (Tr.^2+Tr.^2) % blong to the transmit radiusEnRecP = Elec * Kbit ;if EnNode(i) >= EnRecP % the energy reciving a boardcast packet can expendEnNode(i) = EnNode(i) - EnRecP ;elseStateNode(i)=0;endif Node.d(i) ==0 % choose the cluster headNode.d(i)=dist ;Node.c(i)=j;elseif Node.d(i) > distNode.d(i)=dist ;Node.c(i)=j;endend% endend%%%%% end of choosing the cluster head ,Node.c(i) save the id of %%%%% cluster headendif StateNode(i)==1Node.csize(Node.c(i))= Node.csize(Node.c(i))+1;endelse % the node is cluster headNode.d(i)=((Node.x(i)-Bx).^2)+((Node.y(i)-By).^2) ;Node.c(i)=TOS_LOCAL_ADDRESS;endendend% painting the node and the cluster head% for i=1:NodeNums% if ClusterHeads(i)==1% plot(Node.x(i),Node.y(i),'rs');% hold on;% else plot(Node.x(i),Node.y(i),'k*'); % hold on;% end% end% the TDMA Phasealldata=0;for i=1:NodeNumsif StateNode(i)==1if ClusterHeads(i)==1TolLengthPacket = Kbit.*Node.csize(i); alldata=alldata+TolLengthPacket; EntranPCH = Elec * TolLengthPacket+ Eamp*TolLengthPacket*(Node.d(i)); EntranPCH.*TDMA;if EnNode(i) >= EntranPCHEnNode(i) = EnNode(i) - EntranPCH ; elseStateNode(i)=0;endelseEntranP = Elec * Node.l(i)+ Eamp*Node.l(i)*(Node.d(i)); EntranP=EntranP.*TDMA;if EnNode(i) >= EntranPEnNode(i) = EnNode(j)-EntranP;elseStateNode(i)=0; % the node deadendEnRecP = Elec * Node.l(i) ;EnRecP=EnRecP.*TDMA;if EnNode(Node.c(i)) >= EnRecPEnNode(Node.c(i)) = EnNode(i) - EnRecP ;elseStateNode(Node.c(i))=0;endendendendif Rounds==1AmountData(Rounds)=alldata;elseAmountData(Rounds)=alldata+AmountData(Rounds-1); endfor i=1:NodeNumsif StateNode(i)==0AliveNode(Rounds)= AliveNode(Rounds)-1;endend% the TDMA Phase% for RNum=1:TDMA% for i=1:NodeNums% if ClusterHeads(i)==1% % EntranPCH = Elec * Node.l(i)+Eamp*Node.l(j)*(Eamp*Node.l(j).^2);% TolLengthPacket = 0;% for j=1:NodeNums% if Node.c(j) ==i% TolLengthPacket =TolLengthPacket+ Node.l(j);% EntranP = Elec * Node.l(j)+ Eamp*Node.l(j)*(Node.d(j)); % The require energy of node transmitting a packet% EnRecP = Elec * Node.l(j) ; % The require energy of recving a packet% if EnNode(j) >= EntranP% EnNode(j) = EnNode(j)-EntranP;% else% StateNode(j)=0; % the node dead% end% if EnNode(i) >= EnRecP% EnNode(i) = EnNode(i) - EnRecP ;% else% StateNode(i)=0;% end% end% end% EntranPCH = Elec * TolLengthPacket+ Eamp*TolLengthPacket*(Node.d(j));% if EnNode(i) >= EntranPCH% EnNode(i) = EnNode(i) - EntranPCH ; % else% StateNode(i)=0;% end% end% end% endsyms sumch sumno countch countno ; sumch=0;sumno=0;countch=0;countno=0;for i=1:NodeNumsif Node.initclEn(i)>0if ClusterHeads(i)==1sumch=sumch+Node.initclEn(i);countch=countch+1;elsesumno=sumno+ Node.initclEn(i);countno=countno+1;endendif StateNode(i)==0AliveNode(Rounds)= AliveNode(Rounds)-1; endendLAECH(Rounds) = sumch/countch;LAENO(Rounds) = sumno/countno;% Rounds = Rounds+1endxtime= 1:1:MaxInteral;plot(xtime,AliveNode);%clear ;% plot(Node.x,Node.y);% plot(Node.x,Node.y,'--rs','LineWidth',2,... % 'MarkerEdgeColor','k',...% 'MarkerFaceColor','g',...% 'MarkerSize',10);% plot(Node.x,Node.y,'k*');。
一种LEACH协议的改进算法LEACH_EH

一种LEACH协议的改进算法LEACH_EH徐鹏【期刊名称】《微型机与应用》【年(卷),期】2014(33)11【摘要】根据 LEACH 协议的特点和局限性对其进行了改进,提出了一种LEACH_EH ( LEACH EAHANCE )算法。
它使用 K_MEANS 算法对簇进行一次性分簇,之后结合节点到簇内质心距离与节点自身剩余能量选举出簇头。
它将簇形成的顺序由先簇头后成簇变为先成簇后簇头,形成一次分簇多次选举簇头的模式。
通过 MATLAB 进行仿真,实验结果表明,改进后的算法比原来的协议在节点能量均衡方面有了较大的提升,延长了网络生存周期。
%This paper propose a LEACH_EH algorithm based on the characteristics and limitations of the LEACH protocol.It uses the K_MEANS algorithm to cluster only once, and then elects the cluster heads by considersing the distance from node to cluster center and the node′s residual energy. It makes the order from electing cluster first and clustering second to clustering first and electing cluster second. It forms the formation of clustering only once and electing cluster multi-times. The MATLAB simulation shows that comparing with LEACH, the LEACH_ED algorithm has a great improvement in the energy balance of the node,and prolong the network life cycle abviously.【总页数】5页(P51-55)【作者】徐鹏【作者单位】华侨大学计算机科学与技术学院,福建厦门 361000【正文语种】中文【中图分类】TN929.5;TP212.9【相关文献】1.一种针对无线传感器网络LEACH协议的改进算法 [J], 石闪;施伟斌;朱蓓2.一种LEACH协议的多级分簇改进算法 [J], 罗冰;黄玉清3.一种针对无线传感器网络LEACH协议的改进算法 [J], 孙建伟;王绍辰;贾军营4.WSN中一种基于LEACH协议的改进算法 [J], 周洁;石志东;张震;单联海;房卫东5.一种基于LEACH协议的改进路由算法 [J], 王飞飞;丁亚飞因版权原因,仅展示原文概要,查看原文内容请购买。
无线传感器网络LEACH算法的改进

无线传感器网络LEACH算法的改进无线传感器网络(WSN)是由大量分布在空间中的无线传感器节点组成的网络,用于监测、收集和传输环境信息或事件。
它被广泛应用于环境监测、军事监测、医疗保健、工业自动化等领域。
由于传感器节点的能量有限,传感器节点之间的通信受限,需要能耗较低的网络协议来延长网络的寿命。
LEACH(Low-Energy Adaptive Clustering Hierarchy)算法是一种用于节能的无线传感器网络协议,通过聚类和轮换角色的方式降低传感器节点的能量消耗,延长整个网络的寿命。
LEACH算法仍然存在一些问题,需要进行改进。
本文将介绍LEACH算法的基本原理,以及一些对LEACH算法的改进方法,以提高其在无线传感器网络中的性能和效率。
一、LEACH算法介绍1. LEACH算法基本原理LEACH算法是一种典型的分簇式无线传感器网络协议,它通过聚类和轮换簇头的方式降低传感器节点的能量消耗。
LEACH算法的基本原理如下:(1)初始化阶段:初始化每个节点的能量,并设置阈值T,根据T决定哪些节点将成为簇头节点。
(2)簇头选择阶段:每个节点以概率的方式成为簇头节点,概率与其剩余能量成正比。
(3)簇形成阶段:非簇头节点将根据其距离最近的簇头节点进行加入。
(4)数据传输阶段:簇头节点收集数据并传输给基站。
(5)簇头轮换阶段:为了均衡网络中各个节点的能量消耗,每个簇头节点在每一轮中都会轮换。
2. LEACH算法存在的问题尽管LEACH算法在节能方面有一定的优势,但是它也存在一些问题:(1)簇头选择过程没有考虑传感器节点的位置及其与基站之间的距离。
(2)没有考虑网络中节点的能量消耗不均匀问题。
(3)没有充分考虑网络中的数据传输量,可能导致某些簇头节点负载过重。
1. 基于节点位置的改进通过引入节点位置信息,可以更合理地选择簇头节点,避免一些节点成为簇头节点后,由于其位置过远而导致能量消耗过大。
可以根据节点与基站之间的距离进行簇头节点的选择,以减少能量消耗。
一种改进的LEACH模型及其仿真分析

Ab t a t T r l n h ewo k l e me e e t eylh r d t n ll w n r y a a t e cus rn ir r h g rt m a e i r v d sr c : o p o o g t e n t r i t fi f c v l t e ta ii a o e e g d p v l t i g h e a c y a o h c n b mp o e i o i e l i i SN,mp o e g r m a d LEACH—EC.A i h—p o a i t e e t g me h n s i i to u e o s lc e c u t rn e d nW i rvda o t l i h n me hg r b b l y s lc i c a im s n r d c d t ee tt l se g h a i n h i
关 键词 : 线传感 器 网络 ; 功耗 路 由 ; 无 低 剩余能 量 ; 点集 中度 ; 头选 取 节 簇
中图分类 号 : P { T3 文献 标识 码 : A
.
文 章编 — 2 X(0 2 0 — 15 0
An I r v d LEACH o e n i lto a y i mp o e M d la d S mu a in An l ss
Ke r s: S ; w n r y m ui g;e i u le e g n d e ta i h a l tn y wo d W Ns l o e eg t n r sd a n r y; o e c n r lt e d s e ig y; ec
0 引 言
无 线 传 感 器 网 络 ( r es S no e ok , Wi ls esr N t rs e w
无线传感器网络LEACH算法的改进与仿真

t i p p rwe a ay e t e o e ai g p n i l fL AC p oo o n r s n n i rv d ag r h , ih tk s it c o n h r tc l S hs a e n lz h p r t r cp e o E H r tc la d p e e t mp o e lo i m wh c a e n o a c u tte p oo o ’ n i a t
p r me es c n i e n t e r a d o iin ic m sa e f t e o e a a tr o sd r g he neg i y n p sto cr u tnc o h n d s,h n e h n d wih e c t e o e t hih r r d mi a c i c mp e nsv g e p e o n n e n o r he ie
p r r n e i s lce o b h l se e d S mu ain rs l e n tae t a e i r v d a g rtm up romst e L e o ma c s ee td t e t e c u t rh a . i lt e ut d mo srt h tt mp o e lo h o t ef r h EAC r tc l n f o s h i H p oo o i
p ro m a e fe e g e ucin, e wo k lftm e p oo g to nd m o trn o e a e a s r n e, t. e r nc s o n r y r d to n t r iei r ln a in a nio g c v rg s u a c ec f i
LEACH 算法MATLAB仿真及其改进

LEACH 算法MATLAB 仿真及其改进1. LEACH 原理LEACH 协议,全称是“低功耗自适应集簇分层型协议” (Low Energy Adaptive Clustering Hierarchy),是一种无线传感器网络路由协议。
基于LEACH 协议的算法,称为LEACH 算法。
LEACH 是MIT 的Chandrakasan 等人为无线传感器网络设计的低功耗自适应聚类路由算法。
与一般的平面多跳路由协议和静态聚类算法相比,LEACH 可以将网络生命周期延长15%,主要通过随机选择聚类首领,平均分担中继通信业务来实现。
LEACH 定义了“轮”(round)的概念,一轮由初始化和稳定工作两个阶段组成。
为了避免额外的处理开销,稳定态一般持续相对较长的时间。
在初始化阶段,聚类首领是通过下面的机制产生的。
传感器节点生成0,1之间的随机数,如果大于阈值T,则选该节点为聚类首领T 的计算方法如下:()[]p r P PT 1mod 1-= (1)其中p 为节点中成为聚类首领的百分数,r 是当前的轮数。
当簇头选定之后,簇头节点主动向网络中节点广播自己成为簇头的消息。
接收到此消息的节点,依据接收信号的强度,选择它所要加入的簇,并发消息通知相应的簇头。
基于时分多址(Time Division Multiple Address ,简称TDMA)的方式,簇头节点为其中的每个成员分配通信时隙,并以广播的形式通知所有的簇内节点。
这样保证了簇内每个节点在指定的传输时隙进行数据传输,而在其他时间进入休眠状态,减少了能量消耗。
在稳定工作阶段,节点持续采集监测数据,在自身传输时隙到来时把监测数据传给簇头节点,簇头节点对接收到数据进行融合处理之后,发送到Sink 节点,这是一种减小通信业务量的合理工作模式。
持续一段时间以后,整个网络进入下一轮工作周期,重新选择簇头节点。
LEACH 协议采用动态转换簇头的方法来平均网络节点的能量消耗,使因能量耗尽而失效的节点呈随机分布状态,因而与一般的多跳路由协议和静态簇算法相比,LEACH 可以将网络生命周期延长15%。
无线传感器网络LEACH算法的改进与仿真

无线传感器网络LEACH算法的改进与仿真万传飞;杜尚丰【摘要】LEACH(low energy adaptive clustering hierarchy)是无线传感器网络层次型拓扑控制中最重要和最具代表性的算法之一.分析了LEACH协议的工作原理,并针对其在簇头选择上存在的不足,提出改进:考虑节点的能量和位置状况,通过引入能量、密度和距离调节参数来修正簇头当选阚值,从而选择出综合性能更为优越的节点担任簇首.仿真实验结果显示,改进后的算法在降低能耗、延长网络生存时间以及保证监测覆盖度等方面比LEACH具有更加优良的性能.%LEACH is one of the most important and representative hierarchical topology control protocols in wireless sensor networks.In this paper we analyze the operating principle of LEACH protocol and present an improved algorithm,which takes into account the protocol' s shortcoming in selecting cluster-head, that rectifies the elected threshold of cluster head by introducing energy, density and distance adjust parameters considering the energy and position circumstance of the nodes, hence the node with higher predominance in comprehensive performance is selected to be the cluster head.Simulation results demonstrate that the improved algorithm outperforms the LEACH protocol in performances of energy reduction, network lifetime prolongation and monitoring coverage assurance, etc.【期刊名称】《计算机应用与软件》【年(卷),期】2011(028)004【总页数】4页(P113-116)【关键词】无线传感器网络;层次型拓扑控制;LEACH【作者】万传飞;杜尚丰【作者单位】中国农业大学信息与电气工程学院,北京,100083;中国农业大学信息与电气工程学院,北京,100083【正文语种】中文0 引言低功耗自适应分簇算法LEACH[1,2]是1999年由麻省理工大学(MIT)电子工程与计算机科学学院的Heinzelman W.R等人提出的,它是第一个以分簇为基础的层次路由协议,是无线传感器网络层次型拓扑控制最重要和最具代表性的算法。