-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathAOAwithTDOA.py
2028 lines (1915 loc) · 86.4 KB
/
AOAwithTDOA.py
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Pypredict
Orbit prediction software. Displays the satellites' position and
orbital parameters in real time. Simulates satellite localization
and deployment.
Copyright (C) 2018-2021, Matías Vidal Valladares, matvidal.
Authors: Matías Vidal Valladares <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
This python class contains methods to estimate the position of an
unknown source, such as a femto-satellite, given two known
positions, such as two CubeSats. We use the TDOA and AOA of a
simulated signal sent by the unknown source. This class replicates
the figures of the research paper called A simple and accurate
TDOA-AOA localization method using two stations. After this, we
study the performance of this method in space, where the base
stations are CubeSats which are not fixed in one position and their
location is affected by the accuracy of their GNSS devices. We also
simulate the deployment of a femto-satellite from one of these
CubeSats and evaluate the location estimation for different
directions of deployment, affected by the accuracy of the attitude
and control systems, and different deployment points in the
mother-CubeSat's orbit. All the research done in this class is for
a research paper submitted at Remote Sensing with the name:
A femto-satellite localization method based on TDOA and AOA using
two CubeSats.
"""
from numpy import arange, arctan2, arccos, array, cos, linalg, matrix, mean, pi, random, savetxt, sin, std, sqrt, zeros, transpose
from pypredict.dpl import Dpl
from pypredict.sat import Sat
from matplotlib.pyplot import axis, plot, setp, show, subplots, subplots_adjust, tight_layout, xticks
from datetime import datetime, timedelta
from pkg_resources import resource_filename
import csv
class Locate(object):
def __init__(self):
print("Initializing AOA with TDOA")
def __call__(self):
return self
def get_distance(self, u, s):
"""
Calculates the Euclidean distance between the vectors u and s.
Parameters
----------
u : numpy.matrix
Vector of the unknown source position (femto-satellite) in
meters.
s : numpy.matrix
Vector of known position (CubeSat) in meters.
Returns
-------
d
Distance between position vectors u and s.
"""
d = sqrt((u[0,0] - s[0,0])**2 + (u[1,0] - s[1,0])**2 + (u[2,0] - s[2,0])**2)
return d
def get_real_vector(self, u, s1, s2):
"""
Returns the TDOA and the two angles of arrival without
measurement noise, given the position vectors u, s1 and s2.
Parameters
----------
u : numpy.matrix
Vector of the unknown source position (femto-satellite) in
meters.
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
Returns
-------
d21
Difference between d2 (distance CubeSat2-Femto-satellite)
and d1 (distance Cubesat1-Femto-satellite) in meters.
theta1
Azimuth of the femto-satellite seen by known position 1
(CubeSat 1) in degrees.
phi1
Elevation of the femto-satellite seen by known position 1
(CubeSat 1) in degrees.
theta2
Azimuth of the femto-satellite seen by known position 2
(CubeSat 2) in degrees.
phi2
Elevation of the femto-satellite seen by known position 2
(CubeSat 2) in degrees.
"""
d1 = linalg.norm(u - s1)
d2 = linalg.norm(u - s2)
d21 = d2 - d1
theta1 = arctan2(u[1,0] - s1[1,0], u[0,0] - s1[0,0])
phi1 = arctan2(u[2,0] - s1[2,0], sqrt((u[0,0] - s1[0,0])**2 + (u[1,0] - s1[1,0])**2))
theta2 = arctan2(u[1,0] - s2[1,0], u[0,0] - s2[0,0])
phi2 = arctan2(u[2,0] - s2[2,0], sqrt((u[0,0] - s2[0,0])**2 + (u[1,0] - s2[1,0])**2))
return d21, theta1, phi1, theta2, phi2
def get_b(self, theta, phi):
"""
Returns the unit vector of the location of the femto-satellite,
at the angles theta and phi with respect to a given CubeSat.
Parameters
----------
theta : numpy.float64
Azimuth of the femto-satellite seen by a given known
position (CubeSat).
phi : numpy.float64
Elevation of the femto-satellite seen by a given known
position (CubeSat).
Returns
-------
b
Unit vector of the unknown source (femto-satellite)
position.
"""
cos_phi = cos(phi)
return matrix([[cos_phi*cos(theta)], [cos_phi*sin(theta)], [sin(phi)]])
def get_Gm(self, theta, phi):
"""
Parameters
----------
theta : numpy.float64
Azimuth of the femto-satellite seen by a given known
position (CubeSat).
phi : numpy.float64
Elevation of the femto-satellite seen by a given known
position (CubeSat).
Returns
-------
Gm
Matrix used to calculate G.
"""
cos_theta = cos(theta)
sin_phi = sin(phi)
sin_theta = sin(theta)
Gm = matrix([[sin_theta, sin_phi*cos_theta],
[-cos_theta, sin_phi*sin_theta],
[0, -cos(phi)]])
return Gm
def get_G(self, b1, b2, G1, G2):
"""
b1 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s1 (CubeSat 2).
b2 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s2 (CubeSat 2).
G1 : numpy.matrix
Matrix used to calculate G or h.
G2 : numpy.matrix
Matrix used to calculate G or h.
Returns
-------
G
Matrix that depends on the angle measurements.
"""
two_b2_minus_b1 = 2*(b2 - b1)
G = matrix([[two_b2_minus_b1[0,0], G1[0,0], G1[0,1], G2[0,0], G2[0,1]],
[two_b2_minus_b1[1,0], G1[1,0], G1[1,1], G2[1,0], G2[1,1]],
[two_b2_minus_b1[2,0], G1[2,0], G1[2,1], G2[2,0], G2[2,1]]])
return G
def get_h(self, d21, s1, s2, b1, b2, G1, G2):
"""
Parameters
----------
d21 : numpy.float64
Difference between d2 (distance CubeSat2-Femto-satellite)
and d1 (distance Cubesat1-Femto-satellite) in meters.
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
b1 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s1 (CubeSat 2).
b2 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s2 (CubeSat 2).
G1 : numpy.matrix
Matrix used to calculate G or h.
G2 : numpy.matrix
Matrix used to calculate G or h.
"""
s1TG1 = s1.transpose()*G1
s2TG2 = s2.transpose()*G2
h = matrix([[((b2 - b1).transpose()*(s1 + s2 - d21*b1))[0,0]],
[s1TG1[0,0]], [s1TG1[0,1]], [s2TG2[0,0]], [s2TG2[0,1]]])
return h
def get_Lm(self, theta, phi):
"""
Parameters
----------
theta : numpy.float64
Azimuth of the femto-satellite seen by a given known
position (CubeSat).
phi : numpy.float64
Elevation of the femto-satellite seen by a given known
position (CubeSat).
Returns
-------
Lm
Matrix used to calculate the matrix T.
"""
cos_phi = cos(phi)
cos_theta = cos(theta)
sin_phi = sin(phi)
sin_theta = sin(theta)
Lm = matrix([[-cos_phi*sin_theta, -sin_phi*cos_theta],
[cos_phi*cos_theta, -sin_phi*sin_theta],
[0, cos_phi]])
return Lm
def get_Tm(self, d, phi):
"""
Parameters
----------
d : numpy.float64
Distance between the unknown source (femto-satellite)
and one of the known positions (CubeSats).
phi : numpy.float64
Elevation of the femto-satellite seen by a given known
position (CubeSat).
Returns
-------
Tm
Matrix used to calculate the matrix T.
"""
Tm = -d*matrix([[cos(phi), 0],
[0, 1]])
return Tm
def get_T(self, d1, d2, b1, b2, L1, L2, T1, T2):
"""
Parameters
----------
d1 : numpy.float64
Distance between the unknown source (femto-satellite)
and the known position 1 (CubeSat 1).
d2 : numpy.float64
Distance between the unknown source (femto-satellite)
and the known position 2 (CubeSat 2).
b1 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s1 (CubeSat 2).
b2 : numpy.matrix
Unit vector of the unknown source (femto-satellite)
position with respect to position s2 (CubeSat 2).
L1 : numpy.matrix
Matrix in terms of the azimuth and elevation from the
known position 1 (CubeSat 1) used to calculate T.
L2 : numpy.matrix
Matrix in terms of the azimuth and elevation from the
known position 2 (CubeSat 2) used to calculate T.
L1 : numpy.matrix
Matrix in terms of the distance and elevation from
the known position 1 (CubeSat 1) used to calculate T.
L2 : numpy.matrix
Matrix in terms of the distance and elevation from
the known position 2 (CubeSat 2) used to calculate T.
Returns
-------
T
Matrix used to calculate the covariance matrix W.
"""
r1b2TL1 = d1*b2.transpose()*L1
r2b1TL2 = d2*b1.transpose()*L2
b2_m_b1_t = ((b2 - b1).transpose()*b1)[0,0]
T = matrix([[-b2_m_b1_t, r1b2TL1[0,0], r1b2TL1[0,1], -r2b1TL2[0,0], -r2b1TL2[0,1]],
[0.0, T1[0,0], T1[0,1], 0.0, 0.0],
[0.0, T1[1,0], T1[1,1], 0.0, 0.0],
[0.0, 0.0, 0.0, T2[0,0], T2[0,1]],
[0.0, 0.0, 0.0, T2[1,0], T2[1,1]]])
return T
def get_Q(self, std_RD, std_AOA):
"""
Generates the measurement noise covariance matrix.
Parameters
----------
std_RD : float
Standard deviation of the range difference in meters.
std_AOA : float
Standard deviation of the AOA in radians.
Returns
-------
Q
Measurement noise covariance matrix.
"""
Q = matrix([[std_RD**2, 0.0, 0.0, 0.0, 0.0],
[0.0, std_AOA**2, 0.0, 0.0, 0.0],
[0.0, 0.0, std_AOA**2, 0.0, 0.0],
[0.0, 0.0, 0.0, std_AOA**2, 0.0],
[0.0, 0.0, 0.0, 0.0, std_AOA**2]])
return Q
def get_W(self, Q, T):
"""
Returns the covariance matrix.
Parameters
----------
Q : numpy.matrix
Measurement noise covariance matrix.
T : numpy.matrix
Matrix used to calculate the covariance matrix W.
If this matrix is invertible, the method gives a unique
solution.
Returns
-------
W
The covariance matrix.
"""
W = T*Q*T.transpose()
return W
def get_error_vector(self, std_RD, std_AOA, L):
"""
Generates the measurement error for the TDOA and AOA.
Parameters
----------
std_RD : float
Standard deviation of the range difference in meters.
std_AOA : float
Standard deviation of the AOA in radians.
L : int
Number of ensemble runs.
Returns
-------
e
Error vector of the TDOA in range and two AOA pairs.
"""
e = random.randn(5, L)
e[0,:] = std_RD*(e[0,:] - mean(e[0,:]))
e[1,:] = std_AOA*(e[1,:] - mean(e[1,:]))
e[2,:] = std_AOA*(e[2,:] - mean(e[2,:]))
e[3,:] = std_AOA*(e[3,:] - mean(e[3,:]))
e[4,:] = std_AOA*(e[4,:] - mean(e[4,:]))
return e
def get_MSE(self, u, s1, s2, k, Q):
"""
Returns the mean-square error.
Parameters
----------
u : numpy.matrix
Vector of the unknown source position (femto-satellite) in
meters.
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
k : tuple
Real measurement vector (without errors). It contains the
TDOA in range and two AOA pairs.
Q : numpy.matrix
Measurement noise covariance matrix.
Returns
-------
MSE
The Mean-Square Error.
"""
b1 = self.get_b(k[1], k[2])
b2 = self.get_b(k[3], k[4])
G1 = self.get_Gm(k[1], k[2])
G2 = self.get_Gm(k[3], k[4])
G = self.get_G(b1, b2, G1, G2)
d1 = linalg.norm(u - s1)
d2 = linalg.norm(u - s2)
L1 = self.get_Lm(k[1], k[2])
L2 = self.get_Lm(k[3], k[4])
T1 = self.get_Tm(d1, k[2])
T2 = self.get_Tm(d2, k[4])
T = self.get_T(d1, d2, b1, b2, L1, L2, T1, T2)
T_inv = T.I
G_transpose = G.transpose()
MSE = ((T_inv*G_transpose).transpose()*Q.I*T_inv*G_transpose).I
return MSE
def get_lm(self, u, sm):
lm = sqrt((u[0,0] - sm[0,0])**2 + (u[1,0] - sm[1,0])**2)
return lm
def get_Dm(self, u, sm, lm, dm):
one_div_lm2 = 1/lm**2
aux = (u[2,0] - sm[2,0])/(dm**2*lm)
Dm = matrix([[-(u[1,0] - sm[1,0])*one_div_lm2, (u[0,0] - sm[0,0])*one_div_lm2, 0],
[-(u[0,0] - sm[0,0])*aux, -(u[1,0] - sm[1,0])*aux, lm/dm**2]])
return Dm
def get_FIM(self, u, s1, s2, Q):
"""
Return the Fisher information matrix.
Parameters
----------
u : numpy.matrix
Vector of the unknown source position (femto-satellite) in
meters.
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
Q : numpy.matrix
Measurement noise covariance matrix.
Returns
-------
FIM
The Fisher Information Matrix.
"""
d1 = linalg.norm(u - s1)
d2 = linalg.norm(u - s2)
c = (u - s2)/d2 - (u - s1)/d1
l1 = self.get_lm(u, s1)
l2 = self.get_lm(u, s2)
D1 = self.get_Dm(u, s1, l1, d1)
D2 = self.get_Dm(u, s2, l2, d2)
dk_duT = matrix([[c[0,0], c[1,0], c[2,0]],
[D1[0,0], D1[0,1], D1[0,2]],
[D1[1,0], D1[1,1], D1[1,2]],
[D2[0,0], D2[0,1], D2[0,2]],
[D2[1,0], D2[1,1], D2[1,2]]])
FIM = dk_duT.transpose()*Q.I*dk_duT
return FIM
def estimate(self, s1, s2, k, e, Q):
"""
Estimates the unknown source position (femto-satellite)
using the known positions (CubeSats 1 and 2) with their
measurements k with errors e and the measurement noise
covariance matrix Q. This is done according to the method
described in the research paper called: A simple and
accurate TDOA-AOA localization method using two stations.
Parameters
----------
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
k : tuple
Real measurement vector (without errors). It contains the
TDOA in range and two AOA pairs.
e : numpy.ndarray
Error vector of the TDOA in range and two AOA pairs.
Q : numpy.matrix
Measurement noise covariance matrix.
Returns
-------
u
Vector of the estimation of the unknown source position
(femto-satellite) in meters.
"""
d21_hat = k[0] + e[0]
theta1_hat = k[1] + e[1]
phi1_hat = k[2] + e[2]
theta2_hat = k[3] + e[3]
phi2_hat = k[4] + e[4]
b1_hat = self.get_b(theta1_hat, phi1_hat)
b2_hat = self.get_b(theta2_hat, phi2_hat)
G1_hat = self.get_Gm(theta1_hat, phi1_hat)
G2_hat = self.get_Gm(theta2_hat, phi2_hat)
G_hat = self.get_G(b1_hat, b2_hat, G1_hat, G2_hat)
G_hat_transpose = G_hat.transpose()
h_hat = self.get_h(d21_hat, s1, s2, b1_hat, b2_hat, G1_hat, G2_hat)
initial_estimate = (G_hat*G_hat_transpose).I*G_hat*h_hat
for i in range(2):
d1 = linalg.norm(initial_estimate - s1)
d2 = linalg.norm(initial_estimate - s2)
L1 = self.get_Lm(theta1_hat, phi1_hat)
L2 = self.get_Lm(theta2_hat, phi2_hat)
T1 = self.get_Tm(d1, phi1_hat)
T2 = self.get_Tm(d2, phi2_hat)
T = self.get_T(d1, d2, b1_hat, b2_hat, L1, L2, T1, T2)
W = self.get_W(Q, T)
if (linalg.det(W) == 0):
return initial_estimate
else:
W_inv = W.I
u_hat = (G_hat*W_inv*G_hat_transpose).I*G_hat*W_inv*h_hat
initial_estimate = u_hat
return u_hat
def RMSE(self, u, estimations, L):
"""
Returns the root-mean-square error.
Parameters
----------
u : numpy.matrix
Vector of the unknown source (femto-satellite)
real position in meters.
estimations : list
L estimations of the unknown source position.
L : int
Number of ensemble runs.
Returns
-------
RMSE
The Root-Mean-Square Error.
"""
aux = 0
for est in estimations:
aux += (est[0,0] - u[0,0])**2 + (est[1,0] - u[1,0])**2 + (est[2,0] - u[2,0])**2
return aux/L
def Bias(self, u, estimations, L):
"""
Returns the estimation bias.
Parameters
----------
u : numpy.matrix
Vector of the unknown source (femto-satellite)
real position in meters.
estimations : list
L estimations of the unknown source position.
L : int
Number of ensemble runs.
Returns
-------
bias
Estimation bias.
"""
acum_u_hat = matrix([[0.0], [0.0], [0.0]])
for est in estimations:
acum_u_hat += est
mean_u_hat = acum_u_hat/L
bias = (mean_u_hat[0,0] - u[0,0])**2 + (mean_u_hat[1,0] - u[1,0])**2 + (mean_u_hat[2,0] - u[2,0])**2
return bias
def get_GNSS_noise(self, std_GNSS, L):
"""
Creates an L length vector of zero mean Gaussian noise.
It considers the standard deviation of a GNSS device.
Parameters
----------
std_GNSS : float
Standard deviation of the GNSS device in meters.
L : int
Number of ensemble runs.
Returns
-------
e
Zero mean Gaussian noise to model the Error of the
two known positions s1 and s2 considering a GNSS
device with a standard deviation std_GNSS.
"""
accuracy_by_axis = std_GNSS/sqrt(3)
e = random.randn(6, L)
e[0,:] = accuracy_by_axis*(e[0,:] - mean(e[0,:]))
e[1,:] = accuracy_by_axis*(e[1,:] - mean(e[1,:]))
e[2,:] = accuracy_by_axis*(e[2,:] - mean(e[2,:]))
e[3,:] = accuracy_by_axis*(e[3,:] - mean(e[3,:]))
e[4,:] = accuracy_by_axis*(e[4,:] - mean(e[4,:]))
e[5,:] = accuracy_by_axis*(e[5,:] - mean(e[5,:]))
return e
def add_GNSS_error(self, s1, s2, e):
"""
Adds noise to the reference positions s1 and s2 considering
the accuracy of the GNSS device.
Parameters
----------
s1 : numpy.matrix
Vector of known position 1 (CubeSat 1) in meters.
s2 : numpy.matrix
Vector of known position 2 (CubeSat 2) in meters.
e : numpy.ndarray
Vector that models the noise of the GNSS devices
for both s1 and s2 known positions.
Returns
-------
noisy_s1
Position vector 1 (CubeSat 1) with zero mean Gaussian
noise due to the GNSS device accuracy.
noisy_s2
Position vector 2 (CubeSat 2) with zero mean Gaussian
noise due to the GNSS device accuracy.
"""
noisy_s1 = matrix([[s1[0,0] + e[0]],
[s1[1,0] + e[1]],
[s1[2,0] + e[2]]])
noisy_s2 = matrix([[s2[0,0] + e[3]],
[s2[1,0] + e[4]],
[s2[2,0] + e[5]]])
return noisy_s1, noisy_s2
def get_deployment_noise(self, std_ADS, std_ACS, N):
"""
Creates an N length vector of zero mean Gaussian noise.
It considers the standard deviation of the attitude
determination and control system of the CubeSat that
deploys the femto-satellite.
Parameters
----------
std_ADS : float
Standard deviation of the satellite's attitude
determination system in degrees.
std_ACS : float
Standard deviation of the satellite's attitude
control system in degrees.
N : int
Number of deployments to be simulated.
Returns
-------
e
Deployment direction noise given that both the attitude
determination and the attitude control systems are not
perfect.
"""
deg2rad = pi/180
e = random.randn(2, N)
e[0,:] = sqrt(std_ADS**2 + std_ACS**2)*deg2rad*(e[0,:] - mean(e[0,:]))
e[1,:] = sqrt(std_ADS**2 + std_ACS**2)*deg2rad*(e[1,:] - mean(e[1,:]))
return e
def noisy_dep_velocity(self, v, e):
"""
Adds noise to the ideal deployment velocity to simulate
the error of the attitude determination and control system
(ADCS) of the CubeSat that deploys the femto-satellite.
Parameters
----------
v : list
Intended deployment velocity (without ADCS noise).
e : numpy.ndarray
Error of the ADCS.
Returns
-------
new_vel
Actual deployent velocity considering the accuracy
of the ADCS.
"""
yaw_noise = e[0]
pitch_noise = e[1]
yaw = arctan2(v[1], v[0]) + yaw_noise
pitch = arctan2(v[2], sqrt(v[0]**2 + v[1]**2)) + pitch_noise
radius = sqrt(v[0]**2 + v[1]**2 + v[2]**2)
new_vel = [radius*cos(yaw)*cos(pitch), radius*sin(yaw)*cos(pitch), radius*sin(pitch)]
return new_vel
def simulation2(self, s1, s2, L, std_RD):
rmse = zeros(len(std_RD))
bias = zeros(len(std_RD))
rcrb = zeros(len(std_RD))
u = matrix([[1000.0], [1000.0], [1000.0]])
k = self.get_real_vector(u, s1, s2)
std_AOA = 0.5*pi/180.0
for i, sigma in enumerate(std_RD):
estimations = []
Q = self.get_Q(sigma, std_AOA)
MSE = self.get_MSE(u, s1, s2, k, Q)
e = self.get_error_vector(sigma, std_AOA, L)
for j in range(L):
u_hat = self.estimate(s1, s2, k, e[:,j], Q)
estimations.append(u_hat)
rmse[i] = self.RMSE(u, estimations, L)
bias[i] = self.Bias(u, estimations, L)
rcrb[i] = MSE[0,0] + MSE[1,1] + MSE[2,2]
return rmse, bias, rcrb
def plot_fig2(self, L):
"""
Figure 2 of A simple and accurate TDOA-AOA localization
method using two stations.
Parameters
----------
L : int
Number of ensemble runs.
"""
rmse = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
bias = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
rcrb = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
std_RD = [10**0.5, 10, 10**1.5, 10**2, 10**2.5, 10**3]
rmse = zeros(len(std_RD))
bias = zeros(len(std_RD))
rcrb = zeros(len(std_RD))
radius = 300.0
deg2rad = pi/180.0
L0 = 10
for i in range(L0):
theta_s = random.uniform(-179, 179)*deg2rad
phi_s = random.uniform(-89, 89)*deg2rad
#s1 = radius*matrix([[cos(theta_s)*cos(phi_s)],
# [sin(theta_s)*cos(phi_s)],
# [sin(phi_s)]])
s1 = radius*matrix([[cos(theta_s)], [sin(theta_s)], [0]])
s2 = -s1
rm, b, rc = self.simulation2(s1, s2, L, std_RD)
rmse += rm
bias += b
rcrb += rc
rmse = sqrt(rmse/L0)
bias = sqrt(bias/L0)
rcrb = sqrt(rcrb/L0)
fig, ax = subplots(1, 1, sharey=False)
ax.loglog(std_RD, rmse, 'o', linewidth=2.0, markersize=12, clip_on=False,
fillstyle="none", label="RMSE of the proposed method")
ax.loglog(std_RD, rcrb, '-', linewidth=2.0, markersize=12,
label="Root CRB")
ax.loglog(std_RD, bias, '+', linewidth=2.0, markersize=12, clip_on=False,
label="Bias of the proposed method")
ax.grid()
ax.legend(fontsize=14, loc="center right")
ax.set(xlabel="{} [m]".format(r'$\sigma_{RD}$'), ylabel="RMSE and bias [m]")
ax.xaxis.label.set_size(16)
ax.yaxis.label.set_size(16)
ax.tick_params(which="both", direction="in", labelsize=14,
bottom=True, top=True, left=True, right=True)
axis((10**0.5, 10**3, 10**(-1), 10**2))
tight_layout()
def simulation3(self, s1, s2, L, std_AOA):
rmse = zeros(len(std_AOA))
bias = zeros(len(std_AOA))
rcrb = zeros(len(std_AOA))
u = matrix([[1000.0], [1000.0], [1000.0]])
k = self.get_real_vector(u, s1, s2)
std_RD = 10.0
for i, sigma in enumerate(std_AOA):
estimations = []
Q = self.get_Q(std_RD, sigma)
MSE = self.get_MSE(u, s1, s2, k, Q)
e = self.get_error_vector(std_RD, sigma, L)
for j in range(L):
u_hat = self.estimate(s1, s2, k, e[:,j], Q)
estimations.append(u_hat)
rmse[i] = self.RMSE(u, estimations, L)
bias[i] = self.Bias(u, estimations, L)
rcrb[i] = MSE[0,0] + MSE[1,1] + MSE[2,2]
return rmse, bias, rcrb
def plot_fig3(self, L):
"""
Figure 3 of A simple and accurate TDOA-AOA localization
method using two stations.
Parameters
----------
L : int
Number of ensemble runs.
"""
std_AOA_deg = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5]
deg2rad = pi/180.0
std_AOA = [i*deg2rad for i in std_AOA_deg]
rmse = zeros(len(std_AOA))
bias = zeros(len(std_AOA))
rcrb = zeros(len(std_AOA))
radius = 300.0
L0 = 10
for i in range(L0):
theta_s = random.uniform(-179, 179)*deg2rad
phi_s = random.uniform(-89, 89)*deg2rad
#s1 = radius*matrix([[cos(theta_s)*cos(phi_s)],
# [sin(theta_s)*cos(phi_s)],
# [sin(phi_s)]])
s1 = radius*matrix([[cos(theta_s)], [sin(theta_s)], [0]])
s2 = -s1
rm, b, rc = self.simulation3(s1, s2, L, std_AOA)
rmse += rm
bias += b
rcrb += rc
rmse = sqrt(rmse/L0)
bias = sqrt(bias/L0)
rcrb = sqrt(rcrb/L0)
fig, ax = subplots(1, 1, sharey=False)
ax.semilogy(std_AOA_deg, rmse, 'o', linewidth=2.0, markersize=12, clip_on=False,
fillstyle="none", label="RMSE of the proposed method")
ax.semilogy(std_AOA_deg, rcrb, '-', linewidth=2.0, markersize=12,
label="Root CRB")
ax.semilogy(std_AOA_deg, bias, '+', linewidth=2.0, markersize=12, clip_on=False,
label="Bias of the proposed method")
ax.grid()
ax.legend(fontsize=14, loc="center right")
ax.set(xlabel="{} [deg]".format(r'$\sigma_{AOA}$'), ylabel="RMSE and bias [m]")
ax.xaxis.label.set_size(16)
ax.yaxis.label.set_size(16)
ax.tick_params(which="both", direction="in", labelsize=14,
bottom=True, top=True, left=True, right=True)
axis((0.5, 2.5, 10**(-1), 10**3))
xticks([0.5, 1, 1.5, 2, 2.5])
tight_layout()
def simulation4(self, s1, s2, L, ratio):
rmse = zeros(len(ratio))
bias = zeros(len(ratio))
rcrb = zeros(len(ratio))
std_RD = 10.0
std_AOA = 1.0*pi/180.0
Q = self.get_Q(std_RD, std_AOA)
base_u = sqrt(3)*matrix([[100.0], [100.0], [100.0]])
for i, a in enumerate(ratio):
estimations = []
u = a*base_u
k = self.get_real_vector(u, s1, s2)
MSE = self.get_MSE(u, s1, s2, k, Q)
e = self.get_error_vector(std_RD, std_AOA, L)
for j in range(L):
u_hat = self.estimate(s1, s2, k, e[:,j], Q)
estimations.append(u_hat)
rmse[i] = self.RMSE(u, estimations, L)
bias[i] = self.Bias(u, estimations, L)
rcrb[i] = MSE[0,0] + MSE[1,1] + MSE[2,2]
return rmse, bias, rcrb
def plot_fig4(self, L):
"""
Figure 4 of A simple and accurate TDOA-AOA localization
method using two stations.
Parameters
----------
L : int
Number of ensemble runs.
"""
ratio = [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
rmse = zeros(len(ratio))
bias = zeros(len(ratio))
rcrb = zeros(len(ratio))
radius = 300.0
deg2rad = pi/180.0
L0 = 10
for i in range(L0):
theta_s = random.uniform(-179, 179)*deg2rad
phi_s = random.uniform(-89, 89)*deg2rad
#s1 = radius*matrix([[cos(theta_s)*cos(phi_s)],
# [sin(theta_s)*cos(phi_s)],
# [sin(phi_s)]])
s1 = radius*matrix([[cos(theta_s)], [sin(theta_s)], [0]])
s2 = -s1
rm, b, rc = self.simulation4(s1, s2, L, ratio)
rmse += rm
bias += b
rcrb += rc
rmse = sqrt(rmse/L0)
bias = sqrt(bias/L0)
rcrb = sqrt(rcrb/L0)
fig, ax = subplots(1, 1, sharey=False)
ax.semilogy(ratio, rmse, 'o', linewidth=2.0, markersize=12, clip_on=False,
fillstyle="none", label="RMSE of the proposed method")
ax.semilogy(ratio, rcrb, '-', linewidth=2.0, markersize=12,
label="Root CRB")
ax.semilogy(ratio, bias, '+', linewidth=2.0, markersize=12, clip_on=False,
label="Bias of the proposed method")
ax.grid()
ax.legend(fontsize=14, loc="center right")
ax.set(xlabel="Source-to-station-range ratio a", ylabel="RMSE and bias [m]")
ax.xaxis.label.set_size(16)
ax.yaxis.label.set_size(16)
ax.tick_params(which="both", direction="in", labelsize=14,
bottom=True, top=True, left=True, right=True)
axis((2, 10, 10**(-1.2), 10**3))
xticks([2, 4, 6, 8, 10])
tight_layout()
def simulation_GNSS(self, sat_u, sat_s1, sat_s2, L, std_GNSS, date):
"""
Runs L estimations for each standard deviation of the GNSS
devices contained in std_GNSS. These standard deviations are
for the GNSS devices used by the CubeSats 1 and 2.
Parameters
----------
sat_u : pypredict.sat.Sat
Satellite object that describes all the orbital
parameters and position of the femto-satellite.
sat_s1 : pypredict.sat.Sat
Satellite object that describes all the orbital
parameters and position of the CubeSat 1.
sat_s2 : pypredict.sat.Sat
Satellite object that describes all the orbital
parameters and position of the CubeSat 2.
L : int
Number of ensemble runs.
std_GNSS : numpy.ndarray
Array of standard deviations of the GNSS devices
in meters.
date : datetime.datetime
Simulation date.
Returns
-------
rmse
The Root-Mean-Square Error.
bias
Estimation bias.
rcrb
The Root Cramer-Rao Bound.
"""
rmse = zeros(len(std_GNSS))
bias = zeros(len(std_GNSS))
rcrb = zeros(len(std_GNSS))
std_RD = 10.0
std_AOA = 1.0*pi/180.0
Q = self.get_Q(std_RD, std_AOA)
sat_u.updateOrbitalParameters(date)
sat_s1.updateOrbitalParameters(date)
sat_s2.updateOrbitalParameters(date + timedelta(seconds=4))
u = sat_u.getXYZ()
s1 = sat_s1.getXYZ()
s2 = sat_s2.getXYZ()
k = self.get_real_vector(u, s1, s2)
MSE = self.get_MSE(u, s1, s2, k, Q)
for i, std in enumerate(std_GNSS):
estimations = []
e = self.get_error_vector(std_RD, std_AOA, L)
GNSS_noise = self.get_GNSS_noise(std, L)
for j in range(L):
noisy_s1, noisy_s2 = self.add_GNSS_error(s1, s2, GNSS_noise[:,j])
k_w_GNSS_error = self.get_real_vector(u, noisy_s1, noisy_s2)
u_hat = self.estimate(noisy_s1, noisy_s2, k_w_GNSS_error, e[:,j], Q)
estimations.append(u_hat)
rmse[i] = self.RMSE(u, estimations, L)
bias[i] = self.Bias(u, estimations, L)
rcrb[i] = MSE[0,0] + MSE[1,1] + MSE[2,2]
print(sqrt(rcrb[i]))
return rmse, bias, rcrb
def plot_fig_GNSS(self, L, dep_date, output="rcrb_GNSS.csv"):
"""
This method studies the effect of the accuracy of the GNSS
devices used by the CubeSats in the femto-satellite's
position estimation. It simulates L0 deployments, and for
each deployment, L ensemble runs for each GNSS standard
deviation.
This method generates Figure 7 of the research paper called:
A femto-satellite localization method based on TDOA and AOA
using two Cubesats.
Parameters
----------
L : int
Number of ensemble runs.
dep_date : datetime.datetime
Date on which the deployment takes place.
"""
start = datetime.utcnow()
std_GNSS = array([10.0, 50.0, 100.0, 120.0])
std_ADS = 36/3600 # STT with 36 arcseconds of accuracy.
std_ACS = 0.06 # RWs of 0.06° of accuracy.
rmse = zeros(len(std_GNSS))
bias = zeros(len(std_GNSS))
rcrb = zeros(len(std_GNSS))
dpl = Dpl()
s1_mass = 3.2
u_mass = 0.08
L0 = 5000