## How to find the distance between two nodes in WSN using matlab?

Asked by zain omar

### zain omar (view profile)

on 12 Jun 2015
Latest activity Answered by MUHAMAMD SHAHKHIR

### MUHAMAMD SHAHKHIR (view profile)

on 17 Mar 2019
hi,
I have created a wireless sensor network simulation consisting of 3 anchor nodes and mobile node with fixed positions. I want to find the real distance and the estimated distance between every anchor with the mobile node. my code is as follow:
n = 4; %anchor nodes
t = 1; %target node
NetSize = 100;%size of the network
%Nodes location in the network
nLocation = [0,NetSize;
0,0;
NetSize,0;
NetSize,NetSize]; %the nodes are distributed at the edge of the network size
%location of the target node which will be random in 2 columns
tLocation = [40,70];
%calculation the distance
for z = 1 : n
distance(z) = sqrt( (nLocation(z,1)-tLocation(t,1)).^2 +(nLocation(z,2)-tLocation(t,2)).^2 );
end
am not sure if this is correct. anyone can help me?? and how to get the estimated distance.

### Stalin Samuel (view profile)

Answer by Stalin Samuel

### Stalin Samuel (view profile)

on 13 Jun 2015

X = [x1,y1;x2,y2];
d = pdist(X,'euclidean')

### Walter Roberson (view profile)

Answer by Walter Roberson

### Walter Roberson (view profile)

on 13 Jun 2015

You could "estimate" a distance using an L1-norm, abs(x difference)+abs(y difference). But it is not clear to me that "estimate" has that meaning in your context.
In the context of nodes for which the absolute coordinates are not known (such as via GPS), it can be necessary to estimate the positions of the nodes in relative terms, by examining available information such as signal strength and which other nodes are visible. In the case of perfect signal information, no reflections and no blockages (but possibly a cutoff on how weak of a signal could be received), locations could be triangulated. The information would only be accurate to within rotations of the coordinate system and to reversal of symmetries. If relative position information is known for some of the nodes, symmetries can be removed from possibilities. If positions of at least two nodes are known relative to a fixed coordinate system then rotations of the systems can be removed. If rotations and symmetries can be removed and absolute coordinates are known for at least one node (such as via GPS) then in theory absolute positions of the other nodes could be calculated.
In practice though, blockages and multipath are a significant concern. There are techniques for estimating position taking those into account, but they are non-trivial. The possibilities open in any particular situation are going to depend on the available sensors, including possibly inertial sensors.

### MUHAMAMD SHAHKHIR (view profile)

Answer by MUHAMAMD SHAHKHIR

### MUHAMAMD SHAHKHIR (view profile)

on 17 Mar 2019

Use euclidean distance plus noisy range measurement , white noise or gaussian noise