You are on page 1of 30

T.C.

BOAZ UNIVERSITY DEPARTMENT of CIVIL ENGINEERING

CE505 APPLIED STOCHASTIC ANALYSIS&MODELLING

project:

GPS Simulation Using MATLAB

by Utku Yldrm Erkan Kurt

What is GPS?
The Global Positioning System (GPS) is a space based radio positioning/navigation system that will provide three-dimensional position, velocity and time information to suitably equipped users anywhere on or near the surface of the earth. The Global Positioning System (GPS) is a system of 31 satellites which circle the earth twice a day in a very percise orbit and and transmit information to earth. The GPS navigator we used during our project, must continuously see at least four of these satellites to calculate our position. By using a timetable of satellite numbers and their orbits stored in the receivers memory, the receiver can determine the distance and position of any GPS satellite and use this information to compute your position.

How GPS works?


Satellites send radio signals to the receivers which are on earth surface. Using these signals receiver calculates its location on earth. A GPS receiver needs four satellites to provide a three-dimensional (3D) fix and three satellites to provide a two-dimensional (2D) fix. A three-dimensional (3D) fix means the unit knows its latitude, longitude and altitude, while a two-dimensional (2D) fix means the unit knows only its latitude and longitude. The satellites share a common time system known as GPS time and transmit (broadcast) a precise time reference as a spread spectrum signal at two frequencies in L-Band: L1=1575,42 MHz, L2=1227,6 MHz. Two spread spectrum codes are used: a civil coarse acquasition (C/A) code and a military precise (P) code. L1 contains both a P band a C/A code, while L2 contains only the P code. The accuracy of both codes is different. The receiver of the civil code cannot decode the military P code when the security status Selective Availability in GPS satellites is turned on.

With selective availability turned on, military users determine their location within 17,8 m, while civilian users determine their position within an accuracy of 100m; hence selective availability degrades the navigation information to all civil users. S1

What is our problem?


S3 d1 d3 P d2 S2

We are trying to write a code using MATLAB which is the same as used in GPS receivers. The code will take the distances (as inputs) send by satellites which is between the satellite and the point. Also the code will know the position of satellites in space. All the points with di distances from each satellite i, defines a sphere in the space. We also assume that earth is spherical. The intersection of these two spheres (the earth and sphere defined by all the points with di distances from each satellite i) is a circle on earth surface. For each satellite i, it is the same situation. If we can take the exact distances, these circles formed with a satellite and earth- intersect exactly at one point and it is our point P. But there is one problem: we cannot determine the di distances exactly. There is an error term. As a result of these errors, the circles do not intersect at one exact point. Each circle intersects the other circle at two different points. From the below figure, we can see that an area (ambiguity area) is formed as a result of the intersection of the circles. We know that our point P lies in this area but we do not know its exact location.

S1

S3

S2

Ambiguity area Point P lies in this area

So; we will propose a probabilistic methodology to estimate the location of point P and the error, while estimating the location of point P.

Proposed Solution
Definitions z Si

di
P RE o y

ri

x P is the location where we read GPS outputs. RE is the radius of the earth. ri is the distance of the satellite i from the center of coordinate system. o is the center of earth and center of our coordinate system. di is the distance at any time send from the satellite to our point P. When we read output from GPS receiver, dio is the data sent from GPS satellite. di is a random variable and we assume that di has a normal pdf with = dio and = 50m. (normally this can be 10m but to be on the safe side we take this as 50m). -spherical coordinate system:

x = r.cos.cos y = r.cos.sin z = r.sin r

Inputs and outputs of the reciever When the user of GPS receiver wants the output as lateral and longitudinal coordinates on earth, the inputs of the receiver will be 1. Radius of the earth; r = RE (Assumption: Earth is assumed to be spherical). 2. Place of satellite i (for i =1,,N); i, i, ri in spherical coordinates. 3. Distance between satellite i (i =1,,N) and our location; dio. (Taken from satellite i, by the GPS gadget). 4. Probability distribution of di and we assume that di has a normal pdf with = dio and = 50m.

pdf

di

