1 内容介绍
节点定位问题是无线传感器网络(WSN)面临的一个难点,科技的发展与进步使得对无线传感器网络定位的要求也与日俱增.没有合理的定位技术,无线传感器网络的应用范围将受到极大的限制,目前改进定位技术突破点体现在改进节点硬件设计以及定位算法两方面. 本论文先讲述了无线传感器网络的发展历程,对无线传感器网络的各方面进行综合分析研究.经历多年的研究探索,无线传感器网络的定位技术主要分为两大类:"非测距"和"测距".通过对这两类定位算法进行全面分析,比较,最后在测距类的定位技术领域中,对TDOA定位系统进行研究.
2 部分代码
%5基站时Chan、Taylor、Fang算法平均定位误差比较
clear;clc;
C = 300000000; % 光速(米每秒)
R = [1000 2000 3000 4000 5000]; % 小区半径(米)
sgma =30;
Rn =1; %(km)
x_delta = 0;
y_delta = 0;
e = 0;
% 随机产生MS的位置(x,y)
u = rand(1);
y = (R/2)*(1-sqrt(u))
v = (sqrt(3)*((R/2)-y))*rand(1);
x = sqrt(3)*y + v
num = 5;
PPP=1000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Chan定位算法
for i = 1:num
% 蜂窝系统各基站坐标
X1 = 0;
Y1 = 0;
X2 = R(i)*(1+sqrt(3)/2);
Y2 = 0;
X3 = R(i)*(sqrt(3)/2);
Y3 = R(i)*(-3/2);
X4 = R(i)*(-sqrt(3)/2);
Y4 = R(i)*(-3/2);
X5 = R(i)*(-1-(sqrt(3)/2));
Y5 = 0;
X6 = R(i)*(-sqrt(3)/2);
Y6 = R(i)*(3/2);
X7 = R(i)*(sqrt(3)/2);
Y7 = R(i)*(3/2);
% 计算MS到各基站的距离
R1 = distance(X1,Y1,x(i),y(i));
R2 = distance(X2,Y2,x(i),y(i));
R3 = distance(X3,Y3,x(i),y(i));
R4 = distance(X4,Y4,x(i),y(i));
R5 = distance(X5,Y5,x(i),y(i));
R6 = distance(X6,Y6,x(i),y(i));
R7 = distance(X7,Y7,x(i),y(i));
% KM = XM^2 + YM^2
K1 = Ka(X1,Y1);
K2 = Ka(X2,Y2);
K3 = Ka(X3,Y3);
K4 = Ka(X4,Y4);
K5 = Ka(X5,Y5);
K6 = Ka(X6,Y6);
K7 = Ka(X7,Y7);
% XM_1 = XM - X1;YM_1 = YM - X1
X2_1 = Xab(X2,X1);
Y2_1 = Xab(Y2,Y1);
X3_1 = Xab(X3,X1);
Y3_1 = Xab(Y3,Y1);
X4_1 = Xab(X4,X1);
Y4_1 = Xab(Y4,Y1);
X5_1 = Xab(X5,X1);
Y5_1 = Xab(Y5,Y1);
X6_1 = Xab(X6,X1);
Y6_1 = Xab(Y6,Y1);
X7_1 = Xab(X7,X1);
Y7_1 = Xab(Y7,Y1);
t_sgma=10^(-7);
% 各TDOA测量值的方差
D_med1= 1.82*(0.4*10^(-6)*(R1/1000)^0.5)^2;
D_med2= 1.82*(0.4*10^(-6)*(R2/1000)^0.5)^2;
D_med3= 1.82*(0.4*10^(-6)*(R3/1000)^0.5)^2;
% D_med4= 1.82*(0.4*10^(-6)*(R4/1000)^0.5)^2;
% D_med5= 1.82*(0.4*10^(-6)*(R5/1000)^0.5)^2;
D_med6= 1.82*(0.4*10^(-6)*(R6/1000)^0.5)^2;
D_med7= 1.82*(0.4*10^(-6)*(R7/1000)^0.5)^2;
T2_1_fangcha = D_med2+D_med1+2*t_sgma^2;
T3_1_fangcha = D_med3+D_med1+2*t_sgma^2;
% T4_1_fangcha = D_med4+D_med1+2*t_sgma^2;
% T5_1_fangcha = D_med5+D_med1+2*t_sgma^2;
T6_1_fangcha = D_med6+D_med1+2*t_sgma^2;
T7_1_fangcha = D_med7+D_med1+2*t_sgma^2;
for k = 1:PPP
t_rms1=0.4*10^(-6)*(R1/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms2=0.4*10^(-6)*(R2/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms3=0.4*10^(-6)*(R3/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
% t_rms4=0.4*10^(-6)*(R4/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
% t_rms5=0.4*10^(-6)*(R5/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms6=0.4*10^(-6)*(R6/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms7=0.4*10^(-6)*(R7/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
% 假设MS到BSi的距离与MS到BS1的距离差为:R2_1=Ri-R1,产生的误差方差为sgma,TDOA(时间差)为:Ti_1=Ri_1/C
R2_1 = Rab(R2,R1) + gngauss(sgma)+C*(t_rms2-t_rms1);
T2_1 = R2_1/C;
R3_1 = Rab(R3,R1) + gngauss(sgma)+C*(t_rms3-t_rms1);
T3_1 = R3_1/C;
% R4_1 = Rab(R4,R1) + gngauss(sgma)+C*(t_rms4-t_rms1);
% T4_1 = R4_1/C;
% R5_1 = Rab(R5,R1) + gngauss(sgma)+C*(t_rms5-t_rms1);
% T5_1 = R5_1/C;
R6_1 = Rab(R6,R1) + gngauss(sgma)+C*(t_rms6-t_rms1);
T6_1 = R6_1/C;
R7_1 = Rab(R7,R1) + gngauss(sgma)+C*(t_rms7-t_rms1);
T7_1 = R7_1/C;
h = 1/2*[HH(R2_1,X2,Y2,X1,Y1);HH(R3_1,X3,Y3,X1,Y1);HH(R6_1,X6,Y6,X1,Y1);HH(R7_1,X7,Y7,X1,Y1)];
Ga = -[X2_1,Y2_1,R2_1;X3_1,Y3_1,R3_1;X6_1,Y6_1,R6_1;X7_1,Y7_1,R7_1];
EQ =
% 计算MS到各基站的距离
R1 = distance(X1,Y1,x(i),y(i));
R2 = distance(X2,Y2,x(i),y(i));
R3 = distance(X3,Y3,x(i),y(i));
R4 = distance(X4,Y4,x(i),y(i));
R5 = distance(X5,Y5,x(i),y(i));
R6 = distance(X6,Y6,x(i),y(i));
R7 = distance(X7,Y7,x(i),y(i));
% KM = XM^2 + YM^2
K1 = Ka(X1,Y1);
K2 = Ka(X2,Y2);
K3 = Ka(X3,Y3);
K4 = Ka(X4,Y4);
K5 = Ka(X5,Y5);
K6 = Ka(X6,Y6);
K7 = Ka(X7,Y7);
% XM_1 = XM - X1;YM_1 = YM - X1
X2_1 = Xab(X2,X1);
Y2_1 = Xab(Y2,Y1);
X3_1 = Xab(X3,X1);
Y3_1 = Xab(Y3,Y1);
X4_1 = Xab(X4,X1);
Y4_1 = Xab(Y4,Y1);
X5_1 = Xab(X5,X1);
Y5_1 = Xab(Y5,Y1);
X6_1 = Xab(X6,X1);
Y6_1 = Xab(Y6,Y1);
X7_1 = Xab(X7,X1);
Y7_1 = Xab(Y7,Y1);
for k = 1:PPP
t_rms1=0.4*10^(-6)*(R1/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms2=0.4*10^(-6)*(R2/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
t_rms3=0.4*10^(-6)*(R3/1000)^0.5*exp(gngauss(0,4)/(10*log10(10)));
R2_1(k) = Rab(R2,R1) + gngauss(sgma)+C*(t_rms2-t_rms1);
R3_1(k) = Rab(R3,R1) + gngauss(sgma)+C*(t_rms3-t_rms1);
% R4_1(k) = Rab(R4,R1) + gngauss(sgma);
% R5_1(k) = Rab(R5,R1) + gngauss(sgma);
% R6_1(k) = Rab(R6,R1) + gngauss(sgma);
% R7_1(k) = Rab(R7,R1) + gngauss(sgma);
g(k)=(R3_1(k)*X2/R2_1(k)-X3)/Y3;
h(k)=(K3-R3_1(k)^2+R3_1(k)*R2_1(k)*(1-(X2/R2_1(k))^2))/(2*Y3);
d(k)=-(1-(X2/R2_1(k))^2+g(k)^2);
e(k)=X2*(1-(X2/R2_1(k))^2)-2*g(k)*h(k);
f(k)=(R2_1(k)^2/4)*(1-(X2/R2_1(k))^2)^2-h(k)^2;
%计算得到移动台的位置
MS_x(k)=(-e(k)-sqrt(e(k)^2-4*d(k)*f(k)))/(2*d(k));
MS_y(k)=g(k)*MS_x(k)+h(k);
err_fang(k) = distance(x(i),y(i),MS_x(k),MS_y(k));
end
loc_err_Fang5(i)=mean(err_fang);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%5个基站
plot(R,loc_err_Chan5,'k+-'); hold on;
plot(R,loc_err_Taylor5,'kd-','MarkerFaceColor','k'); hold on;
plot(R,loc_err_Fang5,'k^-','MarkerFaceColor','k');
xlabel('TDOA误差标准差/s');
ylabel('定位误差均值/m');
axis([0 5550 0 500]);
legend('Chan','Taylor','Fang');
3 运行结果
4 参考文献
[1]罗平. 基于TDOA的无线传感器网络定位系统研究与设计[D]. 昆明理工大学, 2014.