-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gsol.m
1364 lines (1334 loc) · 54.6 KB
/
Gsol.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
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
classdef Gsol < handle
% Gsol: GNSS solution class
% ---------------------------------------------------------------------
% Gsol Declaration:
% gsol = Gsol(); Create empty gt.Gsol object
%
% gsol = Gsol(file); Create gt.Gsol object from RTKLIB solution file
% file : 1x1, RTKLIB solution file (???.pos)
%
% gsol = Gsol(solstr); Create gt.Gsol object from solution struct
% sol : 1x1, RTKLIB solution struct
%
% gsol = Gsol(time, pos, [stat]); Create gt.Gsol object from time and position
% time : 1x1, Time, gt.Gtime object
% pos : 1x1, Position, gt.Gpos object
% [stat] : 1x1, Solution status (optional)
% ---------------------------------------------------------------------
% Gsol Properties:
% n : 1x1, Number of epochs
% time : 1x1, Time, gt.Gtime object
% pos : 1x1, Position, gt.Gpos object
% vel : 1x1, Velocity, gt.Gvel object
% pcov : 1x1, Position covariance, gt.Gcov object
% vcov : 1x1, Velocity covariance, gt.Gcov object
% dtr : (obj.n)x6, Receiver clock bias to time systems (s)
% ns : (obj.n)x1, Number of valid satellites
% stat : (obj.n)x1, Solution status (SOLQ_???)
% age : (obj.n)x1, Age of differential (s)
% ratio : (obj.n)x1, AR ratio factor for validation
% dt : 1x1, Solution time interval (s)
% ---------------------------------------------------------------------
% Gsol Methods:
% setSolFile(file); Set solution from file
% setSolStruct(solstr); Set solution from solution struct
% setSolTimePos(gtime, gpos, [stat]); Set solution from gt.Gtime and gt.Gpos objects
% setOrg(pos, type); Set coordinate origin
% setOrgGpos(gpos); Set coordinate origin by gt.Gpos
% outSol(file, [gopt]); Output solution file
% insert(idx, gsol); Insert gt.Gsol object
% append(gsol); Append gt.Gsol object
% [perr, verr] = difference(gobj); Compute position/velocity errors
% gsol = copy(); Copy object
% gsol = select(idx); Select solution from index
% gsol = selectTimeSpan(ts, te); Select solution from time span
% sol = struct([idx]); Convert from gt.Gsol object to solution struct
% gsol = fixedInterval([dt]); Resampling solution at fixed interval
% [gsol,gsolref] = common(gsolref); Extract common time with reference solution
% gobs = obj.same(gobsref); Same time as reference solution
% [gpos, gcov] = mean([stat],[idx]); Compute the position and covariance
% [mllh, sdenu] = meanLLH([stat],[idx]); Compute mean geodetic position and standard deviation
% [mxyz, sdxyz] = meanXYZ([stat],[idx]); Compute mean ECEF position and standard deviation
% [menu, sdenu] = meanENU([stat],[idx]); Compute mean ENU position and standard deviation
% nstat = statCount([stat]); Count solution status
% rstat = statRate([stat]); Compute solution status rate
% str = fixRateStr(); Ambiguity fixed rate string
% showFixRate(); Show ambiguity fixed rate
% outKML(file, [open], [lw], [lc], [ps], [pc], [idx], [alt]); Output Google Earth KML file
% plot([stat],[idx]); Plot solution position
% plotAll([stat],[idx]); Plot all solution
% plotMap([stat],[idx]); Plot solution to map
% plotSatMap([stat],[idx]); Plot solution to satellite map
% help(); Show help
% ---------------------------------------------------------------------
% Gsol Overloads:
% [perr, verr] = obj - gobj; Compute position/velocity errors
% ---------------------------------------------------------------------
% Author: Taro Suzuki
%
properties
n % Number of epochs
time % Time, gt.Gtime object
pos % Position, gt.Gpos object
vel % Velocity, gt.Gvel object
pcov % Position covariance, gt.Gcov object
vcov % Velocity covariance, gt.Gcov object
dtr % Receiver clock bias to time systems (s)
ns % Number of valid satellites
stat % Solution status (SOLQ_???)
age % Age of differential (s)
ratio % AR ratio factor for valiation
thres % threshold
dt % Solution time interval (s)
end
methods
%% constructor
function obj = Gsol(varargin)
if nargin==0 % generate empty object
obj.n = 0;
elseif nargin==1 && (ischar(varargin{1}) || isStringScalar(varargin{1}))
obj.setSolFile(char(varargin{1})); % file
elseif nargin==1 && isstruct(varargin{1})
obj.setSolStruct(varargin{1}); % sol struct
elseif nargin==2
obj.setSolTimePos(varargin{1}, varargin{2});
elseif nargin==3
obj.setSolTimePos(varargin{1}, varargin{2}, varargin{3});
else
error('Wrong input arguments');
end
end
%% setSolFile
function setSolFile(obj, file)
% setSolFile: Set solution from file
% -------------------------------------------------------------
% Read the .pos file of RTKLIB.
%
% Usage: ------------------------------------------------------
% obj.setSolFile(file)
%
% Input: ------------------------------------------------------
% file : RTKLIB solution file (???.pos)
%
arguments
obj gt.Gsol
file (1,:) char
end
[sol, sol.rb] = rtklib.readsol(obj.absPath(file));
% reference position
if all(sol.rb == [0,0,0])
sol.rb = [];
end
obj.setSolStruct(sol);
end
%% setSolStruct
function setSolStruct(obj, solstr)
% setSolStruct: Set solution from solution struct
% -------------------------------------------------------------
% Set objects from RTKLIB's solution structure.
%
% Usage: ------------------------------------------------------
% obj.setSolStruct(solstr)
%
% Input: ------------------------------------------------------
% solstr : RTKLIB solution struct
%
arguments
obj gt.Gsol
solstr struct
end
if ~all(solstr.type == solstr.type(1))
error('Solution formatting is inconsistent');
end
obj.n = solstr.n;
obj.time = gt.Gtime(solstr.ep);
obj.time.round(3);
obj.dt = obj.time.estInterval();
obj.dtr = solstr.dtr;
obj.ns = solstr.ns;
obj.stat = gt.C.SOLQ(solstr.stat);
obj.age = solstr.age;
obj.ratio = solstr.ratio;
obj.thres = solstr.thres;
if ~isfield(solstr, 'rb')
solstr.rb = [];
end
if ~isempty(solstr.rb)
if all(solstr.rb == [0,0,0])
solstr.rb = [];
end
end
solstr.rr(solstr.stat==0,:) = NaN;
if solstr.type(1) == 0 % ECEF
obj.pos = gt.Gpos(solstr.rr(:,1:3), 'xyz');
obj.pcov = gt.Gcov(solstr.qr, 'xyz');
if any(solstr.rr(:,4:6), 'all')
obj.vel = gt.Gvel(solstr.rr(:,4:6), 'xyz');
obj.vcov = gt.Gcov(solstr.qv, 'xyz');
end
if ~isempty(solstr.rb); obj.setOrg(solstr.rb, 'xyz'); end
else % enu
obj.pos = gt.Gpos(solstr.rr(:,1:3), 'enu');
obj.pcov = gt.Gcov(solstr.qr, 'enu');
if any(solstr.rr(:,4:6), 'all')
obj.vel = gt.Gvel(solstr.rr(:,4:6), 'enu');
obj.vcov = gt.Gcov(solstr.qv, 'enu');
end
if ~isempty(solstr.rb); obj.setOrg(solstr.rb, 'xyz'); end
end
end
%% setSolTimePos
function setSolTimePos(obj, gtime, gpos, stat)
% setSolTimePos: Set solution from gt.Gtime and gt.Gpos objects
% -------------------------------------------------------------
% gtime and gpos must be the same size.
%
% Usage: ------------------------------------------------------
% obj.setSolTimePos(time, pos, [stat])
%
% Input: ------------------------------------------------------
% gtime : Time, gt.Gtime object
% gpos : Position, gt.Gpos object
% stat : Solution status (optional) Default: gt.C.SOLQ_FIX
%
arguments
obj gt.Gsol
gtime gt.Gtime
gpos gt.Gpos
stat = gt.C.SOLQ_FIX
end
if gtime.n ~= gpos.n
error('Time and pos must be same size');
end
if isempty(gpos.xyz)
error('pos.xyz must be set to a value');
end
if isscalar(stat)
stat = stat*ones(gtime.n,1);
end
solstr.n = gtime.n;
solstr.rb = gpos.orgxyz;
solstr.ep = gtime.ep;
solstr.rr = [gpos.xyz zeros(solstr.n,3)];
solstr.qr = zeros(solstr.n,6);
solstr.qv = zeros(solstr.n,6);
solstr.dtr = zeros(solstr.n,6);
solstr.type = zeros(solstr.n,1);
solstr.stat = stat;
solstr.ns = ones(solstr.n,1);
solstr.age = zeros(solstr.n,1);
solstr.ratio = zeros(solstr.n,1);
solstr.thres = zeros(solstr.n,1);
obj.setSolStruct(solstr);
end
%% setOrg
function setOrg(obj, org, orgtype)
% setOrg: Set coordinate orgin
% -------------------------------------------------------------
% Geodetic and ECEF position can be set as the origin.
%
% Usage: ------------------------------------------------------
% obj.setOrg(org, orgtype)
%
% Input: ------------------------------------------------------
% org : Coordinate origin
% orgtype : Coordinate type: 'llh' or 'xyz'
%
arguments
obj gt.Gsol
org (1,3) double
orgtype (1,:) char {mustBeMember(orgtype,{'llh','xyz'})}
end
obj.pos.setOrg(org, orgtype);
obj.pcov.setOrg(org, orgtype);
if ~isempty(obj.vel)
obj.vel.setOrg(org, orgtype);
obj.vcov.setOrg(org, orgtype);
end
end
%% setOrgGpos
function setOrgGpos(obj, gpos)
% setOrgGpos: Set coordinate origin by gt.Gpos
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.setOrgGpos(gpos)
%
% Input: ------------------------------------------------------
% gpos : 1x1, gt.Gpos, Coordinate origin position
%
arguments
obj gt.Gsol
gpos gt.Gpos
end
if isempty(gpos.llh)
error("gpos.llh is empty");
end
obj.setOrg(gpos.llh(1,:),"llh");
end
%% outSol
function outSol(obj, file, gopt)
% outSol: Output solution file
% -------------------------------------------------------------
% Output RTKLIB solution file (???.pos).
%
% If an process option structure is input, output RTKLIB process
% options in the solution file header.
%
% Usage: ------------------------------------------------------
% obj.outSol(file, [gopt])
%
% Input: ------------------------------------------------------
% file : Output solution file name (???.pos)
% [gopt] : RTKLIB process option object (optional)
%
arguments
obj gt.Gsol
file (1,:) char
gopt = []
end
solstr = obj.struct();
if isempty(solstr.rb)
solstr.rb = [0 0 0];
end
if ~isempty(gopt)
if ~isa(gopt, 'gt.Gopt')
error('gt.Gopt must be input')
end
rtklib.outsol(obj.absPath(file), solstr, gopt.struct);
else
rtklib.outsol(obj.absPath(file), solstr);
end
end
%% insert
function insert(obj, idx, gsol)
% insert: Insert gt.Gsol object
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.insert(idx, gsol)
%
% Input: ------------------------------------------------------
% idx : 1x1, Integer index to insert data
% gsol: 1x1, gt.Gsol object
%
arguments
obj gt.Gobs
idx (1,1) {mustBeInteger}
gsol gt.Gsol
end
if idx<=0 || idx>obj.n
error('Index is out of range');
end
solstr1 = obj.struct();
solstr2 = gsol.struct();
solstr.n = solstr1.n+solstr2.n;
solstr.rb = obj.insertdata(solstr1.rb, idx, solstr2.rb);
solstr.ep = obj.insertdata(solstr1.ep, idx, solstr2.ep);
solstr.rr = obj.insertdata(solstr1.xyz, idx, solstr2.xyz);
solstr.qr = obj.insertdata(solstr1.qr, idx, solstr2.qr);
solstr.qv = obj.insertdata(solstr1.qv, idx, solstr2.qv);
solstr.dtr = obj.insertdata(solstr1.dtr, idx, solstr2.dtr);
solstr.type = obj.insertdata(solstr1.type, idx, solstr2.type);
solstr.stat = obj.insertdata(solstr1.stat, idx, solstr2.stat);
solstr.ns = obj.insertdata(solstr1.ns, idx, solstr2.ns);
solstr.age = obj.insertdata(solstr1.age, idx, solstr2.age);
solstr.ratio = obj.insertdata(solstr1.ratio, idx, solstr2.ratio);
solstr.thres = obj.insertdata(solstr1.thres, idx, solstr2.thres);
obj.setSolStruct(solstr);
end
%% append
function append(obj, gsol)
% append: Append gt.Gsol object
% -------------------------------------------------------------
% Add gt.Gobs object.
% obj.n will be obj.n+gsol.n
%
% Usage: ------------------------------------------------------
% obj.append(gsol)
%
% Input: ------------------------------------------------------
% gsol : 1x1, gt.Gsol object
%
arguments
obj gt.Gsol
gsol gt.Gsol
end
solstr1 = obj.struct();
solstr2 = gsol.struct();
solstr.n = solstr1.n+solstr2.n;
solstr.rb = solstr1.rb;
solstr.ep = [solstr1.ep; solstr2.ep];
solstr.rr = [solstr1.xyz; solstr2.xyz];
solstr.qr = [solstr1.qr; solstr2.qr];
solstr.qv = [solstr1.qv; solstr2.qv];
solstr.dtr = [solstr1.dtr; solstr2.dtr];
solstr.type = [solstr1.type; solstr2.type];
solstr.stat = [solstr1.stat; solstr2.stat];
solstr.ns = [solstr1.ns; solstr2.ns];
solstr.age = [solstr1.age; solstr2.age];
solstr.ratio = [solstr1.ratio; solstr2.ratio];
solstr.thres = [solstr1.thres; solstr2.thres];
obj.setSolStruct(solstr);
end
%% difference
function [perr, verr] = difference(obj, gobj)
% difference: Compute position/velocity errors
% -------------------------------------------------------------
% Compute the difference between two gt.Gsol objects and
% compute the position and velocity error.
%
% The size of the input must be the same as the size of this
% object.
%
% Usage: ------------------------------------------------------
% [perr, verr] = obj.difference(gobj)
%
% Input: ------------------------------------------------------
% gobj : gt.Gsol or gt.Gpos or gt.Gvel object
%
% Output: -----------------------------------------------------
% perr : 1x1, Position error, gt.Gerr object
% verr : 1x1, Velocity error, gt.Gerr object
%
arguments
obj gt.Gsol
gobj
end
verr = gt.Gerr();
switch class(gobj)
case 'gt.Gpos'
perr = obj.pos-gobj;
case 'gt.Gvel'
if ~isempty(obj.vel)
verr = obj.vel-gobj;
end
case 'gt.Gsol'
perr = obj.pos-gobj.pos;
if ~isempty(obj.vel) && ~isempty(gobj.vel)
verr = obj.vel-gobj.vel;
end
otherwise
error('gt.Gpos or gt.Gvel or gt.Gsol must be input')
end
end
%% copy
function gsol = copy(obj)
% copy: Copy object
% -------------------------------------------------------------
% MATLAB handle class is used, so if you want to create a
% different instance, you need to use the copy method.
%
% Usage: ------------------------------------------------------
% gsol = obj.copy()
%
% Output: -----------------------------------------------------
% gsol : 1x1, Copied gt.Gsol object
%
arguments
obj gt.Gsol
end
gsol = obj.select(1:obj.n);
end
%% select
function gsol = select(obj, idx)
% select: Select solution from index
% -------------------------------------------------------------
% Select solution from index and return a new object.
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% obj.select(idx)
%
% Input: ------------------------------------------------------
% idx : Logical or numeric index to select
%
% Output: -----------------------------------------------------
% gsol : 1x1, Selected gt.Gsol object
%
arguments
obj gt.Gsol
idx {mustBeInteger, mustBeVector}
end
if ~any(idx)
error('Selected index is empty');
end
solstr = obj.struct(idx);
gsol = gt.Gsol(solstr);
end
%% selectTimeSpan
function gsol = selectTimeSpan(obj, ts, te)
% selectTimeSpan: Select solution from time span
% -------------------------------------------------------------
% Select solution from the time span and return a new object.
% The time span is start and end time represented by gt.Gtime.
%
% Usage: ------------------------------------------------------
% obj.selectTimeSpan(ts, te)
%
% Input: ------------------------------------------------------
% ts : Start time (gt.Gtime)
% te : End time (gt.Gtime)
%
% Output: -----------------------------------------------------
% gsol : 1x1, Selected gt.Gsol object
%
arguments
obj gt.Gsol
ts gt.Gtime
te gt.Gtime
end
tr = obj.roundDateTime(obj.time.t, obj.dt);
tsr = obj.roundDateTime(ts.t, obj.dt);
ter = obj.roundDateTime(te.t, obj.dt);
idx = tr>=tsr & tr<=ter;
gsol = obj.select(idx);
end
%% struct
function solstr = struct(obj, idx)
% solstr: Convert from gt.Gsol object to solution struct
% -------------------------------------------------------------
% The index may be a logical or numeric index.
%
% Usage: ------------------------------------------------------
% obj.struct([idx])
%
% Input: ------------------------------------------------------
% [idx]: Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
%
% Output: -----------------------------------------------------
% solstr : RTKLIB solution struct
%
arguments
obj gt.Gsol
idx {mustBeInteger, mustBeVector} = 1:obj.n
end
if isempty(obj.pos.xyz)
pos_ = obj.pos.enu;
pcov_ = obj.pcov.enu;
type_ = ones(obj.n,1); % type (0:xyz-ecef,1:enu-baseline)
if ~isempty(obj.vel)
vel_ = obj.vel.enu;
vcov_ = obj.vcov.enu;
end
else
pos_ = obj.pos.xyz;
pcov_ = obj.pcov.xyz;
type_ = zeros(obj.n,1); % type (0:xyz-ecef,1:enu-baseline)
if ~isempty(obj.vel)
vel_ = obj.vel.xyz;
vcov_ = obj.vcov.xyz;
end
end
solstr.rb = obj.pos.orgxyz;
solstr.ep = obj.time.ep(idx,:);
solstr.n = size(solstr.ep,1);
if ~isempty(obj.vel)
solstr.rr = [pos_(idx,:) vel_(idx,:)];
solstr.qv = vcov_(idx,:);
else
solstr.rr = [pos_(idx,:) zeros(solstr.n,3)];
solstr.qv = zeros(solstr.n,6);
end
solstr.qr = pcov_(idx,:);
solstr.type = type_(idx);
solstr.dtr = obj.dtr(idx,:);
solstr.stat = double(obj.stat(idx,:));
solstr.ns = obj.ns(idx,:);
solstr.age = obj.age(idx,:);
solstr.ratio = obj.ratio(idx,:);
solstr.thres = obj.thres(idx,:);
end
%% fixedInterval
function gsol = fixedInterval(obj, dt)
% fixedInterval: Resampling solution at fixed interval
% -------------------------------------------------------------
% The time interval of the solution will be constant at the
% specified second.
%
% If the time interval of the original solution is not constant,
% NaN is inserted into the solution at that time.
%
% Usage: ------------------------------------------------------
% obj.fixedInterval([dt])
%
% Input: ------------------------------------------------------
% [dt] : 1x1, double, Time interval for resampling (s)
% (optional) Default: dt = obj.dt
%
% Output: -----------------------------------------------------
% gsol : 1x1, Resampled gt.Gsol object
%
arguments
obj gt.Gsol
dt (1,1) double = 0
end
if dt==0; dt = obj.dt; end
if isempty(obj.pos.xyz)
type = 1; % 0:xyz-ecef,1:enu-baseline
else
type = 0; % 0:xyz-ecef,1:enu-baseline
end
tr = obj.roundDateTime(obj.time.t,obj.dt);
tfixr = obj.roundDateTime((tr(1):seconds(dt):tr(end))',dt);
nfix = length(tfixr);
tfix = NaT(nfix,1,"TimeZone","UTC");
[~, idx1,idx2] = intersect(tfixr,tr);
tfix(idx1) = obj.time.t(idx2);
tfix = fillmissing(tfix,'linear');
gtfix = gt.Gtime(tfix);
solstr = obj.struct();
solstrfix.n = nfix;
solstrfix.ep = gtfix.ep;
solstrfix.rb = obj.pos.orgxyz;
solstrfix.rr = NaN(nfix,6);
solstrfix.qr = NaN(nfix,6);
solstrfix.qv = NaN(nfix,6);
solstrfix.dtr = NaN(nfix,6);
solstrfix.type = type*ones(nfix,1);
solstrfix.stat = zeros(nfix,1);
solstrfix.ns = NaN(nfix,1);
solstrfix.age = NaN(nfix,1);
solstrfix.ratio = NaN(nfix,1);
solstrfix.thres = zeros(nfix,1);
solstrfix.rr(idx1,:) = solstr.rr(idx2,:);
solstrfix.qr(idx1,:) = solstr.qr(idx2,:);
solstrfix.qv(idx1,:) = solstr.qv(idx2,:);
solstrfix.dtr(idx1,:) = solstr.dtr(idx2,:);
solstrfix.type(idx1) = solstr.type(idx2,:);
solstrfix.stat(idx1) = solstr.stat(idx2,:);
solstrfix.ns(idx1) = solstr.ns(idx2,:);
solstrfix.age(idx1) = solstr.age(idx2,:);
solstrfix.ratio(idx1) = solstr.ratio(idx2,:);
solstrfix.thres(idx1) = solstr.thres(idx2,:);
gsol = gt.Gsol(solstrfix);
end
%% commonSol
function [gsolc,gsolrefc] = commonSol(obj, gsolref)
% common: Extract common time with reference solution
% -------------------------------------------------------------
% Extract the common time between the reference gt.Gobs object
% and the current object.
%
% Output new gt.Gsol object and reference gt.Gsol object.
%
% gsolc.time = gsolrefc.time
%
% Usage: ------------------------------------------------------
% obj.common(gsolref)
%
% Input: ------------------------------------------------------
% gsolref : 1x1, Reference gt.Gsol object
%
% Output: -----------------------------------------------------
% gsolc : 1x1, New gt.Gsol object
% gsolrefc : 1x1, New reference gt.Gsol object
%
arguments
obj gt.Gsol
gsolref gt.Gsol
end
t = obj.roundDateTime(obj.time.t, obj.dt);
tref = obj.roundDateTime(gsolref.time.t, gsolref.dt);
[~,tind,tindref] = intersect(t, tref);
gsolc = obj.select(tind);
gsolrefc = gsolref.select(tindref);
end
%% sameSol
function gsol = same(obj, gsolref)
% same: Same time as reference solution
% -------------------------------------------------------------
% Create an gt.Gsol object whose time are consistent with
% the reference gt.Gsol object.
%
% gsol.time = gsolref.time
%
% If the time of the reference solution is not in the current
% solution, NaN is inserted into the solution.
%
% Usage: ------------------------------------------------------
% gobs = obj.same(gobsref)
%
% Input: ------------------------------------------------------
% gobsref : 1x1, Reference gt.Gobs object
%
% Output: -----------------------------------------------------
% gobs : 1x1, New gt.Gobs object
%
arguments
obj gt.Gsol
gsolref gt.Gsol
end
if isempty(obj.pos.xyz)
type = 1; % 0:xyz-ecef,1:enu-baseline
else
type = 0; % 0:xyz-ecef,1:enu-baseline
end
solstr_ = obj.struct;
n_ = gsolref.n;
solstr.n = n_;
t = obj.roundDateTime(obj.time.t, obj.dt);
tref = obj.roundDateTime(gsolref.time.t, gsolref.dt);
[~,idx1,idx2] = intersect(tref,t);
ep_ = gsolref.time.ep;
ep_(idx1,:) = obj.time.ep(idx2,:);
solstr.ep = ep_;
solstr.rb = obj.pos.orgxyz;
solstr.rr = NaN(n_,6);
solstr.qr = NaN(n_,6);
solstr.qv = NaN(n_,6);
solstr.dtr = NaN(n_,6);
solstr.type = type*ones(n_,1);
solstr.stat = zeros(n_,1);
solstr.ns = NaN(n_,1);
solstr.age = NaN(n_,1);
solstr.ratio = NaN(n_,1);
solstr.thres = zeros(n_,1);
solstr.rr(idx1,:) = solstr_.rr(idx2,:);
solstr.qr(idx1,:) = solstr_.qr(idx2,:);
solstr.qv(idx1,:) = solstr_.qv(idx2,:);
solstr.dtr(idx1,:) = solstr_.dtr(idx2,:);
solstr.type(idx1) = solstr_.type(idx2,:);
solstr.stat(idx1) = solstr_.stat(idx2,:);
solstr.ns(idx1) = solstr_.ns(idx2,:);
solstr.age(idx1) = solstr_.age(idx2,:);
solstr.ratio(idx1) = solstr_.ratio(idx2,:);
solstr.thres(idx1) = solstr_.thres(idx2,:);
gsol = gt.Gsol(solstr);
end
%% mean
function [gpos, gcov] = mean(obj, stat, idx)
% mean: Compute mean position and covariance
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.mean([stat], [idx])
%
% Input: ------------------------------------------------------
% [stat]: Solution status to compute mean position (optional)
% 0:ALL, SOLQ_XXX, Default: stat = 0
% [idx] : Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
%
% Output: -----------------------------------------------------
% gpos : 1x1, gt.Gpos object with mean position
% gcov : 1x1, gt.Gcov object
%
arguments
obj gt.Gsol
stat (1,1) {mustBeInteger} = 0
idx {mustBeInteger, mustBeVector} = 1:obj.n
end
if isempty(obj.pos.llh)
error('pos.llh must be set to a value');
end
gsol = obj.select(idx);
if stat==0
idxstat = true(gsol.n,1);
else
idxstat = gsol.stat==stat;
end
[gpos, gcov] = gsol.pos.mean(idxstat);
end
%% meanLLH
function [mllh, sdenu] = meanLLH(obj, stat, idx)
% meanLLH: Compute mean geodetic position and standard deviation
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.meanLLH([stat], [idx])
%
% Input: ------------------------------------------------------
% [stat]: Solution status to compute mean position (optional)
% 0:ALL, SOLQ_XXX, Default: stat = 0
% [idx] : Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
%
% Output: -----------------------------------------------------
% mllh : 1x3, Mean geodetic position
% sdenu : 1x3, Standard deviation of ENU position
%
arguments
obj gt.Gsol
stat (1,1) {mustBeInteger} = 0
idx {mustBeInteger, mustBeVector} = 1:obj.n
end
if isempty(obj.pos.llh)
error('pos.llh must be set to a value');
end
gsol = obj.select(idx);
if stat==0
idxstat = true(gsol.n,1);
else
idxstat = gsol.stat==stat;
end
[mllh, sdenu] = gsol.pos.meanLLH(idxstat);
end
%% meanXYZ
function [mxyz, sdxyz] = meanXYZ(obj, stat, idx)
% meanXYZ: Compute mean ECEF position and standard deviation
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.meanXYZ([stat], [idx])
%
% Input: ------------------------------------------------------
% [stat]: Solution status to compute mean position (optional)
% 0:ALL, SOLQ_XXX, Default: stat = 0
% [idx] : Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
%
% Output: -----------------------------------------------------
% mxyz : 1x3, Mean ECEF position
% sdxyz : 1x3, Standard deviation of ECEF position
%
arguments
obj gt.Gsol
stat (1,1) {mustBeInteger} = 0
idx {mustBeInteger, mustBeVector} = 1:obj.n
end
if isempty(obj.pos.xyz)
error('pos.xyz must be set to a value');
end
gsol = obj.select(idx);
if stat==0
idxstat = true(gsol.n,1);
else
idxstat = gsol.stat==stat;
end
[mxyz, sdxyz] = gsol.pos.meanXYZ(idxstat);
end
%% meanENU
function [menu, sdenu] = meanENU(obj, stat, idx)
% meanENU: Compute mean ENU position and standard deviation
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.meanENU([stat], [idx])
%
% Input: ------------------------------------------------------
% [stat]: Solution status to compute mean position (optional)
% 0:ALL, SOLQ_XXX, Default: stat = 0
% [idx] : Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
%
% Output: -----------------------------------------------------
% menu : 1x3, Mean ENU position
% sdenu : 1x3, Standard deviation of ENU position
%
arguments
obj gt.Gsol
stat (1,1) {mustBeInteger} = 0
idx {mustBeInteger, mustBeVector} = 1:obj.n
end
if isempty(obj.pos.enu)
error('pos.enu must be set to a value');
end
gsol = obj.select(idx);
if stat==0
idxstat = true(gsol.n,1);
else
idxstat = gsol.stat==stat;
end
[menu, sdenu] = gsol.pos.meanENU(idxstat);
end
%% statCount
function nstat = statCount(obj, stat)
% statCount: Count solution status
% -------------------------------------------------------------
% The order of solution status (SOLQ_???) is as follows:
% [FIX, FLOAT, SBAS, DGPS, SINGLE, PPP, DR]
%
% Usage: ------------------------------------------------------
% obj.statCount([stat])
%
% Input: ------------------------------------------------------
% [stat] : Solution status (optional)
% SOLQ_XXX, Default: All solution status
%
% Output: -----------------------------------------------------
% nstat : 1x7, Solution status count
%
arguments
obj gt.Gsol
stat (1,:) = 1:7
end
for i=1:length(stat)
nstat(1,i) = nnz(obj.stat==double(stat(i)));
end
end
%% statRate
function rstat = statRate(obj, stat)
% statRate: Compute solution status rate
% -------------------------------------------------------------
% The order of solution status (SOLQ_???) is as follows:
% [FIX, FLOAT, SBAS, DGPS, SINGLE, PPP, DR]][
%
% Usage: ------------------------------------------------------
% obj.statRate([stat])
%
% Input: ------------------------------------------------------
% [stat] : Solution status (optional)
% SOLQ_XXX, Default: All solution status
%
% Output: -----------------------------------------------------
% rstat : 1x7, Solution status rate (%)
%
arguments
obj gt.Gsol
stat (1,:) = 1:7
end
nstat = obj.statCount(stat);
rstat = 100*nstat/obj.n;
end
%% statRateStr
function str = statRateStr(obj)
% statRateStr: Solution status rate string
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% str = obj.statRateStr()
%
% Output: -----------------------------------------------------
% str : String, (Fix: %.1f% (%d/%d),...)
%
arguments
obj gt.Gsol
end
name = string(gt.C.SOLQNAME(double(unique(obj.stat))));
rate = obj.statRate(unique(obj.stat));
count = obj.statCount(unique(obj.stat));
str = "";
for i=1:length(name)
if i>=2
str = str+", ";
end
str = str+sprintf("%s:%.1f%% (%d/%d)",name(i),rate(i),count(i),obj.n);
end
end
%% showStatRate
function showStatRate(obj)
% showStatRate: Show status rate
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.showStatRate()
%
arguments
obj gt.Gsol
end
disp(obj.statRateStr);
end
%% fixRateStr
function str = fixRateStr(obj)
% fixRateStr: Ambiguity fixed rate string
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% str = obj.fixRateStr()
%
% Output: -----------------------------------------------------
% str : String, (Fixed rate: %.1f% (%d/%d))
%
arguments
obj gt.Gsol
end
nfix = obj.statCount(gt.C.SOLQ_FIX);
rfix = obj.statRate(gt.C.SOLQ_FIX);
str = sprintf("Fixed rate: %.1f%% (%d/%d)",rfix,nfix,obj.n);
end
%% showFixRate
function showFixRate(obj)
% showFixRate: Show ambiguity fixed rate
% -------------------------------------------------------------
%
% Usage: ------------------------------------------------------
% obj.showFixRate()
%
arguments
obj gt.Gsol
end
disp(obj.fixRateStr);
end
%% outKML
function outKML(obj, file, open, lw, lc, ps, pc, idx, alt)
% outKML: Output Google Earth KML file
% -------------------------------------------------------------
% Output Google Earth KML file. If Google Earth is installed,
% it will automatically open the KML file by default.
%
% Usage: ------------------------------------------------------
% obj.outKML(file, [open], [lw], [lc], [ps], [pc], [idx], [alt])
%
% Input: ------------------------------------------------------
% file: Output KML file name (???.kml)
% [open]: 1x1, Open KML file (optional) (0:off,1:on)
% Default: off
% [lw]: 1x1, Line width (0: No line) (optional) Default: 1.0
% [lc]: Line Color, MATLAB Style, e.g. "r" or [1 0 0]
% (optional) Default: "w"
% [ps]: 1x1, Point size (0: No point) (optional) Default: 0.5
% [pc]: Point Color, MATLAB Style (0: Solution status)
% e.g. "r" or [1 0 0] (optional) Default: 0
% [idx]: Logical or numeric index to select (optional)
% Default: idx = 1:obj.n
% [alt]: 1x1, Output altitude (optional)
% (0:off,1:elipsoidal,2:geodetic) Default: off
%
arguments