Solution algorithm
1. First of all we must define the intersection area created by n circles, using dios that satellites send to our GPS. So we need the equation of each circle which is the intersection set of a sphere with earth centered and earth radius, and a sphere with satellite centered and with dio radius. This will define all points that are dio far from the satellite i. Definition of a circle when two spheres intersect: We have the formula of two spheres. First sphere is the earth and the formula of the earth is in spherical coordinates. Second sphere is around the satellite i and have a radius dio. The formula is in cartesian coordinates.

EQ.1: r = RE; where RE is the radius of the earth. EQ.2: (x-xi)2 + (y-yi)2 + (z-zi)2 = dio2 Convert EQ.2 into spherical coordinates: x = r.cos.cos y = r.cos.sin z = r.sin xi = ri.cosi.cosi yi = ri.cosi.sini zi = ri.sini

(r.cos.cos -ri.cosi.cosi)2+(r.cos.cos -ri.cosi.cosi)2+(r.cos.cos -ri.cosi.cosi)2 =dio2 r


2

r2cos2cos2 - 2rcoscos ricosicosi + ri2cos2icos2i r2cos2sin2 - 2rcossin ricosisini + ri2cos2isin2i r2sin2 2rsinrisini + ri2sin2i = dio2

r i2

r2 + ri2 2r.ri(coscoscosicosi + cossincosisini + sinsini) = dio2 .(*) fi(r, , , ri, i, i) = dio2 We find the intersection of two spheres, by putting r = RE in (*) equation: RE2 + ri2 2RE.ri(coscoscosicosi + cossincosisini + sinsini) = dio2 dio2 = fi(RE, , , ri, i, i) 2. Using two circle equations, we find the intersection points: dio2 = fi(RE, , , ri, i, i) djo2 = fi(RE, , , rj, j, j)

If there is n satellites; there are n circles. there are n(n-1)/2 intersecting circle pairs. there are n(n-1) intersecting points. We eliminate the points that we do not need by calculating the distance between the points and the center of the circles. If the distance is larger than the diameter of the circle we calculated the distance for; we eliminate the point (the blue dots on the above figure). As a result of these processes, we find the boundary for our point P (the triangular shape bounded by the red dots on the above figure). For each of the three red dots on the above figure, there are different and s (the radius of the earth for all of them are same as expected). We find max, min, max, min from these pairs to create a rectangular area around point P. max min

max

min

3. At the very beginning, we try to transform two variables (di , dj) into new variables ( , ). We do the transformation and find the Jacobian matrix for transormation, but when we write the code and run we saw that the Jacobian matrix is incorrect. Then we strat to think the right solution. Then as seen from the figure below, for every d there is a circle created by satellite i and earth. At the beginning we thought that , are independent from each other and tried to transform one variable (di) to two variables( , ) ,but it is impossible to pass to 2 degrees of freedom from one degree of freedom. Then we see that in every circle created by satellite i ; , are related with each other with an equation. For every there is a on the circle. So we decide that all , pairs in one circle equation will have the same probability of d. So the probability of a point in our ambiguity area will be product of probabilities of distances between that point and satellites.

Our MATLAB source code


%Determine the number of satellites and satellite properties ap=input('Enter the latitude of point \n'); bp=input('Enter the longitude of point \n'); n=input('Enter the number of satellites \n'); for i=1:n fprintf('Enter the height of the satellite %i in meters \n',i) rs(i)=input(''); fprintf('Enter the alpha of the satellite %i in degrees \n',i) as(i)=input(''); as(i)=(as(i)*2*pi)/360; fprintf('Enter the beta of the satellite %i in degrees \n',i) bs(i)=input(''); bs(i)=(bs(i)*2*pi)/360; fprintf('Enter the distance between the satellite %i and the point where we take measurement,send from satellite %i \n',i,i) d(i)=input(''); end %Radius of earth and sigma for normal distribution re=6371000; s=50; %Normally we won't use ap and bp we will find alpha and between for each satellite circle but it is time consuming ap=(ap*2*pi)/360; bp=(bp*2*pi)/360;

