无线传感器网络路由协议的研究LEACH与SEP协议 联系客服

发布时间 : 星期日 文章无线传感器网络路由协议的研究LEACH与SEP协议更新完毕开始阅读

南京邮电大学2012届毕业设计(论文)

附录

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%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;

24

南京邮电大学2012届毕业设计(论文)

?lec=Etx=Erx

ETX=50*0.000000001; ERX=50*0.000000001;

%Transmit Amplifier types Efs=10*0.000000000001; Emp=0.0013*0.000000000001; úta 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=1999;

%%%%%%%%%%%%%%%%%%%%%%%%%

END PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%

%Computation of do do=sqrt(Efs/Emp);

%Creation of the random Sensor Network

figure(1);

for i=1:1:n

S1(i).xd=rand(1,1)*xm; XR1(i)=S1(i).xd; S1(i).yd=rand(1,1)*ym; YR1(i)=S1(i).yd;

S1(i).G=0;

%initially there are no cluster heads only nodes S1(i).type='N';

temp_rnd01=i;

%Random Election of Normal Nodes if (temp_rnd01>=m*n+1) S1(i).E=Eo;

S1(i).ENERGY=0;

plot(S1(i).xd,S1(i).yd,'o'); hold on; end

25

OF

南京邮电大学2012届毕业设计(论文)

%Random Election of Advanced Nodes if (temp_rnd01

plot(S1(i).xd,S1(i).yd,'+'); hold on; end

end

S1(n+1).xd=sink.x; S1(n+1).yd=sink.y;

plot(S1(n+1).xd,S1(n+1).yd,'x');

%First Iteration

figure(1);

%counter for CHs countCHs1=0;

%counter for CHs per round rcountCHs1=0; cluster1=1;

countCHs1;

rcountCHs1=rcountCHs1+countCHs1; flag_first_dead1=0;

for r=0:1:rmax r

%Operation for epoch

if(mod(r, round(1/p) )==0) for i=1:1:n S1(i).G=0; S1(i).cl=0; end end

hold off;

%Number of dead nodes

dead1=0;

%Number of dead Advanced Nodes dead_a1=0;

26

南京邮电大学2012届毕业设计(论文)

%Number of dead Normal Nodes dead_n1=0;

%counter for bit transmitted to Bases Station and to Cluster Heads packets_TO_BS1=0;

packets_TO_CH1=0;

%counter for bit transmitted to Bases Station and to Cluster Heads %per round

PACKETS_TO_CH1(r+1)=0; PACKETS_TO_BS1(r+1)=0;

for i=1:1:n

%checking if there is a dead node if (S1(i).E<=0)

plot(S1(i).xd,S1(i).yd,'red .'); dead1=dead1+1;

if(S1(i).ENERGY==1) dead_a1=dead_a1+1; end

if(S1(i).ENERGY==0) dead_n1=dead_n1+1; end

hold on; end

if S1(i).E>0

S1(i).type='N';

if (S1(i).ENERGY==0)

plot(S1(i).xd,S1(i).yd,'o'); end

if (S1(i).ENERGY==1)

plot(S1(i).xd,S1(i).yd,'+'); end

hold on; end

%ALIVE=100-dead; % plot(i,ALIVE,'b-');

end

plot(S1(n+1).xd,S1(n+1).yd,'x');

STATISTICS1(r+1).DEAD=dead1; DEAD1(r+1)=dead1;

DEAD_N1(r+1)=dead_n1;

27