clc;
clear,close all;
BorderHeight=1000;%区域长度
BorderWidth=[10,8,5,3];%区域宽度
BeanconAmountA=51;%信标节点数量
Dis=BorderHeight/(BeanconAmountA-1); %信标节点间的距离
R=50;%节点的通信距离
BigBeacon=3;%选取的信号强度最大的节点数目
LoopNum=100;%试验重复次数
SBeta=3;
for x=1:4
gl1=0;
gl2=0;
gl3=0;
gl4=0;
for m=1:LoopNum
m
%生成移动节点坐标
Dx=BorderHeight.*rand(1,1);
Dy=BorderWidth(x).*rand(1,1);
UN=[Dx,Dy];
for j=1:BeanconAmountA
Beacon(:,j)=[j;(j-1)*Dis;0];%沿区域一侧生成信标节点坐标
distance(:,j)=sqrt((Dx-((j-1)*Dis))^2+Dy^2);%计算移动节点到信标的距离
end
figure(1);
%画出节点部署图
% plot(Dx,Dy,'k.');
hold on
% plot(Beacon(2,1:BeanconAmountA),Beacon(3,1:BeanconAmountA),'r*');
% xlim([0,BorderHeight]);
% ylim([0,BorderWidth]);
% title('* 红色信标节点 . 黑色移动节点');
%用标准RSSI方法测算距离
Loc=LocByRssi(UN,Beacon,distance,BeanconAmountA,R,BigBeacon,Dis,Dx,Dy,m,SBeta);
%用动态路径衰落指数的RSSI方法测算距离
X=LocByDRssi(UN,Beacon,distance,BeanconAmountA,R,BigBeacon,Dis,Dx,Dy,m,SBeta);
%求点位误差、横向误差、纵向误差
error1(1,m)=sqrt((abs(Dx-X(1)))^2+(abs(Dy-X(2)))^2);
error1(2,m)=abs(X(1)-Dx);
error1(3,m)=abs(X(2)-Dy);
error2(1,m)=sqrt((abs(Dx-Loc(1)))^2+(abs(Dy-Loc(2)))^2);
error2(2,m)=abs(Loc(1)-Dx);
error2(3,m)=abs(Loc(2)-Dy);
%统计两种算法误差落在1m以内的次数
if error1(1,m)<1
gl1=gl1 +1;
end
if error2(1,m)<1
gl2=gl2 +1;
end
%统计两种算法误差落在1.5m以内的次数
if error1(1,m)<1.5
gl3=gl3+1;
end
if error2(1,m)<1.5
gl4=gl4+1;
end
end
%统计动态beta值算法误差落在1m、1.5m以内的概率
gltj1(x,1)=(gl1/m)*100;
gltj1(x,2)=(gl3/m)*100;
%统计标准RSSI算法误差落在1m、1.5m以内的概率
gltj2(x,1)=(gl2/m)*100;
gltj2(x,2)=(gl4/m)*100;
max1(x,1)=max(error1(1,:));
max1(x,2)=max(error1(2,:));
max1(x,3)=max(error1(3,:));
avg1(x,:)=mean(error1,2);
std1(x,1)=std(error1(1,:));
std1(x,2)=std(error1(2,:));
std1(x,3)=std(error1(3,:));
max2(x,1)=max(error2(1,:));
max2(x,2)=max(error2(2,:));
max2(x,3)=max(error2(3,:));
avg2(x,:)=mean(error2,2);
std2(x,1)=std(error2(1,:));
std2(x,2)=std(error2(2,:));
std2(x,3)=std(error2(3,:));
error(x,:) = mean(error1(:,:),1);
end
for i=1:4
wucha1(i)=((avg2(i,1)-avg1(i,1))/avg2(i,1))*100;
wucha2(i)=((std2(i,1)-std1(i,1))/std2(i,1))*100;
end
max1
avg1
std1
max2
avg2
std2
wucha1
wucha2
gltj1
gltj2
Accuracy=error/R
figure;
plot(error(1,:),'-o');
title('移动节点的点位误差')
figure;
plot(error(2,:),':+')
title('移动节点的纵向误差')
figure;
plot(error(3,:),':+')
title('移动节点的横向误差')
figure;
plot(error(4,:),':+')
title('移动节点的横向误差2')
Aucc1=0;
Aucc2=0;
for m=i:LoopNum
Aucc1=Aucc1+error(3,m);
Aucc2=Aucc2+error(4,m);
end
Aucc1=Aucc1/LoopNum
Aucc2=Aucc2/LoopNum
D148