%Defining the square ambiguity area,normally found from maximum and minumum alpha and betas %that found from intersection points of circles, but now we use alpha and beta of point %Using s value we choose, we calculated the most possible interval for probability calculation for i=1:3 a=ap-0.00004:0.000001:ap+0.00004; b=bp-0.00004:0.000001:bp+0.00004; sizea=length(a); sizeb=length(b); pab=ones(sizea,sizeb); %Finding the probabilities for alpha,beta pairs for k=1:sizea for l=1:sizeb for i=1:n dab(i)=(re^2+rs(i)^22*re*rs(i)*(cos(b(l))*cos(a(k))*cos(bs(i))*cos(as(i))+cos(b(l))*sin(a(k))*cos(bs(i))*sin(as(i)) +sin(b(k))*sin(bs(i))))^(1/2); pdab(i)=normpdf(dab(i),d(i),s); if i==n for j=1:n pab(k,l)=pdab(j)*pab(k,l); end end end end end %Plot of the probability distribution of alpha's and beta's

figure,meshc(a,b,pab),xlabel('alpha'),ylabel('beta'),zlabel('Probability of points') %To find the centroid of the volume sumofmass=0; sumofmoma=0; sumofmomb=0; for k=1:sizea for l=1:sizeb sumofmass=pab(k,l)+sumofmass; sumofmoma=pab(k,l)*a(k)+sumofmoma; end end for l=1:sizeb for k=1:sizea sumofmomb=pab(k,l)*b(l)+sumofmomb; end end centera=sumofmoma/sumofmass; centerb=sumofmomb/sumofmass; %To find the maximum probable point mostprobablepoint=max(max(pab)); for k=1:sizea for l=1:sizeb if pab(k,l)==mostprobablepoint mostprobablealpha=a(k); mostprobablebeta=b(l); end end end

%Revising our initial values to refine the calculations ap=centera; bp=centerb; for i=1:n d(i)=(re^2+rs(i)^22*re*rs(i)*(cos(bp)*cos(ap)*cos(bs(i))*cos(as(i))+cos(bp)*sin(ap)*cos(bs(i))*sin(as(i))+sin(b p)*sin(bs(i))))^(1/2); end end

%Conversion to degree-minute-second from radian %for estimation of point using the center of mass of probability lat=centera*360/(2*pi); long=centerb*360/(2*pi); if long<0 hemilong=('South'); else hemilong=('North'); end if lat<0 hemilat=('West'); else hemilat=('East'); end degreelong=fix(long); minutelong=fix((long-degreelong)*60);

secondlong=(long-degreelong-minutelong/60)*60; degreelat=fix(lat); minutelat=fix((lat-degreelat)*60); secondlat=(lat-degreelat-minutelat/60)*60; %Output of the system for mass center fprintf('\n Your position estimation using mass center\n') fprintf('%i %i %d %s \n',degreelong,minutelong,secondlong,hemilong) fprintf('%i %i %d %s \n',degreelat,minutelat,secondlat,hemilat) %Conversion to degree-minute-second from radian %for estimation of point using most probable point latp=mostprobablealpha*360/(2*pi); longp=mostprobablebeta*360/(2*pi);

if longp<0 hemilongp=('South'); else hemilongp=('North'); end if latp<0 hemilatp=('West'); else hemilatp=('East'); end degreelongp=fix(longp); minutelongp=fix((longp-degreelongp)*60); secondlongp=(longp-degreelongp-minutelongp/60)*60;

