Code covered by the BSD License

# Mobile user Localization in WSN

by

### Bachan P (view profile)

Dynamic Triangular location method determines the position of mobile user inside a building.

DTN.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       DYNAMIC TRIANGULATION ALGORITHM       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic
clear all
clc
r=input('enter the cell radius in meters=');
N=input('enter the no of cells=');
%number of sensor nods
S=3;
%finding the coordinates for S sensor nodes
x(1)=1;
y(1)=1;
p(1,:)=[x(1),y(1)];
for i=2:N
x(i)=(i-1)*1.5*r;
h(i)=(i-1)*sqrt(3)*r;
y(i)=h(i)^2-x(i)^2;
p(i,:)=[x(i),y(i)];
end
for i=1:S
k=randint(1,1,[1 N]);
P(i,:)=p(k,:);
end
disp(P)

%finding the received signal strength captured by all sensor nodes
theta=2*pi*rand;
X=r*cos(theta);
Y=r*sin(theta);
M=[X,Y];
sum=0;
for i=1:S
for j=1:2
a=sum+(M(1,j)-P(i,j))^2;
end
d(i)=sqrt(a);
end
d0=10;
n=4;
for i=1:S
end

%finding stongest rssi and generating mapping circle
for i=1:S
end
for i=1:S
for j=1:2
t(i,j)=(d(i))^2+M(1,j);
end
end
[v p]=min(d);
xth =x(p)+d(p)*cos(theta);
yth=y(p)+d(p)*sin(theta);

%generate the cost function
cost

%finding minimum cost function and angle
for k=1:359
if(p==1)
cf(k)=sqrt(abs(e3(k)-e2(k)));
elseif(p==2)
cf(k)=sqrt(abs(e3(k)-e1(k)));
else
cf(k)=sqrt(abs(e2(k)-e1(k)));
end
subplot(3,1,3);
plot(k,cf(k),'r.');
hold on
grid on
xlabel('angle in degrees')
ylabel('cost function')
title('cost function with respect to change in angle')
end
[CF ang]=min(cf);
plot(ang,CF,'go');
legend('cost function','minimum cost function')
theta=ang;
D(1,:)=[x(p)+d(p)*cos(theta),y(p)+d(p)*sin(theta)];
figure,
plot(t(1:3,1),t(1:3,2),'rs','MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',4)
grid on
hold on
xlabel('x co-ordinate of sensor nodes')
ylabel('y co-ordinates of sensor nodes')
legend
plot(D(1,1),D(1,2),'bs','MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',4)

%results
fprintf('RSSIs collected from 3 sensor nodes=')