This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrecpos.m
108 lines (101 loc) · 3.4 KB
/
recpos.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function [phi_old,lambda_old] = recpos(P,prns,time,Eph)
%RECPOS Least-squares searching for receiver position.
% Given 4 or more pseudoranges and ephemerides.
% Zoom on the plot to detect the search pattern!
% Idea to this script originates from Clyde C. Goad
%Kai Borre 04-19-96
%Copyright (c) by Kai Borre
%$Revision 1.0 $ $Date: 1997/09/24 $
vlight = 299792458; % vacuum speed of light in m/s
Omegae_dot = 7.292115147e-5; % rotation rate of the earth in rad/s
dtr = pi/180;
[m,n] = size(P);
sv = prns;
for t = 1:m
icol = find_eph(Eph,sv(t),time);
tx_RAW = time-P(t,1)/vlight;
TOC = Eph(21,icol);
dt = check_t(tx_RAW-TOC);
tcorr(t) = (Eph(2,icol)*dt + Eph(20,icol))*dt + Eph(19,icol)%%;
tx_GPS = tx_RAW-tcorr(t);
XS(:,t) = satpos(tx_GPS, Eph(:,icol));
[phi(t),lambda(t),h(t)] = togeod(6378137,298.257223563,...
XS(1,t),XS(2,t),XS(3,t));
end
close all
% Satellite positions are now known in the ECEF system in form of
% Cartesian (X,Y,Z) and geographical (phi,lambda).
% First guess for receiver's position is (phi_old,lambda_old)
phi
lambda
phi_old = mean(phi) %;
lambda_old = mean(lambda) %;
scale = 900;
acc_p = [];
acc_l = [];
Old_Sum = 10^20;
tic
phi_old = 57;
lambda_old = 10;
for iter = 1:8 % You may find a nicer upper bound for "iter"
scale = scale/10;
sin_phi0 = sin(phi_old*dtr);
cos_phi0 = cos(phi_old*dtr);
ndiv = 8;
for b = 0:ndiv
psi = b*scale/ndiv; % distance
sin_psi = sin(psi*dtr);
cos_psi = cos(psi*dtr);
for alpha = 0:20:340 % azimuth
sin_phi2 = sin_phi0*cos_psi...
+cos_phi0*sin_psi*cos(alpha*dtr);
phi2 = asin(sin_phi2)/dtr;
if cos(phi2) == 0
sin_dlambda = 0;
else
sin_dlambda = sin(alpha*dtr)*sin_psi/cos(phi2*dtr);
end;
dlambda = asin(sin_dlambda)/dtr;
lambda2 = lambda_old + dlambda;
[XR(1,1),XR(2,1),XR(3,1)] = frgeod(6378137,...
298.257223563, phi2, lambda2, 0);
for t = 1:m
cal_one_way(1,t) = norm(XS(:,t)-XR);
sat_clock(t) = tcorr(t)*vlight;
omegatau = Omegae_dot*cal_one_way(1,t)/vlight;
R3 = [ cos(omegatau) sin(omegatau) 0;
-sin(omegatau) cos(omegatau) 0;
0 0 1];
X_ECF(:,t) = R3*XS(:,t);
cal_one_way(1,t) = norm(X_ECF(:,t)- XR);
one_way_res(1,t) = ...
P(t,1)-cal_one_way(1,t)+sat_clock(t);
end;
resid_t = one_way_res(1,:)-one_way_res(1,1);
New_Sum = resid_t*resid_t';
if New_Sum < Old_Sum
Old_Sum = New_Sum;
phi_save = phi2;
lambda_save = lambda2;
acc_p = [acc_p phi2];
acc_l = [acc_l lambda2];
end;
end %alpha
end %b
fprintf('Sum of residuals squared: %6g\n', Old_Sum);
phi_old = phi_save
lambda_old = lambda_save
end %iter
toc
figure
hold on
plot(acc_l,acc_p,'ro', acc_l,acc_p,'c-')
grid
zoom
hold off
fprintf('Final value for latitude %10.6f\n', phi_old);
fprintf('Final value for longitude %9.6f\n', lambda_old);
% "Exact" values are known as
% phi_old = 40.00196769
%lambda_old = 276.9785555
%%%%%%%% end recpos.m %%%%%%%%%%%%%%%%%%%%%