Professional Documents
Culture Documents
clc.
for i=1:1: 10
for j=1:1: 10
x (j+(i-1)*10)=(i-1)*10;
y (j+(i-1)*10)=(j-1) * 10;
end
end
figure
plot(x,y,'.')
hold on
%Randomly distributed 50 nodes to be located within the coordinate system, indicated by a red asterisk
xy=[x;y]
hold on
xm=90;
ym=90;
n=50.;
for i=1:1: n
Sx(i)=rand(1,1)*xm;
Sy(i)=rand(1,1)*ym;
xlabel('x axis')
end
dm=30;
m=100.;
for j=1:1: n
SS=[Sx(j);Sy(j)];
k=0.;
DM as the radius, look for each node to be positioned around the anchor node
for i=1:1:m
if d< = dm
%xy is a 2-row m-column matrix, all abscissa is the first row, and the ordinate is the second row; xx (j, i)
%Represents the abscissa of the i-th anchor node of the j-th node to be located
p(j, i)=1/d ;
yy(j,i)=xy(2, i);
k=k+1;
else.
p(j, i)=0;
xx(j, i)=0;
yy(j, i)=0;
end
end
The average coordinates of all anchor nodes within the range of calculation%, that is, the centroid,
expressed as a hollow circle
if k~=0
else.
end
hold on
if k~=0
else.
end
hold on
%Draw each node to be located away from the centroid belongs to a green line
Title ('Centroid')
hold on
%Draw each node to be located away from the weighted centroid belongs to a red line
Title ('xCentroid')
hold on
err(j)=norm((NN-SS), 2)/dm
end
figure
axis([0 n 0 10])
j=1:1: n
The %green line indicates the error between the center of mass and the actual position
hold on
%Red line indicates the error between the weighted centroid and the actual position
hold on
Title ('Centroid')
E=sum (e) / n
ERR=sum (err)/n
clear all;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Values %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PT=-15.28;
GT=2.2;
GR=1;%1.5
L=0;
x=0:0.125:10;
y=0:0.125:10;
lambda=(3*10^8)/(2.4*10^9);
barx=0;
bary=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Access Points %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xap1=0; %2
yap1=0; %4
xap2=3.5; %5
yap2=9; %6
xap3=7; %8
yap3=0; %8
for i=1:1000
PA1(i)=-69.72+sqrt(0.3^2)*randn(1,1);
PA2(i)=-64.68+sqrt(0.5^2)*randn(1,1);
PA3(i)=-65.63+sqrt(0.8^2)*randn(1,1);
end
for p=1:40
for i=1:1:81
for j=1:1:81
a=sqrt((xap1-x(i)).^2+(yap1-y(j)).^2)-0.5;
PR1(i,j)=PT+GT+GR-L+20*log10(lambda/(4*pi))-20*log10(a);
end;
end;
%PA1=-69.72; %4/7
F1=(PR1-PA1(p)).^2;
FU1=1./(1+F1);
for i=1:1:81
for j=1:1:81
a=sqrt((xap2-x(i)).^2+(yap2-y(j)).^2)-1;
PR2(i,j)=PT+GT+GR-L+20*log10(lambda/(4*pi))-20*log10(a);
end;
end;
%PA2=-64.68; %4/7
F2=(PR2-PA2(p)).^2;
FU2=1./(1+F2);
for i=1:1:81
for j=1:1:81
a=sqrt((xap3-x(i)).^2+(yap3-y(j)).^2)-1;
PR3(i,j)=PT+GT+GR-L+20*log10(lambda/(4*pi))-20*log10(a);
end;
end;
%PA3=-65.63; %4/7
F3=(PR3-PA3(p)).^2;
FU3=1./(1+F3);
for i=1:1:81
for j=1:1:81
FU4(i,j)=FU1(i,j)*FU2(i,j)*FU3(i,j);
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Maximum %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
position=[1,1];
m=0;
a=1;
b=1;
for i=1:5
max(1,i)=0;
max(4,i)=0;
end;
for i=1:1:81
for j=1:1:81
for g=1:1:5
if FU4(i,j)>max(1,g)
ma=max(1,g);
max(1,g)=FU4(i,j);
for h=5-g+1:1:5
ma=max(1,h);
max(1,h)=ma;
end;
max(2,g)=i/8;
max(3,g)=j/8;
break;
end;
end;
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Plots %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
max;
barx=barx/5;
bary=bary/5;
erreurcase2=((bary-4)^2+(barx-7)^2)^(0.5);
sauvegardeerreur(p)=erreurcase2;
%subplot(2,2,4), surf(x,y,FU4),xlabel('x'); ylabel('y');zlabel('position
information'),title(erreurcase2);
sauvx(p,1)=barx;
sauvy(p,1)=bary;
variancex=cov(sauvx);
variancey=cov(sauvy);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%% Kalman Filter %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initial State
%%%%%%%%%%%%%%%
if p==1
initialx=0;
initialy=0;
X=[initialx;initialy];
end
sigmax=10^(-5);
sigmay=10^(-5);
B=10;
pb=[B 0;0 B];
% Matrix definition
%%%%%%%%%%%%%%%%%%%
A=[1 0;0 1];
H=[1 0;0 1];
R=[variancex 0;0 variancey];
xb=A*X;
pb=A*pb*A'+[sigmax 0;0 sigmay];
K=pb*H*inv(H*pb*H'+R);
X=xb+K*(H*[barx;bary]-H*xb); % use of the triangulation measure
sauv(p,1)=X(1,1);
sauv(p,2)=X(2,1);
pb=(eye(2)-K*H)*pb;
end
%'Nouvelle serie'
%X
t=1:40;
subplot(2,1,1); plot(t,sauv(:,1)),hold,
plot(t,mean(sauvx(:,1)).*ones(1,40),'r'),title('evolution of the x axis measure')
subplot(2,1,2); plot(t,sauv(:,2)),hold,
plot(t,mean(sauvy(:,1)).*ones(1,40),'r'),title('evolution of the y axis measure')
for n=6:2: 30
y=100*rand(1,100);
w=100*rand(1, n);
z=100*rand(1, n);
grid on;
C=0;
X=zeros(1,100);
Y=zeros(1,100);
for k=1: n
dist = distance (x(i), y(i), w(k), z(k)); distance between %node and anchor node
a=a+w(k);
b=b+z(k);
m=m+1;
end
end
if m>=2
X(i)=a/m;
Y(i)=b/m;
%hold on;
else X (i)=0;
Y(i)=0;
end
end
grid on;
ALE=0;
% if X(i)~=0&Y(i)~=0
ALE=ALE+sqrt((X(i)-x(i))^2+(Y(i)-y(i))^2);
% end
end
ALE=ALE/4;
c1(n/2-2)=(100-C)/100;
ale1(n/2-2)=ALE;
end
figure ;
plot(bili,c1);
grid on;
title ('anchor node ratio and the proportion of nodes can be located in Fig.');
figure,
plot(bili, ale1);
grid on;
% divides the region into a number of adjacent triangles, placing the beacon nodes at
the vertices of the triangle
% can also be said to be the sensor nodes randomly but as evenly distributed as
possible in the area, after being positioned as a beacon node
% unknown nodes transmit positioning signals to the surroundings, and each beacon node
receives its distance from the unknown node by using RSSI ranging algorithm after
receiving.
% selects the three smallest distances from these distances and uses its corresponding
beacon node as the selected beacon node.
% to ensure that the unknown node is inside the triangle formed by the selected beacon
node
% TR distance in the following program refers to the distance between the selected
beacon node and the unknown node
%PL is the path loss of the precise TR distance; Pr is the received power of the
beacon node
PL = PL0+10*n*log10(d/d0); % unit is dB
Pr = Pt - PL; % unit is dB
PrW = 10^(Pr/10); % unit is W
%RSSI is the received signal strength indication, here is the received power
containing Gaussian random variables
%Xn is a zero-mean Gaussian distribution random variable with a standard deviation
of cigema
%PrG is the received power of the Gaussian random variable, which is used to
simulate the measured value of the received power in dB.
Cigema = 11.8; % unit is dB
N = 5e3;
Xn = normrnd(0, cigema, N, 1);
X = mean(Xn); % mean
PrG = Pr+X; % unit is dB
PrGW = 10^(PrG/10); % unit is W
RSSI = PrGW; % unit is W
clear all
v_sensor=0;%%sensor speed
yradarpositon=0; %%
ppred=zeros(4,4);
Pzz=zeros(2,2);
Pxx=zeros(4,2);
xpred=zeros(4,1);
ypred=zeros(2,1);
sumx=0;
sumy=0;
sumxukf=0;
sumyukf=0;
sumxekf=0;
sumyekf=0; %%%of the initial value of the statistics
L=4;
alpha = 1;
kalpha=0;
belta=2;
ramda=3-L;
tao=[t^3/3 t^2/2 0 0;
t^2/2 t 0 0;
0 0 t^3/3 t^2/2;
G=[t^2/2 0
t0
0 t^2/2
0 t ];
a=35*pi/180;
a_v=5/100;
a_sensor=45*pi/180;
x (1)=8000; %%initial position
y(1)=12000;
x(i+1)=x(i)+v*cos(a)*t;
y(i+1)=y(i)+v*sin(a)*t;
end
xradarpositon=0;
yradarpositon=0;
measureerror=[azimutherror^2 0; 0 rangeerror^2];
processerror=tao*processnoise;
A=[1 t 0 0;
0 1 0 0;
0 0 1 t;
0 0 0 1];
Anoise=size(A,1);
for j=1:2*L+1
Wm (j)=1/(2*(L+ramda));
Wc (j)=1/(2*(L+ramda));
end
Wm(1)=ramda/(L+ramda);
Wc (1)=ramda/(L+ramda);%+1-alpha^2+belta; % % weight
if i= = 1
end
cho=(chol(P*(L + ramda)))';%
for j=1:L
end
F=A;
Xsigmapre=F*Xsigma;
xpred=zeros(Anoise,1);
for j=1:2*L+1
end
Noise1=Anoise;
ppred=zeros(Noise1, Noise1);
for j=1:2*L+1
end
ppred=ppred+processerror;
chor=(chol((L+ramda)*ppred))';
for j=1:L
end
end
ypred=zeros(2,1);
for j=1:2*L+1
end
Pzz=zeros(2,2);
for j=1:2*L+1
end
Pzz=Pzz+measureerror;
Pxy=zeros(Anoise, 2);
for j=1:2*L+1
end
K=Pxy*inv(Pzz);
P=ppred-K*Pzz*K';
xukf(i)=xestimate(1,1);
yukf(i)=xestimate(3,1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if i= = 1
ekf_xestimate=[Zmeasure(2, i)*cos (Zmeasure(1, i)) 0 Zmeasure (2, i)*sin (Zmeasure(1, i)) 0 ]';
ekf_xpred=ekf_xestimate;
end;
F=A;
ekf_xpred=F*ekf_xestimate;
ekf_ppred=F*ekf_p*F'+processerror;
ekf_z(1,1)=atan(ekf_xpred(3)/ekf_xpred(1)) ;
ekf_z(2,1)=sqrt ((ekf_xpred(1))^2+(ekf_xpred(3))^2);
PHHP=H*ekf_ppred*H'+measureerror;
ekf_K=ekf_ppred*H' * inv(PHHP);
ekf_p=(eye (L)-ekf_K*H)*ekf_ppred;
ekf_xestimate=ekf_xpred+ekf_K*(Zmeasure (:, i)-ekf_z);
traceekf(i)=trace(ekf_p);
xekf(i)=ekf_xestimate(1,1);
yekf(i)=ekf_xestimate(3,1);
ukferrorx (i)=xestimate(1)+xradarpositon-x(i);
ukferrory(i)=xestimate (3)+yradarpositon-y(i);
ekferrorx(i)=ekf_xestimate(1)+xradarpositon-x(i);
ekferrory(i)=ekf_xestimate(3)+yradarpositon-y(i);
aa (i)=xx (i)+xradarpositon-x(i);;
bb (i)=yy (i)+yradarpositon-y(i);
sumx=sumx+(errorx (i)^2);
sumy=sumy+(errory (i)^2);
sumxukf=sumxukf+(ukferrorx(i)^2);
sumyukf=sumyukf+(ukferrory(i)^2);
sumxekf=sumxekf+(ekferrorx(i)^2);
sumyekf=sumyekf+(ekferrory(i)^2);
mseerrory(i)=sqrt(sumy/(i-1));
mseerrorxukf(i)=sqrt(sumxukf/(i-1)); statistical mean square error of%UKF
mseerroryukf(i)=sqrt(sumyukf/(i-1));
mseerroryekf(i)=sqrt(sumyekf/(i-1));
end
figure(1);
plot(mseerrorxukf, 'r');
hold on;
plot(mseerrorxekf, 'g');
hold on;
plot (mseerrorx,'.');
hold on;
figure(2)
plot(mseerroryukf, 'r');
hold on;
plot(mseerroryekf, 'g');
hold on;
plot (mseerrory,'.');
hold on;
figure(3)
plot(x, y);
hold on;
hold on;
hold on;
plot(xx,yy, 'm');