degreelatp=fix(latp); minutelatp=fix((latp-degreelatp)*60); secondlatp=(latp-degreelatp-minutelatp/60)*60; %Output of the system for most probable point fprintf('\n Your position estimation using most probable point \n') fprintf('%i %i %d %s \n',degreelongp,minutelongp,secondlongp,hemilongp) fprintf('%i %i %d %s \n',degreelatp,minutelatp,secondlatp,hemilatp) %Calculating the error sum=0; total=0; for k=1:sizea for l=1:sizeb if pab(k,l)>0.1*mostprobablepoint total=total+1; x1=re*cos(b(l))*cos(a(k)); y1=re*cos(b(l))*sin(a(k)); z1=re*sin(b(l)); x2=re*cos(centerb)*cos(centera); y2=re*cos(centerb)*sin(centera); z2=re*sin(centerb); sum=sum+((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)^(1/2); end end end error=sum/total; fprintf('Error of the estimation \n') fprintf('%d',error)

Inputs to the code


Enter the latitude of point 29.0523611 Enter the longitude of point 41.0835 Enter the number of satellites 5 Enter the height of the satellite 1 in meters 20243200 Enter the alpha of the satellite 1 in degrees 25.6 Enter the beta of the satellite 1 in degrees 9 Enter the distance between the satellite 1 and the point where we take measurement, send from satellite 1 (1) 15237610 Enter the height of the satellite 2 in meters 20197500 Enter the alpha of the satellite 2 in degrees -42.2 Enter the beta of the satellite 2 in degrees 43.3 Enter the distance between the satellite 2 and the point where we take measurement, send from satellite 2 (2) 16945900 Enter the height of the satellite 3 in meters 20161500 Enter the alpha of the satellite 3 in degrees 53.8 Enter the beta of the satellite 3 in degrees 24.9

Enter the distance between the satellite 3 and the point where we take measurement, send from satellite 3 (3) 14713650 Enter the height of the satellite 4 in meters 20101700 Enter the alpha of the satellite 4 in degrees 97.4 Enter the beta of the satellite 4 in degrees 3.3 Enter the distance between the satellite 4 and the point where we take measurement, send from satellite 4 .(4) 19075230 Enter the height of the satellite 5 in meters 20142400 Enter the alpha of the satellite 5 in degrees 1.8 Enter the beta of the satellite 5 in degrees 35.8 Enter the distance between the satellite 5 and the point where we take measurement, send from satellite 5 (5) 14427730 note about (1),(2),(3),(4),(5): These are the figures that we get from the GPS receiver. But they are not the exact values. The exact ones are: 19075178, (5).14427708. (1). 15237604, (2). 16945895, (3). 14713601, (4).

outputs
Your position estimation using mass center 41 5 6.486010e-002 North 29 3 1.152029e-001 East Your position estimation using most probable point 41 5 6.486028e-002 North 29 3 1.152027e-001 East Error of the estimation 6.451908e+001

DGPS (differential GPS)


A DGPS (differential GPS) system employs a local reference station, which has a high quality GPS receiver and an antenna at a known, surveyed location. The reference station estimates the slowly varying components of the GPS satellite range measurement errors, and transmits them as corrections to users within communucation range of the station. With this concept higher position accuracies are achieved for users in the vicinity of a DGPS reference station (the accuracy reduces with increasing radial distance). A surveying application: By using GPS equipment on an aircraft -typically dual- frequency, 24 channel receivers with the antenna as close as possible to camera lens itself and a DGPS base station on the ground, the position of the plane itself can be recorded to an accuracy levevl of about 2 meters (this obviates the need to send in survey crews in advance to set visible ground markers). Using the GPS code, station only calculates the error ratio in distances and send this to GPS receiver. So the sigma of the distribution will be smaller than the previous case.

Our MATLAB source code for DGPS


%Determine the number of satellites, satellite properties and estimated location ast=input('Enter the latitude of station \n'); bst=input('Enter the longitude of station \n'); ap=input('Enter the latitude of point \n'); bp=input('Enter the longitude of point \n'); n=input('Enter the number of satellites \n'); for i=1:n fprintf('Enter the height of the satellite %i in meters \n',i) rs(i)=input(''); fprintf('Enter the alpha of the satellite %i in degrees \n',i) as(i)=input(''); as(i)=(as(i)*2*pi)/360; fprintf('Enter the beta of the satellite %i in degrees \n',i) bs(i)=input(''); bs(i)=(bs(i)*2*pi)/360; fprintf('Enter the distance between the satellite %i and the station, send from satellite %i \n',i,i) ds(i)=input(''); fprintf('Enter the distance between the satellite %i and the point where we take measurement,send from satellite %i \n',i,i) dp(i)=input(''); end %Radius of earth and sigma for normal distribution re=6371000;

s=10; %Refining the values of dp(i) and converting them to d(i) to put them in algortihm %First finding the error ratio and applying them to dp(i) and converting them to d(i) ast=(ast*2*pi)/360; bst=(bst*2*pi)/360; for i=1:n des(i)=(re^2+rs(i)^22*re*rs(i)*(cos(bst)*cos(ast)*cos(bs(i))*cos(as(i))+cos(bst)*sin(ast)*cos(bs(i))*sin(as(i))+sin (bst)*sin(bs(i))))^(1/2); err(i)=ds(i)/des(i); d(i)=dp(i)/err(i); end %Normally we won't use ap and bp we will find alpha and between for each satellite circle pairs but it is time consuming ap=(ap*2*pi)/360; bp=(bp*2*pi)/360; %Defining the square ambiguity area,normally found from maximum and minumum alpha and betas %that found from intersection points of circles, but now we use alpha and beta of point %Using s value we choose, we calculated the most possible interval for probability calculation for i=1:3 a=ap-0.00002:0.000001:ap+0.00002; b=bp-0.00002:0.000001:bp+0.00002; sizea=length(a); sizeb=length(b);

pab=ones(sizea,sizeb); %Finding the probabilities for alpha,beta pairs for k=1:sizea for l=1:sizeb for i=1:n dab(i)=(re^2+rs(i)^22*re*rs(i)*(cos(b(l))*cos(a(k))*cos(bs(i))*cos(as(i))+cos(b(l))*sin(a(k))*cos(bs(i))*sin(as(i)) +sin(b(k))*sin(bs(i))))^(1/2); pdab(i)=normpdf(dab(i),d(i),s); if i==n for j=1:n pab(k,l)=pdab(j)*pab(k,l); end end end end end %Plot of the probability distribution of alpha's and beta's figure,meshc(a,b,pab),xlabel('alpha'),ylabel('beta'),zlabel('Probability of points') %To find the centroid of the volume sumofmass=0; sumofmoma=0; sumofmomb=0; for k=1:sizea for l=1:sizeb sumofmass=pab(k,l)+sumofmass; sumofmoma=pab(k,l)*a(k)+sumofmoma; end end

for l=1:sizeb for k=1:sizea sumofmomb=pab(k,l)*b(l)+sumofmomb; end end centera=sumofmoma/sumofmass; centerb=sumofmomb/sumofmass; %To find the maximum probable point mostprobablepoint=max(max(pab)); for k=1:sizea for l=1:sizeb if pab(k,l)==mostprobablepoint mostprobablealpha=a(k); mostprobablebeta=b(l); end end end %Revising our initial values to refine the calculations ap=centera; bp=centerb; for i=1:n d(i)=(re^2+rs(i)^22*re*rs(i)*(cos(bp)*cos(ap)*cos(bs(i))*cos(as(i))+cos(bp)*sin(ap)*cos(bs(i))*sin(as(i))+sin(b p)*sin(bs(i))))^(1/2); end end

%Conversion to degree-minute-second from radian %for estimation of point using the center of mass of probability lat=centera*360/(2*pi); long=centerb*360/(2*pi); if long<0 hemilong=('South'); else hemilong=('North'); end if lat<0 hemilat=('West'); else hemilat=('East'); end degreelong=fix(long); minutelong=fix((long-degreelong)*60); secondlong=(long-degreelong-minutelong/60)*60; degreelat=fix(lat); minutelat=fix((lat-degreelat)*60); secondlat=(lat-degreelat-minutelat/60)*60; %Output of the system for mass center fprintf('\n Your position estimation using mass center\n') fprintf('%i %i %d %s \n',degreelong,minutelong,secondlong,hemilong) fprintf('%i %i %d %s \n',degreelat,minutelat,secondlat,hemilat)

%Conversion to degree-minute-second from radian %for estimation of point using most probable point latp=mostprobablealpha*360/(2*pi); longp=mostprobablebeta*360/(2*pi);

if longp<0 hemilongp=('South'); else hemilongp=('North'); end if latp<0 hemilatp=('West'); else hemilatp=('East'); end degreelongp=fix(longp); minutelongp=fix((longp-degreelongp)*60); secondlongp=(longp-degreelongp-minutelongp/60)*60; degreelatp=fix(latp); minutelatp=fix((latp-degreelatp)*60); secondlatp=(latp-degreelatp-minutelatp/60)*60; %Output of the system for most probable point fprintf('\n Your position estimation using most probable point \n') fprintf('%i %i %d %s \n',degreelongp,minutelongp,secondlongp,hemilongp) fprintf('%i %i %d %s \n',degreelatp,minutelatp,secondlatp,hemilatp)

%Calculating the error sum=0; total=0; for k=1:sizea for l=1:sizeb if pab(k,l)>0.1*mostprobablepoint total=total+1; x1=re*cos(b(l))*cos(a(k)); y1=re*cos(b(l))*sin(a(k)); z1=re*sin(b(l)); x2=re*cos(centerb)*cos(centera); y2=re*cos(centerb)*sin(centera); z2=re*sin(centerb); sum=sum+((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)^(1/2); end end end error=sum/total; fprintf('Error of the estimation \n') fprintf('%d',error)

inputs to the code


Enter the latitude of station 29.0523889 Enter the longitude of station 41.0835278 Enter the latitude of point 29.0518611 Enter the longitude of point 41.0833056 Enter the number of satellites 5 Enter the height of the satellite 1 in meters 20243200 Enter the alpha of the satellite 1 in degrees 25.6 Enter the beta of the satellite 1 in degrees 9 Enter the distance between the satellite 1 and the station, send from satellite 1 15237610 Enter the distance between the satellite 1 and the point where we take measurement,send from satellite 1 15237480 Enter the height of the satellite 2 in meters 20197500 Enter the alpha of the satellite 2 in degrees -42.2 Enter the beta of the satellite 2 in degrees 43.3 Enter the distance between the satellite 2 and the station, send from satellite 2 16945900 Enter the distance between the satellite 2 and the point where we take measurement,send from satellite 2

16945970 Enter the height of the satellite 3 in meters 20161500 Enter the alpha of the satellite 3 in degrees 53.8 Enter the beta of the satellite 3 in degrees 24.9 Enter the distance between the satellite 3 and the station, send from satellite 3 14713650 Enter the distance between the satellite 3 and the point where we take measurement,send from satellite 3 14713600 Enter the height of the satellite 4 in meters 20101700 Enter the alpha of the satellite 4 in degrees 97.4 Enter the beta of the satellite 4 in degrees 3.3 Enter the distance between the satellite 4 and the station, send from satellite 4 19075230 Enter the distance between the satellite 4 and the point where we take measurement,send from satellite 4 19075220 Enter the height of the satellite 5 in meters 20142400 Enter the alpha of the satellite 5 in degrees 1.8 Enter the beta of the satellite 5 in degrees 35.8 Enter the distance between the satellite 5 and the station, send from satellite 5 14427730 Enter the distance between the satellite 5 and the point where we take measurement,send from satellite 5 14427700

output
Your position estimation using mass center 41 4 9.661268e-001 North 29 3 1.282118e-001 East Your position estimation using most probable point 41 4 9.661268e-001 North 29 3 1.282118e-001 East Error of the estimation 1.265814e+001

Conclusion
In this project, we try to estimate the position and error of handheld GPS receivers using a probabilistic approach. We build a simulation with some assumptions that gives the location and error of handheld GPS receivers. But we saw that the error and the location depends on sigma of the normal probability distribution of the distances between point and the satellites when we use different sigma values. The location estimations are nearly same but the error gets larger and larger with increasing sigma values. And it is very hard to find the ambiguity area, since equations are implicit and needs iteration for solution. We have to discretizing the whole word with small intervals. But it is hard to iterate for a huge data points. Then we tried to find the area with random numbers, but it is not efficient and it is time consuming.

You might also like