matlab实现无线传感器网络DV-HOP算法中如何计算能量损耗

关于matlab实现无线传感器网络DV-HOP算法中如何计算能量损耗
用MATLAB实现无线传感器网络DV-HOP算法,然后根据下列文字编写代码计算能量损耗:  
目前,在低能量无线电通信领域有大量的研究。无线电通信特性的不同假设,包括传输和接收模型中的能量消耗,将决定不同协议的优势所在。在我们的工作中,我们假设了一个简单的模型,无线电通信消耗的能量来运行传输或接收电路Eelec=50nJ/ bit,以及作为传输信号增益,Eamp=100pJ/bit/m2以达到一个可接受的Eb/Nb。
  这些参数略高于无线电通信设计的目前的技术水平。我们同时假设了因信道传输造成的的能量损耗。因此,使用我们的无线电通信模型,为了传输一个k位的信息到距离为d的地方,无线电通信将消耗:
  ETx(k,d)=ETx-elec(k)+ETx-amp(k,d) (1)
  ETx(k,d)=Eelec*k+Eamp*k*d2

为了接收该信息,无线电通信将消耗:

  ERx(k)=ERx-elec(k) (2)
  ERx(k)=Eelec*k
  根据这些参数值可以看出,接收一条信息代价很高,因此协议应该力求实现不但使传输距离最小化,而且让每条信息的传输数量和接收操作最小化。
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DV-Hop算法 ~~~~~~~~~~~~~~~~~~~~~~~~
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% BorderLength-----正方形区域的边长,单位:m
% NodeAmount-------网络节点的个数
% BeaconAmount---信标节点数
% Sxy--------------用于存储节点的序号,横坐标,纵坐标的矩阵
%Beacon----------信标节点坐标矩阵;BeaconAmount*BeaconAmount
%UN-------------未知节点坐标矩阵;2*UNAmount
% Distance------未知节点到信标节点距离矩阵;2*BeaconAmount
%h---------------节点间初始跳数矩阵
%X---------------节点估计坐标初始矩阵,X=[x,y]'
% R------------------节点的通信距离,一般为10-100m

clear,close all;
k=2000;
E_elec=50*0.000000001;
E_amp=100*0.000000000001;
E_da=5*0.000000001;
E_0=0.5;%初始能量
E_b=0.1;%波动能量
maxx=40;%节点分布范围
maxy=40;%节点分布范围
BorderLength=100;
NodeAmount=100;
BeaconAmount=9;
UNAmount=NodeAmount-BeaconAmount;
R=50;

% D=zeros(NodeAmount,NodeAmount);%未知节电到信标节点距离初始矩阵;BeaconAmount行NodeAmount列
h=zeros(NodeAmount,NodeAmount);%初始跳数为0;BeaconAmount行NodeAmount列
X=zeros(2,UNAmount);%节点估计坐标初始矩阵

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~在正方形区域内产生均匀分布的随机拓扑~~~~~~~~~~~~~~~~~~~~
C=-50+BorderLength.*rand(2,NodeAmount);%生成随机坐标
%带逻辑号的节点坐标
Sxy=[[1:NodeAmount];C];
Beacon=[Sxy(2,1:BeaconAmount);Sxy(3,1:BeaconAmount)];%信标节点坐标
UN=[Sxy(2,(BeaconAmount+1):NodeAmount);Sxy(3,(BeaconAmount+1):NodeAmount)];%未知节点坐标
%画出节点分布图
plot(Sxy(2,1:BeaconAmount),Sxy(3,1:BeaconAmount),'r*',Sxy(2,(BeaconAmount+1):NodeAmount),Sxy(3,(BeaconAmount+1):NodeAmount),'k.')
xlim([5-0,BorderLength/2]);
ylim([-50,BorderLength/2]);
title('* 红色信标节点 . 黑色未知节点')
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~初始化节点间距离、跳数矩阵~~~~~~~~~~~~~~~~~~~~~~
for i=1:NodeAmount
for j=1:NodeAmount
Dall(i,j)=((Sxy(2,i)-Sxy(2,j))^2+(Sxy(3,i)-Sxy(3,j))^2)^0.5;%所有节点间相互距离
if (Dall(i,j)<=R)&(Dall(i,j)>0)
h(i,j)=1;%初始跳数矩阵
elseif i==j
h(i,j)=0;
else h(i,j)=inf;
end
end
end
%~~~~~~~~~~~~~~~~~~~~~~~~~最短路经算法计算节点间跳数~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for k=1:NodeAmount
for i=1:NodeAmount
for j=1:NodeAmount
if h(i,k)+h(k,j)<h(i,j)%min(h(i,j),h(i,k)+h(k,j))
h(i,j)=h(i,k)+h(k,j);
end
end
end
end

