RSSI指纹定位技术性能仿真
要求一:RSSI的测量值由对数路径损耗模型产生,为减小波动造成的误差,其值可由多次测量取平均值来得到。
要求二:定位指纹数据库的建立是基于网格形式产生不同的指纹节点。
要求三: 比较KNN算法与WKNN算法的CDF曲线对比图,横坐标为定位误差,纵坐标为CDF。
函数databaseone主要代码:
%databaseone部分:
function [X]=databaseone(A,sigma)
% A is the coordinate of BSS
% sigma is the standard deviation of RSSI measurement
pd0=0;
n=3;
[m,~]=size(A);
tt=5;
coor=[];
RSSIone=[];
for i=20:20:480
for j=20:20:480
coor1=[i,j];
coor=[coor;coor1];
d1=A-ones(m,1)*coor1;
d2=sum(d1.^2,2);
d=d2.^(1/2);
for k=1:tt
rssi(:,k)=pd0-10*n*log10(d)-10^(sigma/10)*randn(m,1);
end
RSS_m=mean(rssi,2)';
RSSIone=[RSSIone;RSS_m];
end
end
全部代码:
%RSSIone部分:
clear all;
clc;
BS1=[0,0];
BS2=[500,0];
BS3=[500,500];
BS4=[0,500];
std_var=4;
A=[BS1;BS2;BS3;BS4];
pd0=0;
n=3;
tt=5;
% the number of RSSI measurement for each BS
number=1000;
for i=1:number
MS=[400*rand,400*rand];
r1=A-ones(4,1)*MS;
r2=(sum(r1.^2,2)).^(1/2);
for k=1:tt
rssi(:,k)=pd0-10*n*log10(r2)-10^(std_var/10)*randn(4,1);
end
RSSIoone=mean(rssi,2);
%database
X=databaseone(A,std_var);
%matching
[m,~]=size(X);
for j=1:m
distance(j)=norm(X(j,3:end)-RSSIoone');
end
[C,I]=sort(distance);
%KNN algorithm
K=3;
match_result=X(I(1:K),1:2);
est1=mean(match_result);
RMSE1(i)=norm(est1-MS);
%WKNN algorithm
weight=1./C(1:K);
weight=weight'/sum(weight);
est2=sum([weight.*match_result(:,1),weight.*match_result(:,2)]);
RMSE2(i)=norm(est2-MS);
est3=X(I(1),1:2);
RMSE3(i)=norm(est3-MS);
end
RMSE=0:20;
for i=1:length(RMSE)
n1=0;
n2=0;
n3=0;
for j=1:number-5
if RMSE1(j)<=RMSE(i)
n1=n1+1;
end
if RMSE2(j)<=RMSE(i)
n2=n2+1;
end
if RMSE3(j)<=RMSE(i)
n3=n3+1;
end
end
p1(i)=n1/number;
p2(i)=n2/number;
p3(i)=n3/number;
end
% plot
plot(RMSE,p1,'-O',RMSE,p2,'-s',RMSE,p3,'-x')
xlabel('The localization error (m)');
ylabel('CDF');
legend('KNN','WKNN','NN');
%databaseone部分:
function [X]=databaseone(A,sigma)
% A is the coordinate of BSS
% sigma is the standard deviation of RSSI measurement
pd0=0;
n=3;
[m,~]=size(A);
tt=5;
coor=[];
RSSIone=[];
for i=20:20:480
for j=20:20:480
coor1=[i,j];
coor=[coor;coor1];
d1=A-ones(m,1)*coor1;
d2=sum(d1.^2,2);
d=d2.^(1/2);
for k=1:tt
rssi(:,k)=pd0-10*n*log10(d)-10^(sigma/10)*randn(m,1);
end
RSS_m=mean(rssi,2)';
RSSIone=[RSSIone;RSS_m];
end
end
X=[coor,RSSIone];
end