Programme for Leach Protocol in WSN
close all
clear all
clc
clf
%%%% program for number of node%%%%%%%%%%%%
n=100
y=randint(1,n,[0,n])
x=-(n/2):1:((n/2)-1)
figure(1)
plot(x,y,'o')
title('100 node random network')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
n=100;
y=( randint(1,n,[0 n]));
p= sort(y);
t=(randint(1,n,[0 580]))*.8;
t1= sort(t)
for i=1:1:n
y(i)= p(n+1-i)
if( t1(i)< 150)
y1(i)=100;
end
if (t1(i)>380)
y1(i)=0;
end
if ((t1(i)>= 150)& (t1(i)<=380))
y1(i)=y(i);
end
end
for i=1:1:n
y(i)= p(n+1-i)
if(t1(i)<25)
y3(i)=100;
else
y3(i)=y(i)*.7;
end
end
figure(3)
plot(t1,y1,'-
r','linewidth',3,'MarkerEdgeColor','r','MarkerFaceColor',[.42 .5 .60],
'MarkerSize',6)
hold on
plot(t1,y3,'-
.b','linewidth',3,'MarkerEdgeColor','b','MarkerFaceColor',[.42 .5 .60],
'MarkerSize',6)
xlabel('Time steps (rounds)')
ylabel('Number of node still alive')
title('system life time using direct transmission and MTE routing with
.5 j/node')
legend('Direct','MTE')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%
n=100
nod=[0 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 ]
评论0