%~~~~~~~~~~~~~~~~~~~~~~~~~求每个信标节点的校正值~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
h1=h(1:BeaconAmount,1:BeaconAmount); %信标节点的跳数因为在现实中我们只知道信标节点之间的距离
D1=Dall(1:BeaconAmount,1:BeaconAmount);%距离,信标节点的跳数因为在现实中我们只知道信标节点之间的距离
for i=1:BeaconAmount
dhop(i,1)=sum(D1(i,:))/sum(h1(i,:));%每个信标节点的平均每跳距离
end
%dhop=(sum(D1,2)./sum(h1,2));每行相加求和,去掉for循环效不率比较高
D2=Dall(1:BeaconAmount,(BeaconAmount+1):NodeAmount);%BeaconAmount行UNAmount列
for i=1:BeaconAmount
for j=1:UNAmount
if min(D2(:,j))==D2(i,j)
Dhop(1,j)=dhop(i,1);%未知节点从最近的信标获得校正值
end
end
end
%Dhop = min(D2,[],1);求每一列的最小值,也就是说每个未知点到信标的最短距离
Dhop
%~~~~~~~~~~~~~~~~~~~~~~~~~~~用跳数估计距离~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hop1=h(1:BeaconAmount,(BeaconAmount+1):NodeAmount)%未知节点到信标跳数,BeaconAmount行UNAmount列
for i=1:UNAmount
hop=Dhop(1,i);%hop为从最近信标获得的校正值
Distance(:,i)=hop*hop1(:,i);%%Beacon行UN列;
end
%Distance2 = repmat(Dhop,8,1).*hop1;
% %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~最小二乘法求未知点坐标~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
d=Distance;
for i=1:2
for j=1:(BeaconAmount-1)
a(i,j)=Beacon(i,j)-Beacon(i,BeaconAmount);
end
end
A=-2*(a');
% d=d1';
%polyfit();最小二乘法的matlab实现
%最小二乘法也就是最小平方法
for m=1:UNAmount
for i=1:(BeaconAmount-1)%根据八个信标点计算出最优位置
B(i,1)=d(i,m)^2-d(BeaconAmount,m)^2-Beacon(1,i)^2+Beacon(1,BeaconAmount)^2-Beacon(2,i)^2+Beacon(2,BeaconAmount)^2;
end
X1=inv(A'*A)*A'*B;%pseudo inverse
X(1,m)=X1(1,1);
X(2,m)=X1(2,1);
end
%pinv()求pseudo inverse.
% for i=1:UNAmount
% error(1,i)=(((X(1,i)-UN(1,i))^2+(X(2,i)-UN(2,i))^2)^0.5);
% end
for UNAmount=1:1:91
load topo
BeaconAmoun=9;
node=rand(2,BeaconAmoun)
x=node(1,:)*maxx;
y=node(2,:)*maxy;
E_0n=E_0+E_b*node(1,:);
R_nc=60;
R_cs=110;
E_men=k*E_elec+E_amp*k*R_nc^2;

R=0;
BeaconAmoun=BeaconAmoun+UNAmount;
E_ch=k*E_elec*(BeaconAmoun-1)+k*E_elec+E_amp*k*R_cs^2;
a=zeros(1,BeaconAmoun);

a(floor(rand*1)+1,floor(rand*BeaconAmoun)+1)=1;
for m=1:1:BeaconAmoun
if(a(1,m)==1)
s=m;
end
end
E_cho=E_0n(1,s);
while(E_cho>E_ch)
R=R+1;
R_sj(1,BeaconAmoun)=R
E_0n(1,s)= E_0n(1,s)-E_ch+E_men;
for j=1:1:BeaconAmoun
E_0n(1,j)= E_0n(1,j)-E_men;
end
E_mins=E_0n(1,1);
for l=1:1:BeaconAmoun
if(E_mins E_mins=E_0n(1,l);
end
end
if (E_mins>E_men)
a=zeros(1,BeaconAmoun);
a(floor(rand*1)+1,floor(rand*BeaconAmoun)+1)=1;
for m=1:1:num1
if(a(1,m)==1)
s=m;
E_cho=E_0n(1,s);
end
end
if(E_mins<E_men)
E_cho=0;
end
end
end
end

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问