資源簡介
leach基本代碼,適用使用matlab仿真。
代碼片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%??????????????????????????LEACH?Protocol??????????????????????????????%
%??????????????????????????Part?of?Thesis:?????????????????????????????%
%???????Energy-Efficient?Protocols?In?Wireless?Sensor?Networks?????????%
%??????????????????????????????????????????????????????????????????????%
%?(c)?Alexandros?Nikolaos?Zattas???????????????????????????????????????%
%?University?of?Peloponnese????????????????????????????????????????????%
%?Department?of?Informatics?and?Telecommunications?????????????????????%
%?For?any?related?questions?or?additional?information??????????????????%
%?send?an?e-mail?to:???????????????????????????????????????????????????%
%?alexzattas@gmail.com?????????????????????????????????????????????????%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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(11)*xm; %?X-axis?coordinates?of?sensor?node
????SN(i).y=rand(11)*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
評論
共有 條評論