MSOE MEMO To: [Dr. Tritt]
From: Simon, Nikolas A.
Date: February 16, 2016
Re: [Project (trilat2d.m,sort_pr.m,power_to_d_friis.m,distance_confirm.m,power_to_xy.m,circle.m,testscript.m) ]
Program Description:
This program serves at the main calculation tool for a more complex location tracking system. This
location tracking system seeks to determine the location of a node based on received power levels from
a fixed grid of beacons. The location tracking system is implemented such that the beacons are ceiling
mounted and the node can move in XY directions on the floor below. These beacons are strategically
placed in a 3 by 3 grid and are tagged such that it is clear from the program input which power level is
which. Each beacon broadcasts message payloads containing beacon number and a power level in units
of dBm. The node detects the associated RSSI (receives signal strength indicator) values of these
beacons which means each beacon in the grid has an identifying label and an associated received power
level from the perspective of the node.
The power values are stored in a list from 1 to 9 where they are then sorted into the three highest
power levels. Expected RSSI received input power levels are between 0 and -120 dBm. The known level
of transmit power Pt for all beacons is in the grid is approximately +10dbm. The known gains of the
transmit and receive antennas on the beacons and nodes are 9.6899 dB.
A method called trilateration is used to calculate the unknown node coordinate. Trilateration
determines an unknown location from multiple reference locations. The distances relative to these
reference locations are used to estimate the coordinate of the unknown location. At least three
reference locations must exist for trilateration to be implemented. If three reference locations are
considered, the origin of each reference location can be considered the center of a sphere where the
unknown location is the intersection of all three spheres.
For the trilateration calculation to work correctly, at least three beacon received power levels must be
known to determine the unknown location of the node in 2 dimensions. Because the node is
constrained to XY coordinates and can not move freely in the Z direction, a constant is introduced to
account for the difference in distance between the ceiling mounted beacons and the ground node in the
physical implementation of the program.
Equations of Interest:
Wavelength:
� = ��
Equation 1: Wavelength relates the speed of light to a desired frequency
�� = �� + � + �
Equation 2: 3d Pythagorean Theorem considers the Z direction
��� = � �� � �4����
Equation 3: Friis Equation relating received power, transmitted power, transmit/receive antenna gains,
wavelength, and range in an inverse square relationship of the three highest power levels
When solved for distance:
→ � = �4��
��� ���
�� = � ��
Equation 4: Linear path loss ratio which related transmitted power to received power. Path loss can be
determined by taking the ratio of transmitted power to received power. Depending on changes to the
orientation of the test environment, this value will change.
�� = � + 20 log � �4�� + 10� !" �1��
Equation 5: Equation for received power using the signal decay exponent which represents
environmental characterization
� = ��#$%& − ��#$&10 log(% � ��%�
Equation 6: Environmental calibration equation for the signal decay exponent where ��#$%& is a
reference received power level at 1 meter away from the source and ��#$& is the received power level at
a distance d away from the source
Solving for d:
→ 10�)log(%#�& − log(%#�%&* = ��#$%& − ��#$& → log(%#�& = ��#$%& − ��#$& + 10� !"(%#�%&10�
→ � = 10+,-#./&0,-#.&1(%23456/#$/&(%2 7
However exponential calculations like this can be computationally intensive and cause lag time in a
program implementation. To reduce computation time, the distance is calculated with a series
expansion to the needed accuracy.
� = �% 81 + 9(! + 9�! + 9;! + 9<! + 9=! + ⋯ ? , A = BC#(%&),-#./&0,-#.&*(%2
Received power can be determined with the environmental calibration equation which is dependent on
the signal decay exponent and with the Friis equation which is dependent on knowing the gains of the
transmit and receive antennas. Being able to calculate received power in two different ways allows for a
method of error checking because gain is not dependent on the signal decay exponent, it is a physical
characteristic of the antenna:
→ �� = 4��D��
Receiver gain equation where Ae represents effective aperture (area covered by the transmitter).
→ �D = � �$
The effective aperture is a function of power density Pd.
→ �$ + EF�7 = � � 4��
Power density is a function of transmit gain.
When comparing the Friis distance values and the signal decay exponent distance values, they are no
more than 1 meter apart from each other for any given calculation. Any more than this would indicate a
calculation error.
Simple 2d Trilateration Equations:
�(� = #G( − G&� + #H( − H&�
��� = #G� − G&� + #H� − H&�
�;� = #G; − G&� + #H; − H&�
Equation Set 7:�(,�,; represents the distances between the reference beacons and the target unknown
node solved for with the Pythagorean Theorem.
G = �I;� + I(; + I�(2#G(H;� + G�H(; + G;H�(&
H = �J;� + J(; + J�(2#H(G;� + H�G(; + H;G�(&
Where:
� = G(� + H(� − �(�
= G�� + H�� − ���
= G;� + H;� − �;�
Equation Set 8: The system of Pythagorean equations is used to solve for the unknown x and y
coordinates which refer to K#G, H& in figure 1. The notation JLM and ILM means #GL − GM&and#HL − HM&.
Figure 1: Diagram of trilateration using three known reference points to determine an unknown
coordinate at the intersection of all three radii. R(,�,; represent the coordinates of the reference
locations.
When adjusting for the fact that the node and beacons are not in the same plane, a Z component must
be introduced into the trilateration equations so the 3d form of the Pythagorean Theorem must be used
for in the system of Pythagorean equations. The z value is always a constant in the implementation,
there is no z direction so it is assumes that the mobile node cannot move freely in the z direction:
�(� = #G( − G&� + #H( − H&� + #O&�
��� = #G� − G&� + #H� − H&� + #O&�
�;� = #G; − G&� + #H; − H&� + #O&�
There is no dependence in the z direction therefore the equation for Z reduces to Z=Z.
Program Inputs:
Received beacon power levels 1 to 9
Program Outputs:
X Y coordinates of unknown location, linear path loss, d error rate, power density, effective aperture
Intermediate Values:
PA: highest received power level
PB: second highest received power level
PC: third highest received power level
D1: transmit radius of beacon with the highest received power level
D2: transmit radius of beacon with the second highest received power level
D3: transmit radius of beacon with the third highest received power level
X1,Y1 : grid coordinates of the beacon with the highest received power level
X2,Y2 : grid coordinates of the beacon with the second highest received power level
X3,Y3 : grid coordinates of the beacon with the third highest received power level
Constants:
λ: 0.3279m wavelength equal to PQ where c is the speed of light and f is the desired center frequency of
915MHz
Gt: 9.6899dB, transmit antenna gain
Gr: 9.6899dB , receive antenna gain
Pt: ≈+10dbM , transmit power
Prd0: 1 dBm, reference received power level at 1m
H: vertical distance from node to ceiling mounted beacons
Discussion of Algorithm:
The user enters a list of 9 received power values in units of dBm. From 1 to 9 each number corresponds
with a fixed position in the 3x3 grid of beacons. The entered values are then sorted into the highest
three values, making sure to keep track of each power value’s specific location number. The three
highest power levels are then entered into the power distance relationship described by the Friis
equation. The three highest power levels must also determine the three individual XY coordinates
belonging to the three highest received power signals. These three results must then be weighted by
power strength to properly align the unknown node coordinate within the triangle of possible area
between the three highest received beacon power levels.
Figure 2: Illustration of possible position within three selected beacon locations. Based on highest,
middle, and lowest power level a weighting is applied which places the coordinate closer to the beacons
which output the highest power. This weighting affects the distance component of the calculations.
The three highest power levels must be processed and converted to three distinct XY coordinates
representing each beacon location. A point to point mapping of the beacon layout is predefined and
Cartesian coordinates are assigned to each beacon.
Figure 3: Mapping to Cartesian coordinates
In the original brainstorming of the algorithm development matrices were considered for data
processing and grid mapping. Storing values in matrices serves to further complicate the design
unnecessarily and the use of matrix calculations would increase calculation time which may affect
response time when the program is deployed.
Program Functions:
1) Sort Received Powers(sort_pr.m)
Inputs: 9 Pr values in units of dBm
Saves inputs to a structure and sorts out the three highest values and their associated beacon number
Outputs: 3 greatest Pr values in the possible range of between 0 and -120 dBm, and their associated
beacon number
H
L M
2) Coordinate Mapping(power_to_xy.m)
Inputs: beacon number associated with 3 highest Pr values
Maps beacon number to Cartesian in the pattern described in Figure 3.
Outputs: x y coordinates for each of the three beacons
3) Power to distance conversion(power_to_d_friis.m)
Inputs: three highest power levels
Implementation of Equation 3
Outputs: three distances representing the radius of each reference point for trilateration
4) Error Checking(distance_confirm.m)
Inputs: 3 highest received powers, reference received power
The second method for distance calculation to compare with the results from the first distance
calculation (implementation of the series form of Equation 5).
Outputs: 3 distances representing the radius of each reference point for trilateration
5) Trilateration(trilat2d.m)
Inputs: x y coordinates of the three reference beacons, distances of each reference point
Implementation of trilateration equations
Outputs: unknown x y coordinate
6) Calculation Plotting(circle.m)
Inputs: x y coordinates and d for each reference location, the unknown coordinate, plot formatting
Plots reference points and the circle representing their individual distances represented in Figure 1 as
well as the unknown coordinate with the plot text function
Outputs: figure displaying unknown coordinate graphically
7) Test Fixture(testscript.m)
Inputs: User entered received power values
Calls all of the previously described functions and prompts the user for input data in the command
window.
Outputs: Figure displaying calculation results graphically
Figure 4: Concept flow diagram of program operation
Error Detection:
The radii represented by the three distances must also intersect for all three beacon locations. This can
be tested geometrically by comparing distances based on the origin of each beacon where overlap
indicates a successful basis for trilateration.
Figure 5: Illustration of all three radii not intersecting indicating that a valid trilateration calculation
cannot be performed
Due to the fact that received power can be calculated in two different ways (by knowing the gain, and by
knowing the signal decay exponent), program inputs can be checked for validity. The system equipment
uses 915MHz patch antennas with a gain of 9.6899 dB and the expected path loss exponent for line of
sight is approximately 1.7 .
RSSI is influenced by a few different factors. Fading is how the signal weakens with the distance of the
received power by the inverse square law. Shadowing is where there is no direct line of sight path
between the receiver and the transmitter. Diffraction occurs off of sharp edges in a room. Scattering
off of objects in a room.
Figure 6: Example desired input where the filled circles represent the beacons with the three highest
power levels and the unknown location is assumed to be somewhere between the three.
Figure 7: Example undesired input where the three highest power levels are scattered to the outskirts of
the grid which represents a much larger area where the unknown location could be. Furthermore this
input data does not make sense physically because the node will always be closer to three adjacent
beacons surrounding it than a beacon located on the other side of the grid.
Because for any given three highest power values the location of the unknown coordinate must be
somewhere in the area created by the implied triangle, a larger area indicates a larger possible error. If
beacons on both sides of the grid exhibit highest power levels, this indicates that there is an
inconsistency with the input RSSI values to the program because the node is always physically closest to
the nearest three beacons that are around it as illustrated in figure 5 (where the node is assumed to be
somewhere in the area between beacons 1, 2, and 5).
Program Example Calculations:
Figure 8: Sample figure generated by the program where the intersection of the three circles represents
the approximate area of the unknown point and the plotted asterisk marks the exact calculated
unknown coordinate. The plotted unknown coordinate is somewhat offset from the intersection of the
three signals. The plot text function is used to mark the unknown coordinate with an asterisk. This
slight shifting could be caused by the circle plotting or the text plot function so that the intersection is
not perfectly aligned with the point.
Figure 9: Received power inputs used to generate figure 8
Figure 10: Example of an invalid input data set where the trilateration calculation cannot be performed
and no unknown coordinate is plotted.
Figure 11: Input power values for figure 10 where NaN is printed to the command window for the XY
trilateration calculation results.
Source Code:
%Nikolas Simon
%trilat2d.m
function[ x, y, z ] = trilat2d(x1, x2, x3, y1, y2, y3, d1, d2,
d3, h)
%2-D trilateration function
% a constant of z is included to account for beacons and node not
being
% in the same 2d plane %system of three pythagorean equations solved for x and y
A=x1^2+y1^2-d1^2;
B=x2^2+y2^2-d2^2;
C=x3^2+y3^2-d3^2; xnum=A*(y3-y2)+B*(y1-y3)+C*(y2-y1);
xdem=2*(x1*(y3-y2)+x2*(y1-y3)+x3*(y2-y1)); ynum=A*(x3-x2)+B*(x1-x3)+C*(x2-x1);
ydem=2*(y1*(x3-x2)+y2*(x1-x3)+y3*(x2-x1));
x=xnum/xdem;
y=ynum/ydem; z=h;
%Nikolas Simon
%sort_pr.m
%sorting function where the nineinput power levels are accepted
as inputs
%and Pa Pb Pc represent the three highest power levels. Ba Bb Bc
represent
%the three locations in the structure associated with the three
highest
%power levels function [Pa Ba Pb Bb Pc
Bc]=sort_pr(Pr1,Pr2,Pr3,Pr4,Pr5,Pr6,Pr7,Pr8,Pr9)
%structure containing recieved power input values
beacon.p1=Pr1;
beacon.p2=Pr2;
beacon.p3=Pr3;
beacon.p4=Pr4;
beacon.p5=Pr5;
beacon.p6=Pr6;
beacon.p7=Pr7;
beacon.p8=Pr8;
beacon.p9=Pr9; M=[beacon.p1 beacon.p2 beacon.p3 beacon.p4 beacon.p5 beacon.p6
beacon.p7...
beacon.p8 beacon.p9]; sortedValues = sort(M(:)); %sort values
maxValues = sortedValues(end-2:end); %find the 3 largest values Pa=maxValues(3);
Pb=maxValues(2);
Pc=maxValues(1);
%series of switch case statements to determine the power level's
original
%location in the grid
switch Pa
case beacon.p1
Ba=1;
case beacon.p2
Ba=2;
case beacon.p3
Ba=3;
case beacon.p4
Ba=4;
case beacon.p5
Ba=5;
case beacon.p6
Ba=6;
case beacon.p7
Ba=7;
case beacon.p8
Ba=8;
case beacon.p9
Ba=9;
end switch Pb
case beacon.p1
Bb=1;
case beacon.p2
Bb=2;
case beacon.p3
Bb=3;
case beacon.p4
Bb=4;
case beacon.p5
Bb=5;
case beacon.p6
Bb=6;
case beacon.p7
Bb=7;
case beacon.p8
Bb=8;
case beacon.p9
Bb=9;
end switch Pc
case beacon.p1
Bc=1;
case beacon.p2
Bc=2;
case beacon.p3
Bc=3;
case beacon.p4
Bc=4;
case beacon.p5
Bc=5;
case beacon.p6
Bc=6;
case beacon.p7
Bc=7;
case beacon.p8
Bc=8;
case beacon.p9
Bc=9;
end end
%Nikolas Simon
%power_to_d_friis.m
%friis distance equation implemented for each reference of the
three
%reference beacons
%function to calculate the radii to the unknown coordinate from
the
function[d1 d2 d3] =
power_to_d_friis(Pa,Pb,Pc,wavelength,gain,transmit_p) %convert to miliwatts
pr1=(10.^(Pa/10));
pr2=(10.^(Pb/10));
pr3=(10.^(Pc/10)); pt=(10.^(transmit_p/10)); d1=wavelength/(4*pi*sqrt((pr1/pt)/(gain*gain))); d2=wavelength/(4*pi*sqrt((pr2/pt)/(gain*gain))); d3=wavelength/(4*pi*sqrt((pr3/pt)/(gain*gain)));
end
%Nikolas Simon
%distance_confirm.m
%function to calculate distance based on signal decay exponent
dependence
function[Ed1 Ed2 Ed3] =
distance_confirm(Pa,Pb,Pc,ref_recieved_pwr) %1m refrence distance
d0=1; %expected signal decay exponent for line of sight
n=1.7; %taylor series calculation for each reference distance
k1=(log(10)*(ref_recieved_pwr-Pa))/(10*n);
k2=(log(10)*(ref_recieved_pwr-Pb))/(10*n);
k3=(log(10)*(ref_recieved_pwr-Pc))/(10*n); Ed1=d0*(1+((k1)/(1))+((k1^2)/(factorial(2)))+((k1^3)/(factorial(3
)))+...
((k1^4)/(factorial(4)))+((k1^5)/(factorial(5)))); Ed2=d0*(1+((k2)/(1))+((k2^2)/(factorial(2)))+((k2^3)/(factorial(3
)))+...
((k2^4)/(factorial(4)))+((k2^5)/(factorial(5)))); Ed3=d0*(1+((k3)/(1))+((k3^2)/(factorial(2)))+((k3^3)/(factorial(3
)))+...
((k3^4)/(factorial(4)))+((k3^5)/(factorial(5)))); end
%Nikolas Simon
%power_to_xy.m
%point to point mapping functionto establish the reference grid
function [x1 y1 x2 y2 x3 y3]=power_to_xy(Ba,Bb,Bc) %assumed layout mapping to cartesian with 7 as (1,1) in a 3x3
grid
%1_2_3
%4_5_6
%7_8_9 %scaling set to 1
scalePa=1;
scalePb=1;
scalePc=1;
%depending on the location inputs, the switch statements will
determine the
%cartiesian coordinates
switch Ba
case 1
x1=1*scalePa;
y1=3*scalePa;
case 2
x1=2*scalePa;
y1=3*scalePa;
case 3
x1=3*scalePa;
y1=3*scalePa;
case 4
x1=1*scalePa;
y1=2*scalePa;
case 5
x1=2*scalePa;
y1=2*scalePa;
case 6
x1=3*scalePa;
y1=2*scalePa;
case 7
x1=1*scalePa;
y1=1*scalePa;
case 8
x1=2*scalePa;
y1=1*scalePa;
case 9
x1=3*scalePa;
y1=1*scalePa;
end switch Bb
case 1
x2=1*scalePb;
y2=3*scalePb;
case 2
x2=2*scalePb;
y2=3*scalePb;
case 3
x2=3*scalePb;
y2=3*scalePb;
case 4
x2=1*scalePb;
y2=2*scalePb;
case 5
x2=2*scalePb;
y2=2*scalePb;
case 6
x2=3*scalePb;
y2=2*scalePb;
case 7
x2=1*scalePb;
y2=1*scalePb;
case 8
x2=2*scalePb;
y2=1*scalePb;
case 9
x2=3*scalePb;
y2=1*scalePb;
end switch Bc
case 1
x3=1*scalePc;
y3=3*scalePc;
case 2
x3=2*scalePc;
y3=3*scalePc;
case 3
x3=3*scalePc;
y3=3*scalePc;
case 4
x3=1*scalePc;
y3=2*scalePc;
case 5
x3=2*scalePc;
y3=2*scalePc;
case 6
x3=3*scalePc;
y3=2*scalePc;
case 7
x3=1*scalePc;
y3=1*scalePc;
case 8
x3=2*scalePc;
y3=1*scalePc;
case 9
x3=3*scalePc;
y3=1*scalePc;
end
end
%Nikolas Simon
%circle.m
%plotting function to show the trilateration calculation
graphically
%accepts the three reference xy values and thier respective
distances, the
%input variables a,b,c represent which subplot is being plotted,
theLabel
%is an input string for each subplot title, ux and uy are the
calculated
%coordinates of the unknown node indicated graphically by an
asterisk function circle(x1,y1,r1,x2,y2,r2,x3,y3,r3,a,b,c,theLabel,ux,uy) hold on subplot(a,b,c); th = 0:pi/50:2*pi; %circle 1 xunit1 = r1 * cos(th) + x1; yunit1 = r1 * sin(th) + y1; %circle 2 xunit2 = r2 * cos(th) + x2; yunit2 = r2 * sin(th) + y2; %circle 3 xunit3 = r3 * cos(th) + x3; yunit3 = r3 * sin(th) + y3; plot(xunit1, yunit1,xunit2, yunit2,xunit3, yunit3);
grid on
title(num2str(theLabel)); text(ux,uy,'*'); hold off
%Nikolas Simon
%testscript.m
%test fixture for the calculation functions
%display two different figures using the same circle plotting
function, the
%trilateration results using the friis equation for distance and
the signal
%path exponent equation for distance %define constant values
h=5;%set room height to 5m
wavelength=0.3279;%meters
transmit_p=10;%dBm
gain=9.6899;%antenna gain dB
ref_recieved_pwr=1;%dBm %user entered recieved power levels
% sample values used in documentation -11,-14,-13,-20,-4,-1,-9,-
3,-9
p1 = input('Enter Power Value 1: ');
p2 = input('Enter Power Value 2: ');
p3 = input('Enter Power Value 3: ');
p4 = input('Enter Power Value 4: ');
p5 = input('Enter Power Value 5: ');
p6 = input('Enter Power Value 6: ');
p7 = input('Enter Power Value 7: ');
p8 = input('Enter Power Value 8: ');
p9 = input('Enter Power Value 9: '); %call to the sorting function
[Pa Ba Pb Bb Pc Bc]=sort_pr(p1,p2,p3,p4,p5,p6,p7,p8,p9); %call to the mapping function
[x1 y1 x2 y2 x3 y3]=power_to_xy(Ba,Bb,Bc); %friis distance calculation
[d1 d2 d3] =
power_to_d_friis(Pa,Pb,Pc,wavelength,gain,transmit_p);
%signal decay exponent distance calculation
[Ed1 Ed2 Ed3] = distance_confirm(Pa,Pb,Pc,ref_recieved_pwr); %calls to the trilateration function using
[ x_1, y_1, z_1 ] = trilat2d(x1, x2, x3, y1, y2, y3, d1, d2, d3,
h);
[ x_2, y_2, z_2 ] = trilat2d(x1, x2, x3, y1, y2, y3, Ed1, Ed2,
Ed3, h); %plot the xy point on the graph circle(x1,y1,d1,x2,y2,d2,x3,y3,d3,1,2,1,'Trilateration Using
Friis Distance',x_1,y_1); circle(x1,y1,Ed1,x2,y2,Ed2,x3,y3,Ed3,1,2,2,'Trilateration Using
Signal Path Exponent Distance',x_2,y_2); %display relevant distance and xy values to the command window disp('x y z coordinates Friis')
disp(x_1);
disp(y_1);
disp(z_1); disp('x y z coordinates signal decay exponent')
disp(x_2);
disp(y_2);
disp(z_2); disp('Friis d values')
disp(d1);
disp(d2);
disp(d3); disp('path exponent d values')
disp(Ed1);
disp(Ed2);
disp(Ed3);
Works Referenced:
http://cdn.intechweb.org/pdfs/13525.pdf
http://www.es.ewi.tudelft.nl/msc-theses/2013-Kocsi.pdf
https://books.google.com/books?id=mdQlBAAAQBAJ&pg=PA404&lpg=PA404&dq=signal+decay+expone
nt+rssi&source=bl&ots=7aKCjETv38&sig=ex_vF6Ye1jf31wJ6waNMQRO7ZKs&hl=en&sa=X&ved=0ahUKE
wiO5sWgs-HKAhXFdT4KHesYBSkQ6AEILzAC#v=onepage&q&f=false
http://www.ijser.org/researchpaper%5CWi-Fi-Indoor-Positioning-System-Based-on-RSSI-
Measurements.pdf
http://www.antenna-theory.com/basics/aperture.php
http://www.tscm.com/pwr-dens.pdf
http://cial.csie.ncku.edu.tw/publication/pdf/conference_papers/A%20RSSI-
based%20Algorithm%20for%20Indoor%20Localization%20Using%20ZigBee%20in%20Wireless%20Senso
r%20Network.pdf