无线传感器网络的电池寿命优化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.