无线传感器网络的电池寿命优化matlab源码

该文介绍了一种针对无线传感器网络(WSN)的电池寿命优化策略,通过修改LEACH协议引入了层次化的簇间通信。代码使用MATLAB实现,模拟了WSN中节点的能量效率,选择剩余能量高且距离基站近的节点作为簇头,并采用TDMA协议进行簇内通信。通过对WSN生命周期和平均能量消耗的管理,延长了网络的生存时间。
摘要由CSDN通过智能技术生成

无线传感器网络的电池寿命优化matlab源码

1 模型

Wireless sensor networks are comprised of independent sensors used to monitor physical/environmental conditions for example temperature, humidity and are distributed spatially. These sensors transmit their collected data to a sink. These sensor nodes are often put in distant areas where a constant energy supply can be a major challenge. Hence the sensors are generally battery operated which limits their energy consumption. An energy efficient optimization algorithm can prevent nodes from being profligate consumers of battery power and use it judiciously instead. Hierarchical routing protocols are the best known protocols to optimize energy consumption in WSNs. ILEACH is considered one of the best among them. To optimize the lifetime, it selects sensor nodes with higher residual energy and lower distance from the Base Station (BS) as Cluster Head (CH) nodes. Then it intelligently manages these nodes by constructing clusters such that the lifetime of WSN is maximized and its average energy dissipation is minimized. TDMA protocol is used for intra cluster communication. This paper proposes a modification of ILEACH protocol by introducing intercluster communication where cluster heads are arranged in a hierarchy, further optimizing the WSN lifetime.

2 部分代码

close all;
clear;
clc;
%-------------------------------
%Number of Nodes in the field
n=200;
%n=input('Enter the number of nodes in the space : ');
%Energy Model (all values in Joules)
%Initial Energy
Eo=0.1;
%Eo=input('Enter the initial energy of sensor nJ : ');
%Field Dimensions - x and y maximum (in meters)
% xm=input('Enter x value for area plot : ');
% ym=input('Enter y value for area plot : ');
xm=100;
ym=100;

%x and y/ Coordinates of the Sink
sink.x=1.5*xm;
sink.y=0.5*ym;

%Optimal Election Probability of a node
%to become cluster head
p=0.2;

%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;

%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.5;
%\alpha
a=1;

%maximum number of rounds
%rmax=input('enter the number of iterations you want to run : ');
rmax=200;
%------------------

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

%Creation of the random Sensor Network
figure(1);
hold off;
for i=1:1:n
   S(i).xd=rand(1,1)*xm;
   XR(i)=S(i).xd;
   S(i).yd=rand(1,1)*ym;
   YR(i)=S(i).yd;
   S(i).G=0;
   %initially there are no cluster heads only nodes
   S(i).type='N';
   
   temp_rnd0=i;
   %Random Election of Normal Nodes
   if (temp_rnd0 >= m*n+1)
       S(i).E=Eo;
       S(i).ENERGY=0;
       plot(S(i).xd,S(i).yd,'o-r');
       hold on;
   end
   %Random Election of Advanced Nodes
   if (temp_rnd0 < m*n+1)
       S(i).E=Eo*(1+a);
       S(i).ENERGY=1;
       plot(S(i).xd,S(i).yd,'+');
       hold on;
   end
end

   
   %Operation for epoch
   if(mod(r, round(1/p) )==0)
       for i=1:1:n
           S(i).G=0;
           S(i).cl=0;
       end
   end
   
   hold off;
   
   %Number of dead nodes
   dead=0;
   %Number of dead Advanced Nodes
   dead_a=0;
   %Number of dead Normal Nodes
   dead_n=0;
   
   %counter for bit transmitted to Bases Station and to Cluster Heads
   packets_TO_BS=0;
   packets_TO_CH=0;
   %counter for bit transmitted to Bases Station and to Cluster Heads
   %per round
   PACKETS_TO_CH(r+1)=0;
   PACKETS_TO_BS(r+1)=0;
   
   figure(1);
   
   for i=1:1:n
       %checking if there is a dead node
       if (S(i).E<=0)
           plot(S(i).xd,S(i).yd,'^','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','y', 'MarkerSize',8);
           dead=dead+1;
           if(S(i).ENERGY==1)
               dead_a=dead_a+1;
           end
           if(S(i).ENERGY==0)
               dead_n=dead_n+1;
           end
           hold on;
       end
       if S(i).E>0
           S(i).type='N';
           if (S(i).ENERGY==0)
               plot(S(i).xd,S(i).yd,'o','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','g', 'MarkerSize',8);
           end
           if (S(i).ENERGY==1)
               plot(S(i).xd,S(i).yd,'+','LineWidth',3, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
           end
           hold on;
       end
   end
   plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1, 'MarkerEdgeColor','k', 'MarkerFaceColor','r', 'MarkerSize',8);
   
   

   
   %Code for Voronoi Cells
   %Unfortynately if there is a small
   %number of cells, Matlab's voronoi
   %procedure has some problems
   warning('OFF');
  [vx,vy]=voronoi(X(:),Y(:));
   plot(X,Y,'g+',vx,vy,'m-');
   hold on;
   voronoi(X,Y);
   axis([10 xm 0 ym]);
end
% figure1 = figure11;
% % Create axes
% axes1 = axes('Parent',figure1,'YGrid','on','XGrid','on','GridLineStyle','--');
% box(axes1,'on');
% hold(axes1,'all');


% figure(2);
% for r=0:1:24
%     ylabel('Average Energy of Each Node');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
%     hold on;
% end
% figure(3);
% for r=0:1:49
%     ylabel('Average Energy of Each Node');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
%     hold on;
% end
% figure(4);
% for r=0:1:74
%     ylabel('Average Energy of Each Node');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
%     hold on;
% end
figure(2);
for r=0:1:rmax-1
   ylabel('Average Energy of Each Node');
   xlabel('Round Number');
   plot([r r+1],[STATISTICS(r+1).AVG STATISTICS(r+2).AVG],'red');
   hold on;
end
% figure(6);
% for r=0:1:24
%     ylabel('Number of Dead Nodes');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
%     hold on;
% end
% figure(7);
% for r=0:1:49
%         ylabel('Number of Dead Nodes');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
%     hold on;
% end
% figure(8);
% for r=0:1:74
%         ylabel('Number of Dead Nodes');
%     xlabel('Round Number');
%     plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
%     hold on;
% end
figure(3);
for r=0:1:rmax-1
   ylabel('Number of Dead Nodes');
   xlabel('Round Number');
   plot([r r+1],[STATISTICS(r+1).DEAD STATISTICS(r+2).DEAD],'red');
   hold on;
end
fid=fopen('LEACHGUI.txt','wt');
for r=0:1:rmax-1
   fprintf( fid, '%f ',STATISTICS(r+1).AVG);
end
fprintf(fid ,'\n');
for r=0:1:rmax-1
   fprintf( fid, '%f ',STATISTICS(r+1).DEAD);
end
fprintf(fid ,'\n');

3 仿真结果

4 参考文献

[1] Rueckert D ,  Sonoda L I ,  Hayes C , et al. Non-rigid registration using free. [J]. IEEE Transactions on Medical Imaging, 1999, 18(8):0-721.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值