source: ntrip/trunk/BNC/src/PPP_SSR_I/pppFilter.cpp@ 6968

Last change on this file since 6968 was 6968, checked in by stuerze, 9 years ago

some additions regarding BDS for future usage

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 37.0 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_pppParam, t_pppFilter
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43#include <sstream>
44#include <newmatio.h>
45#include <newmatap.h>
46
47#include "pppFilter.h"
48#include "pppClient.h"
49#include "bncutils.h"
50#include "bncantex.h"
51#include "pppOptions.h"
52#include "pppModel.h"
53
54using namespace BNC_PPP;
55using namespace std;
56
57const double MAXRES_CODE = 2.98 * 3.0;
58const double MAXRES_PHASE_GPS = 2.98 * 0.03;
59const double MAXRES_PHASE_GLONASS = 2.98 * 0.03;
60const double GLONASS_WEIGHT_FACTOR = 1.0;
61const double BDS_WEIGHT_FACTOR = 2.0;
62
63#define LOG (_pppClient->log())
64#define OPT (_pppClient->opt())
65
66// Constructor
67////////////////////////////////////////////////////////////////////////////
68t_pppParam::t_pppParam(t_pppParam::parType typeIn, int indexIn,
69 const QString& prnIn) {
70 type = typeIn;
71 index = indexIn;
72 prn = prnIn;
73 index_old = 0;
74 xx = 0.0;
75 numEpo = 0;
76}
77
78// Destructor
79////////////////////////////////////////////////////////////////////////////
80t_pppParam::~t_pppParam() {
81}
82
83// Partial
84////////////////////////////////////////////////////////////////////////////
85double t_pppParam::partial(t_satData* satData, bool phase) {
86
87 Tracer tracer("t_pppParam::partial");
88
89 // Coordinates
90 // -----------
91 if (type == CRD_X) {
92 return (xx - satData->xx(1)) / satData->rho;
93 }
94 else if (type == CRD_Y) {
95 return (xx - satData->xx(2)) / satData->rho;
96 }
97 else if (type == CRD_Z) {
98 return (xx - satData->xx(3)) / satData->rho;
99 }
100
101 // Receiver Clocks
102 // ---------------
103 else if (type == RECCLK) {
104 return 1.0;
105 }
106
107 // Troposphere
108 // -----------
109 else if (type == TROPO) {
110 return 1.0 / sin(satData->eleSat);
111 }
112
113 // Glonass Offset
114 // --------------
115 else if (type == GLONASS_OFFSET) {
116 if (satData->prn[0] == 'R') {
117 return 1.0;
118 }
119 else {
120 return 0.0;
121 }
122 }
123
124 // Galileo Offset
125 // --------------
126 else if (type == GALILEO_OFFSET) {
127 if (satData->prn[0] == 'E') {
128 return 1.0;
129 }
130 else {
131 return 0.0;
132 }
133 }
134
135 // BDS Offset
136 // ----------
137 else if (type == BDS_OFFSET) {
138 if (satData->prn[0] == 'C') {
139 return 1.0;
140 }
141 else {
142 return 0.0;
143 }
144 }
145
146 // Ambiguities
147 // -----------
148 else if (type == AMB_L3) {
149 if (phase && satData->prn == prn) {
150 return 1.0;
151 }
152 else {
153 return 0.0;
154 }
155 }
156
157 // Default return
158 // --------------
159 return 0.0;
160}
161
162// Constructor
163////////////////////////////////////////////////////////////////////////////
164t_pppFilter::t_pppFilter(t_pppClient* pppClient) {
165
166 _pppClient = pppClient;
167 _tides = new t_tides();
168
169 // Antenna Name, ANTEX File
170 // ------------------------
171 _antex = 0;
172 if (!OPT->_antexFileName.empty()) {
173 _antex = new bncAntex(OPT->_antexFileName.c_str());
174 }
175
176 // Bancroft Coordinates
177 // --------------------
178 _xcBanc.ReSize(4); _xcBanc = 0.0;
179 _ellBanc.ReSize(3); _ellBanc = 0.0;
180
181 // Save copy of data (used in outlier detection)
182 // ---------------------------------------------
183 _epoData_sav = new t_epoData();
184
185 // Some statistics
186 // ---------------
187 _neu.ReSize(3); _neu = 0.0;
188 _numSat = 0;
189 _pDop = 0.0;
190}
191
192// Destructor
193////////////////////////////////////////////////////////////////////////////
194t_pppFilter::~t_pppFilter() {
195 delete _tides;
196 delete _antex;
197 for (int iPar = 1; iPar <= _params.size(); iPar++) {
198 delete _params[iPar-1];
199 }
200 for (int iPar = 1; iPar <= _params_sav.size(); iPar++) {
201 delete _params_sav[iPar-1];
202 }
203 delete _epoData_sav;
204}
205
206// Reset Parameters and Variance-Covariance Matrix
207////////////////////////////////////////////////////////////////////////////
208void t_pppFilter::reset() {
209
210 Tracer tracer("t_pppFilter::reset");
211
212 double lastTrp = 0.0;
213 for (int ii = 0; ii < _params.size(); ii++) {
214 t_pppParam* pp = _params[ii];
215 if (pp->type == t_pppParam::TROPO) {
216 lastTrp = pp->xx;
217 }
218 delete pp;
219 }
220 _params.clear();
221
222 int nextPar = 0;
223 _params.push_back(new t_pppParam(t_pppParam::CRD_X, ++nextPar, ""));
224 _params.push_back(new t_pppParam(t_pppParam::CRD_Y, ++nextPar, ""));
225 _params.push_back(new t_pppParam(t_pppParam::CRD_Z, ++nextPar, ""));
226 _params.push_back(new t_pppParam(t_pppParam::RECCLK, ++nextPar, ""));
227 if (OPT->estTrp()) {
228 _params.push_back(new t_pppParam(t_pppParam::TROPO, ++nextPar, ""));
229 }
230 if (OPT->useSystem('R')) {
231 _params.push_back(new t_pppParam(t_pppParam::GLONASS_OFFSET, ++nextPar, ""));
232 }
233 if (OPT->useSystem('E')) {
234 _params.push_back(new t_pppParam(t_pppParam::GALILEO_OFFSET, ++nextPar, ""));
235 }/*
236 if (OPT->useSystem('C')) {
237 _params.push_back(new t_pppParam(t_pppParam::BDS_OFFSET, ++nextPar, ""));
238 }*/
239
240 _QQ.ReSize(_params.size());
241 _QQ = 0.0;
242 for (int iPar = 1; iPar <= _params.size(); iPar++) {
243 t_pppParam* pp = _params[iPar-1];
244 pp->xx = 0.0;
245 if (pp->isCrd()) {
246 _QQ(iPar,iPar) = OPT->_aprSigCrd(1) * OPT->_aprSigCrd(1);
247 }
248 else if (pp->type == t_pppParam::RECCLK) {
249 _QQ(iPar,iPar) = OPT->_noiseClk * OPT->_noiseClk;
250 }
251 else if (pp->type == t_pppParam::TROPO) {
252 _QQ(iPar,iPar) = OPT->_aprSigTrp * OPT->_aprSigTrp;
253 pp->xx = lastTrp;
254 }
255 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
256 _QQ(iPar,iPar) = 1000.0 * 1000.0;
257 }
258 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
259 _QQ(iPar,iPar) = 1000.0 * 1000.0;
260 }
261 else if (pp->type == t_pppParam::BDS_OFFSET) {
262 _QQ(iPar,iPar) = 1000.0 * 1000.0;
263 }
264 }
265}
266
267// Bancroft Solution
268////////////////////////////////////////////////////////////////////////////
269t_irc t_pppFilter::cmpBancroft(t_epoData* epoData) {
270
271 Tracer tracer("t_pppFilter::cmpBancroft");
272
273 if (int(epoData->sizeSys('G')) < OPT->_minObs) {
274 LOG << "t_pppFilter::cmpBancroft: not enough data\n";
275 return failure;
276 }
277
278 Matrix BB(epoData->sizeSys('G'), 4);
279
280 QMapIterator<QString, t_satData*> it(epoData->satData);
281 int iObsBanc = 0;
282 while (it.hasNext()) {
283 it.next();
284 t_satData* satData = it.value();
285 if (satData->system() == 'G') {
286 ++iObsBanc;
287 QString prn = it.key();
288 BB(iObsBanc, 1) = satData->xx(1);
289 BB(iObsBanc, 2) = satData->xx(2);
290 BB(iObsBanc, 3) = satData->xx(3);
291 BB(iObsBanc, 4) = satData->P3 + satData->clk;
292 }
293 }
294
295 bancroft(BB, _xcBanc);
296
297 // Ellipsoidal Coordinates
298 // ------------------------
299 xyz2ell(_xcBanc.data(), _ellBanc.data());
300
301 // Compute Satellite Elevations
302 // ----------------------------
303 QMutableMapIterator<QString, t_satData*> im(epoData->satData);
304 while (im.hasNext()) {
305 im.next();
306 t_satData* satData = im.value();
307 cmpEle(satData);
308 if (satData->eleSat < OPT->_minEle) {
309 delete satData;
310 im.remove();
311 }
312 }
313
314 return success;
315}
316
317// Computed Value
318////////////////////////////////////////////////////////////////////////////
319double t_pppFilter::cmpValue(t_satData* satData, bool phase) {
320
321 Tracer tracer("t_pppFilter::cmpValue");
322
323 ColumnVector xRec(3);
324 xRec(1) = x();
325 xRec(2) = y();
326 xRec(3) = z();
327
328 double rho0 = (satData->xx - xRec).norm_Frobenius();
329 double dPhi = t_CST::omega * rho0 / t_CST::c;
330
331 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
332 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
333 xRec(3) = z();
334
335 xRec += _tides->displacement(_time, xRec);
336
337 satData->rho = (satData->xx - xRec).norm_Frobenius();
338
339 double tropDelay = delay_saast(satData->eleSat) +
340 trp() / sin(satData->eleSat);
341
342 double wind = 0.0;
343 if (phase) {
344 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
345 }
346
347 double offset = 0.0;
348 t_frequency::type frqA = t_frequency::G1;
349 t_frequency::type frqB = t_frequency::G2;
350 if (satData->prn[0] == 'R') {
351 offset = Glonass_offset();
352 frqA = t_frequency::R1;
353 frqB = t_frequency::R2;
354 }
355 else if (satData->prn[0] == 'E') {
356 offset = Galileo_offset();
357 //frqA = t_frequency::E1; as soon as available
358 //frqB = t_frequency::E5; -"-
359 }
360 else if (satData->prn[0] == 'C') {
361 offset = Bds_offset();
362 //frqA = t_frequency::C2; as soon as available
363 //frqB = t_frequency::C7; -"-
364 }
365 double phaseCenter = 0.0;
366 if (_antex) {
367 bool found;
368 phaseCenter = satData->lkA * _antex->rcvCorr(OPT->_antNameRover, frqA,
369 satData->eleSat, satData->azSat,
370 found)
371 + satData->lkB * _antex->rcvCorr(OPT->_antNameRover, frqB,
372 satData->eleSat, satData->azSat,
373 found);
374 if (!found) {
375 LOG << "ANTEX: antenna >" << OPT->_antNameRover << "< not found\n";
376 }
377 }
378
379 double antennaOffset = 0.0;
380 double cosa = cos(satData->azSat);
381 double sina = sin(satData->azSat);
382 double cose = cos(satData->eleSat);
383 double sine = sin(satData->eleSat);
384 antennaOffset = -OPT->_neuEccRover(1) * cosa*cose
385 -OPT->_neuEccRover(2) * sina*cose
386 -OPT->_neuEccRover(3) * sine;
387
388 return satData->rho + phaseCenter + antennaOffset + clk()
389 + offset - satData->clk + tropDelay + wind;
390}
391
392// Tropospheric Model (Saastamoinen)
393////////////////////////////////////////////////////////////////////////////
394double t_pppFilter::delay_saast(double Ele) {
395
396 Tracer tracer("t_pppFilter::delay_saast");
397
398 double xyz[3];
399 xyz[0] = x();
400 xyz[1] = y();
401 xyz[2] = z();
402 double ell[3];
403 xyz2ell(xyz, ell);
404 double height = ell[2];
405
406 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
407 double TT = 18.0 - height * 0.0065 + 273.15;
408 double hh = 50.0 * exp(-6.396e-4 * height);
409 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
410
411 double h_km = height / 1000.0;
412
413 if (h_km < 0.0) h_km = 0.0;
414 if (h_km > 5.0) h_km = 5.0;
415 int ii = int(h_km + 1);
416 double href = ii - 1;
417
418 double bCor[6];
419 bCor[0] = 1.156;
420 bCor[1] = 1.006;
421 bCor[2] = 0.874;
422 bCor[3] = 0.757;
423 bCor[4] = 0.654;
424 bCor[5] = 0.563;
425
426 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
427
428 double zen = M_PI/2.0 - Ele;
429
430 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
431}
432
433// Prediction Step of the Filter
434////////////////////////////////////////////////////////////////////////////
435void t_pppFilter::predict(int iPhase, t_epoData* epoData) {
436
437 Tracer tracer("t_pppFilter::predict");
438
439 if (iPhase == 0) {
440
441 const double maxSolGap = 0.0;
442
443 bool firstCrd = false;
444 if (!_lastTimeOK.valid() || (maxSolGap > 0.0 && _time - _lastTimeOK > maxSolGap)) {
445 firstCrd = true;
446 _startTime = epoData->tt;
447 reset();
448 }
449
450 // Use different white noise for Quick-Start mode
451 // ----------------------------------------------
452 double sigCrdP_used = OPT->_noiseCrd(1);
453 if ( OPT->_seedingTime > 0.0 && OPT->_seedingTime > (epoData->tt - _startTime) ) {
454 sigCrdP_used = 0.0;
455 }
456
457 // Predict Parameter values, add white noise
458 // -----------------------------------------
459 for (int iPar = 1; iPar <= _params.size(); iPar++) {
460 t_pppParam* pp = _params[iPar-1];
461
462 // Coordinates
463 // -----------
464 if (pp->type == t_pppParam::CRD_X) {
465 if (firstCrd) {
466 if (OPT->xyzAprRoverSet()) {
467 pp->xx = OPT->_xyzAprRover[0];
468 }
469 else {
470 pp->xx = _xcBanc(1);
471 }
472 }
473 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
474 }
475 else if (pp->type == t_pppParam::CRD_Y) {
476 if (firstCrd) {
477 if (OPT->xyzAprRoverSet()) {
478 pp->xx = OPT->_xyzAprRover[1];
479 }
480 else {
481 pp->xx = _xcBanc(2);
482 }
483 }
484 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
485 }
486 else if (pp->type == t_pppParam::CRD_Z) {
487 if (firstCrd) {
488 if (OPT->xyzAprRoverSet()) {
489 pp->xx = OPT->_xyzAprRover[2];
490 }
491 else {
492 pp->xx = _xcBanc(3);
493 }
494 }
495 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
496 }
497
498 // Receiver Clocks
499 // ---------------
500 else if (pp->type == t_pppParam::RECCLK) {
501 pp->xx = _xcBanc(4);
502 for (int jj = 1; jj <= _params.size(); jj++) {
503 _QQ(iPar, jj) = 0.0;
504 }
505 _QQ(iPar,iPar) = OPT->_noiseClk * OPT->_noiseClk;
506 }
507
508 // Tropospheric Delay
509 // ------------------
510 else if (pp->type == t_pppParam::TROPO) {
511 _QQ(iPar,iPar) += OPT->_noiseTrp * OPT->_noiseTrp;
512 }
513
514 // Glonass Offset
515 // --------------
516 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
517 pp->xx = 0.0;
518 for (int jj = 1; jj <= _params.size(); jj++) {
519 _QQ(iPar, jj) = 0.0;
520 }
521 _QQ(iPar,iPar) = 1000.0 * 1000.0;
522 }
523
524 // Galileo Offset
525 // --------------
526 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
527 _QQ(iPar,iPar) += 0.1 * 0.1;
528 }
529
530 else if (pp->type == t_pppParam::BDS_OFFSET) {
531 _QQ(iPar,iPar) += 0.1 * 0.1;//TODO
532 }
533 }
534 }
535
536 // Add New Ambiguities if necessary
537 // --------------------------------
538 if (OPT->ambLCs('G').size() || OPT->ambLCs('R').size() ||
539 OPT->ambLCs('E').size() || OPT->ambLCs('C').size()) {
540
541 // Make a copy of QQ and xx, set parameter indices
542 // -----------------------------------------------
543 SymmetricMatrix QQ_old = _QQ;
544
545 for (int iPar = 1; iPar <= _params.size(); iPar++) {
546 _params[iPar-1]->index_old = _params[iPar-1]->index;
547 _params[iPar-1]->index = 0;
548 }
549
550 // Remove Ambiguity Parameters without observations
551 // ------------------------------------------------
552 int iPar = 0;
553 QMutableVectorIterator<t_pppParam*> im(_params);
554 while (im.hasNext()) {
555 t_pppParam* par = im.next();
556 bool removed = false;
557 if (par->type == t_pppParam::AMB_L3) {
558 if (epoData->satData.find(par->prn) == epoData->satData.end()) {
559 removed = true;
560 delete par;
561 im.remove();
562 }
563 }
564 if (! removed) {
565 ++iPar;
566 par->index = iPar;
567 }
568 }
569
570 // Add new ambiguity parameters
571 // ----------------------------
572 QMapIterator<QString, t_satData*> it(epoData->satData);
573 while (it.hasNext()) {
574 it.next();
575 t_satData* satData = it.value();
576 addAmb(satData);
577 }
578
579 int nPar = _params.size();
580 _QQ.ReSize(nPar); _QQ = 0.0;
581 for (int i1 = 1; i1 <= nPar; i1++) {
582 t_pppParam* p1 = _params[i1-1];
583 if (p1->index_old != 0) {
584 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
585 for (int i2 = 1; i2 <= nPar; i2++) {
586 t_pppParam* p2 = _params[i2-1];
587 if (p2->index_old != 0) {
588 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
589 }
590 }
591 }
592 }
593
594 for (int ii = 1; ii <= nPar; ii++) {
595 t_pppParam* par = _params[ii-1];
596 if (par->index_old == 0) {
597 _QQ(par->index, par->index) = OPT->_aprSigAmb * OPT->_aprSigAmb;
598 }
599 par->index_old = par->index;
600 }
601 }
602}
603
604// Update Step of the Filter (currently just a single-epoch solution)
605////////////////////////////////////////////////////////////////////////////
606t_irc t_pppFilter::update(t_epoData* epoData) {
607
608 Tracer tracer("t_pppFilter::update");
609
610 _time = epoData->tt; // current epoch time
611
612 if (OPT->useOrbClkCorr()) {
613 LOG << "Precise Point Positioning of Epoch " << _time.timestr(1)
614 << "\n---------------------------------------------------------------\n";
615 }
616 else {
617 LOG << "Single Point Positioning of Epoch " << _time.timestr(1)
618 << "\n--------------------------------------------------------------\n";
619 }
620
621 // Outlier Detection Loop
622 // ----------------------
623 if (update_p(epoData) != success) {
624 return failure;
625 }
626
627 // Set Solution Vector
628 // -------------------
629 LOG.setf(ios::fixed);
630 QVectorIterator<t_pppParam*> itPar(_params);
631 while (itPar.hasNext()) {
632 t_pppParam* par = itPar.next();
633 if (par->type == t_pppParam::RECCLK) {
634 LOG << "\n clk = " << setw(10) << setprecision(3) << par->xx
635 << " +- " << setw(6) << setprecision(3)
636 << sqrt(_QQ(par->index,par->index));
637 }
638 else if (par->type == t_pppParam::AMB_L3) {
639 ++par->numEpo;
640 LOG << "\n amb " << par->prn.mid(0,3).toAscii().data() << " = "
641 << setw(10) << setprecision(3) << par->xx
642 << " +- " << setw(6) << setprecision(3)
643 << sqrt(_QQ(par->index,par->index))
644 << " nEpo = " << par->numEpo;
645 }
646 else if (par->type == t_pppParam::TROPO) {
647 double aprTrp = delay_saast(M_PI/2.0);
648 LOG << "\n trp = " << par->prn.mid(0,3).toAscii().data()
649 << setw(7) << setprecision(3) << aprTrp << " "
650 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
651 << " +- " << setw(6) << setprecision(3)
652 << sqrt(_QQ(par->index,par->index));
653 }
654 else if (par->type == t_pppParam::GLONASS_OFFSET) {
655 LOG << "\n offGlo = " << setw(10) << setprecision(3) << par->xx
656 << " +- " << setw(6) << setprecision(3)
657 << sqrt(_QQ(par->index,par->index));
658 }
659 else if (par->type == t_pppParam::GALILEO_OFFSET) {
660 LOG << "\n offGal = " << setw(10) << setprecision(3) << par->xx
661 << " +- " << setw(6) << setprecision(3)
662 << sqrt(_QQ(par->index,par->index));
663 }
664 else if (par->type == t_pppParam::BDS_OFFSET) {
665 LOG << "\n offBds = " << setw(10) << setprecision(3) << par->xx
666 << " +- " << setw(6) << setprecision(3)
667 << sqrt(_QQ(par->index,par->index));
668 }
669 }
670
671 LOG << endl << endl;
672
673 // Compute dilution of precision
674 // -----------------------------
675 cmpDOP(epoData);
676
677 // Final Message (both log file and screen)
678 // ----------------------------------------
679 LOG << OPT->_roverName << " PPP "
680 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
681 << setw(14) << setprecision(3) << x() << " +- "
682 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
683 << setw(14) << setprecision(3) << y() << " +- "
684 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
685 << setw(14) << setprecision(3) << z() << " +- "
686 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
687
688 // NEU Output
689 // ----------
690 if (OPT->xyzAprRoverSet()) {
691 double xyz[3];
692 xyz[0] = x() - OPT->_xyzAprRover[0];
693 xyz[1] = y() - OPT->_xyzAprRover[1];
694 xyz[2] = z() - OPT->_xyzAprRover[2];
695
696 double ellRef[3];
697 xyz2ell(OPT->_xyzAprRover.data(), ellRef);
698 xyz2neu(ellRef, xyz, _neu.data());
699
700 LOG << " NEU "
701 << setw(8) << setprecision(3) << _neu[0] << " "
702 << setw(8) << setprecision(3) << _neu[1] << " "
703 << setw(8) << setprecision(3) << _neu[2] << endl << endl;
704 }
705 else {
706 LOG << endl << endl;
707 }
708
709 _lastTimeOK = _time; // remember time of last successful update
710 return success;
711}
712
713// Outlier Detection
714////////////////////////////////////////////////////////////////////////////
715QString t_pppFilter::outlierDetection(int iPhase, const ColumnVector& vv,
716 QMap<QString, t_satData*>& satData) {
717
718 Tracer tracer("t_pppFilter::outlierDetection");
719
720 QString prnGPS;
721 QString prnGlo;
722 double maxResGPS = 0.0;
723 double maxResGlo = 0.0;
724 findMaxRes(vv, satData, prnGPS, prnGlo, maxResGPS, maxResGlo);
725
726 if (iPhase == 1) {
727 if (maxResGlo > 2.98 * OPT->_maxResL1) {
728 LOG << "Outlier Phase " << prnGlo.toAscii().data() << ' ' << maxResGlo << endl;
729 return prnGlo;
730 }
731 else if (maxResGPS > 2.98 * OPT->_maxResL1) {
732 LOG << "Outlier Phase " << prnGPS.toAscii().data() << ' ' << maxResGPS << endl;
733 return prnGPS;
734 }
735 }
736 else if (iPhase == 0 && maxResGPS > 2.98 * OPT->_maxResC1) {
737 LOG << "Outlier Code " << prnGPS.toAscii().data() << ' ' << maxResGPS << endl;
738 return prnGPS;
739 }
740
741 return QString();
742}
743
744// Phase Wind-Up Correction
745///////////////////////////////////////////////////////////////////////////
746double t_pppFilter::windUp(const QString& prn, const ColumnVector& rSat,
747 const ColumnVector& rRec) {
748
749 Tracer tracer("t_pppFilter::windUp");
750
751 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
752
753 // First time - initialize to zero
754 // -------------------------------
755 if (!_windUpTime.contains(prn)) {
756 _windUpSum[prn] = 0.0;
757 }
758
759 // Compute the correction for new time
760 // -----------------------------------
761 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
762 _windUpTime[prn] = Mjd;
763
764 // Unit Vector GPS Satellite --> Receiver
765 // --------------------------------------
766 ColumnVector rho = rRec - rSat;
767 rho /= rho.norm_Frobenius();
768
769 // GPS Satellite unit Vectors sz, sy, sx
770 // -------------------------------------
771 ColumnVector sz = -rSat / rSat.norm_Frobenius();
772
773 ColumnVector xSun = t_astro::Sun(Mjd);
774 xSun /= xSun.norm_Frobenius();
775
776 ColumnVector sy = crossproduct(sz, xSun);
777 ColumnVector sx = crossproduct(sy, sz);
778
779 // Effective Dipole of the GPS Satellite Antenna
780 // ---------------------------------------------
781 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
782 - crossproduct(rho, sy);
783
784 // Receiver unit Vectors rx, ry
785 // ----------------------------
786 ColumnVector rx(3);
787 ColumnVector ry(3);
788
789 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
790 double neu[3];
791
792 neu[0] = 1.0;
793 neu[1] = 0.0;
794 neu[2] = 0.0;
795 neu2xyz(recEll, neu, rx.data());
796
797 neu[0] = 0.0;
798 neu[1] = -1.0;
799 neu[2] = 0.0;
800 neu2xyz(recEll, neu, ry.data());
801
802 // Effective Dipole of the Receiver Antenna
803 // ----------------------------------------
804 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
805 + crossproduct(rho, ry);
806
807 // Resulting Effect
808 // ----------------
809 double alpha = DotProduct(dipSat,dipRec) /
810 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
811
812 if (alpha > 1.0) alpha = 1.0;
813 if (alpha < -1.0) alpha = -1.0;
814
815 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
816
817 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
818 dphi = -dphi;
819 }
820
821 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
822 }
823
824 return _windUpSum[prn];
825}
826
827//
828///////////////////////////////////////////////////////////////////////////
829void t_pppFilter::cmpEle(t_satData* satData) {
830 Tracer tracer("t_pppFilter::cmpEle");
831 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
832 double rho = rr.norm_Frobenius();
833
834 double neu[3];
835 xyz2neu(_ellBanc.data(), rr.data(), neu);
836
837 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
838 if (neu[2] < 0) {
839 satData->eleSat *= -1.0;
840 }
841 satData->azSat = atan2(neu[1], neu[0]);
842}
843
844//
845///////////////////////////////////////////////////////////////////////////
846void t_pppFilter::addAmb(t_satData* satData) {
847 Tracer tracer("t_pppFilter::addAmb");
848 bool found = false;
849 for (int iPar = 1; iPar <= _params.size(); iPar++) {
850 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
851 _params[iPar-1]->prn == satData->prn) {
852 found = true;
853 break;
854 }
855 }
856 if (!found) {
857 t_pppParam* par = new t_pppParam(t_pppParam::AMB_L3,
858 _params.size()+1, satData->prn);
859 _params.push_back(par);
860 par->xx = satData->L3 - cmpValue(satData, true);
861 }
862}
863
864//
865///////////////////////////////////////////////////////////////////////////
866void t_pppFilter::addObs(int iPhase, unsigned& iObs, t_satData* satData,
867 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
868
869 Tracer tracer("t_pppFilter::addObs");
870
871 const double ELEWGHT = 20.0;
872 double ellWgtCoef = 1.0;
873 double eleD = satData->eleSat * 180.0 / M_PI;
874 if (eleD < ELEWGHT) {
875 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
876 }
877
878 // Remember Observation Index
879 // --------------------------
880 ++iObs;
881 satData->obsIndex = iObs;
882
883 // Phase Observations
884 // ------------------
885 if (iPhase == 1) {
886 ll(iObs) = satData->L3 - cmpValue(satData, true);
887 double sigL3 = 2.98 * OPT->_sigmaL1;
888 if (satData->system() == 'R') {
889 sigL3 *= GLONASS_WEIGHT_FACTOR;
890 }
891 if (satData->system() == 'C') {
892 sigL3 *= BDS_WEIGHT_FACTOR;
893 }
894 PP(iObs,iObs) = 1.0 / (sigL3 * sigL3) / (ellWgtCoef * ellWgtCoef);
895 for (int iPar = 1; iPar <= _params.size(); iPar++) {
896 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
897 _params[iPar-1]->prn == satData->prn) {
898 ll(iObs) -= _params[iPar-1]->xx;
899 }
900 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
901 }
902 }
903
904 // Code Observations
905 // -----------------
906 else {
907 double sigP3 = 2.98 * OPT->_sigmaC1;
908 ll(iObs) = satData->P3 - cmpValue(satData, false);
909 PP(iObs,iObs) = 1.0 / (sigP3 * sigP3) / (ellWgtCoef * ellWgtCoef);
910 for (int iPar = 1; iPar <= _params.size(); iPar++) {
911 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
912 }
913 }
914}
915
916//
917///////////////////////////////////////////////////////////////////////////
918QByteArray t_pppFilter::printRes(int iPhase, const ColumnVector& vv,
919 const QMap<QString, t_satData*>& satDataMap) {
920
921 Tracer tracer("t_pppFilter::printRes");
922
923 ostringstream str;
924 str.setf(ios::fixed);
925
926 QMapIterator<QString, t_satData*> it(satDataMap);
927 while (it.hasNext()) {
928 it.next();
929 t_satData* satData = it.value();
930 if (satData->obsIndex != 0) {
931 str << _time.timestr(1)
932 << " RES " << satData->prn.mid(0,3).toAscii().data()
933 << (iPhase ? " L3 " : " P3 ")
934 << setw(9) << setprecision(4) << vv(satData->obsIndex) << endl;
935 }
936 }
937
938 return QByteArray(str.str().c_str());
939}
940
941//
942///////////////////////////////////////////////////////////////////////////
943void t_pppFilter::findMaxRes(const ColumnVector& vv,
944 const QMap<QString, t_satData*>& satData,
945 QString& prnGPS, QString& prnGlo,
946 double& maxResGPS, double& maxResGlo) {
947
948 Tracer tracer("t_pppFilter::findMaxRes");
949
950 maxResGPS = 0.0;
951 maxResGlo = 0.0;
952
953 QMapIterator<QString, t_satData*> it(satData);
954 while (it.hasNext()) {
955 it.next();
956 t_satData* satData = it.value();
957 if (satData->obsIndex != 0) {
958 QString prn = satData->prn;
959 if (prn[0] == 'R') {
960 if (fabs(vv(satData->obsIndex)) > maxResGlo) {
961 maxResGlo = fabs(vv(satData->obsIndex));
962 prnGlo = prn;
963 }
964 }
965 else {
966 if (fabs(vv(satData->obsIndex)) > maxResGPS) {
967 maxResGPS = fabs(vv(satData->obsIndex));
968 prnGPS = prn;
969 }
970 }
971 }
972 }
973}
974
975// Update Step (private - loop over outliers)
976////////////////////////////////////////////////////////////////////////////
977t_irc t_pppFilter::update_p(t_epoData* epoData) {
978
979 Tracer tracer("t_pppFilter::update_p");
980
981 // Save Variance-Covariance Matrix, and Status Vector
982 // --------------------------------------------------
983 rememberState(epoData);
984
985 QString lastOutlierPrn;
986
987 // Try with all satellites, then with all minus one, etc.
988 // ------------------------------------------------------
989 while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
990
991 QByteArray strResCode;
992 QByteArray strResPhase;
993
994 // Bancroft Solution
995 // -----------------
996 if (cmpBancroft(epoData) != success) {
997 break;
998 }
999
1000 // First update using code observations, then phase observations
1001 // -------------------------------------------------------------
1002 bool usePhase = OPT->ambLCs('G').size() || OPT->ambLCs('R').size() ||
1003 OPT->ambLCs('E').size() || OPT->ambLCs('C').size() ;
1004
1005 for (int iPhase = 0; iPhase <= (usePhase ? 1 : 0); iPhase++) {
1006
1007 // Status Prediction
1008 // -----------------
1009 predict(iPhase, epoData);
1010
1011 // Create First-Design Matrix
1012 // --------------------------
1013 unsigned nPar = _params.size();
1014 unsigned nObs = 0;
1015 if (iPhase == 0) {
1016 nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
1017 }
1018 else {
1019 nObs = epoData->sizeAll();
1020 }
1021
1022 // Prepare first-design Matrix, vector observed-computed
1023 // -----------------------------------------------------
1024 Matrix AA(nObs, nPar); // first design matrix
1025 ColumnVector ll(nObs); // tems observed-computed
1026 DiagonalMatrix PP(nObs); PP = 0.0;
1027
1028 unsigned iObs = 0;
1029 QMapIterator<QString, t_satData*> it(epoData->satData);
1030 while (it.hasNext()) {
1031 it.next();
1032 t_satData* satData = it.value();
1033 if (iPhase == 1 || satData->system() != 'R') {
1034 QString prn = satData->prn;
1035 addObs(iPhase, iObs, satData, AA, ll, PP);
1036 }
1037 }
1038
1039 // Compute Filter Update
1040 // ---------------------
1041 ColumnVector dx(nPar); dx = 0.0;
1042 kalman(AA, ll, PP, _QQ, dx);
1043 ColumnVector vv = ll - AA * dx;
1044
1045 // Print Residuals
1046 // ---------------
1047 if (iPhase == 0) {
1048 strResCode = printRes(iPhase, vv, epoData->satData);
1049 }
1050 else {
1051 strResPhase = printRes(iPhase, vv, epoData->satData);
1052 }
1053
1054 // Check the residuals
1055 // -------------------
1056 lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
1057
1058 // No Outlier Detected
1059 // -------------------
1060 if (lastOutlierPrn.isEmpty()) {
1061
1062 QVectorIterator<t_pppParam*> itPar(_params);
1063 while (itPar.hasNext()) {
1064 t_pppParam* par = itPar.next();
1065 par->xx += dx(par->index);
1066 }
1067
1068 if (!usePhase || iPhase == 1) {
1069 if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
1070 LOG << "Neglected PRNs: ";
1071 if (!_outlierGPS.isEmpty()) {
1072 LOG << _outlierGPS.last().toAscii().data() << ' ';
1073 }
1074 QStringListIterator itGlo(_outlierGlo);
1075 while (itGlo.hasNext()) {
1076 QString prn = itGlo.next();
1077 LOG << prn.toAscii().data() << ' ';
1078 }
1079 }
1080 LOG << strResCode.data() << strResPhase.data();
1081
1082 return success;
1083 }
1084 }
1085
1086 // Outlier Found
1087 // -------------
1088 else {
1089 restoreState(epoData);
1090 break;
1091 }
1092
1093 } // for iPhase
1094
1095 } // while selectSatellites
1096
1097 restoreState(epoData);
1098 return failure;
1099}
1100
1101// Remeber Original State Vector and Variance-Covariance Matrix
1102////////////////////////////////////////////////////////////////////////////
1103void t_pppFilter::rememberState(t_epoData* epoData) {
1104
1105 _QQ_sav = _QQ;
1106
1107 QVectorIterator<t_pppParam*> itSav(_params_sav);
1108 while (itSav.hasNext()) {
1109 t_pppParam* par = itSav.next();
1110 delete par;
1111 }
1112 _params_sav.clear();
1113
1114 QVectorIterator<t_pppParam*> it(_params);
1115 while (it.hasNext()) {
1116 t_pppParam* par = it.next();
1117 _params_sav.push_back(new t_pppParam(*par));
1118 }
1119
1120 _epoData_sav->deepCopy(epoData);
1121}
1122
1123// Restore Original State Vector and Variance-Covariance Matrix
1124////////////////////////////////////////////////////////////////////////////
1125void t_pppFilter::restoreState(t_epoData* epoData) {
1126
1127 _QQ = _QQ_sav;
1128
1129 QVectorIterator<t_pppParam*> it(_params);
1130 while (it.hasNext()) {
1131 t_pppParam* par = it.next();
1132 delete par;
1133 }
1134 _params.clear();
1135
1136 QVectorIterator<t_pppParam*> itSav(_params_sav);
1137 while (itSav.hasNext()) {
1138 t_pppParam* par = itSav.next();
1139 _params.push_back(new t_pppParam(*par));
1140 }
1141
1142 epoData->deepCopy(_epoData_sav);
1143}
1144
1145//
1146////////////////////////////////////////////////////////////////////////////
1147t_irc t_pppFilter::selectSatellites(const QString& lastOutlierPrn,
1148 QMap<QString, t_satData*>& satData) {
1149
1150 // First Call
1151 // ----------
1152 if (lastOutlierPrn.isEmpty()) {
1153 _outlierGPS.clear();
1154 _outlierGlo.clear();
1155 return success;
1156 }
1157
1158 // Second and next trials
1159 // ----------------------
1160 else {
1161
1162 if (lastOutlierPrn[0] == 'R') {
1163 _outlierGlo << lastOutlierPrn;
1164 }
1165
1166 // Remove all Glonass Outliers
1167 // ---------------------------
1168 QStringListIterator it(_outlierGlo);
1169 while (it.hasNext()) {
1170 QString prn = it.next();
1171 if (satData.contains(prn)) {
1172 delete satData.take(prn);
1173 }
1174 }
1175
1176 if (lastOutlierPrn[0] == 'R') {
1177 _outlierGPS.clear();
1178 return success;
1179 }
1180
1181 // GPS Outlier appeared for the first time - try to delete it
1182 // ----------------------------------------------------------
1183 if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
1184 _outlierGPS << lastOutlierPrn;
1185 if (satData.contains(lastOutlierPrn)) {
1186 delete satData.take(lastOutlierPrn);
1187 }
1188 return success;
1189 }
1190
1191 }
1192
1193 return failure;
1194}
1195
1196//
1197////////////////////////////////////////////////////////////////////////////
1198double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
1199 return aa(1)*bb(1) + aa(2)*bb(2) + aa(3)*bb(3) - aa(4)*bb(4);
1200}
1201
1202//
1203////////////////////////////////////////////////////////////////////////////
1204void t_pppFilter::bancroft(const Matrix& BBpass, ColumnVector& pos) {
1205
1206 if (pos.Nrows() != 4) {
1207 pos.ReSize(4);
1208 }
1209 pos = 0.0;
1210
1211 for (int iter = 1; iter <= 2; iter++) {
1212 Matrix BB = BBpass;
1213 int mm = BB.Nrows();
1214 for (int ii = 1; ii <= mm; ii++) {
1215 double xx = BB(ii,1);
1216 double yy = BB(ii,2);
1217 double traveltime = 0.072;
1218 if (iter > 1) {
1219 double zz = BB(ii,3);
1220 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
1221 (yy-pos(2)) * (yy-pos(2)) +
1222 (zz-pos(3)) * (zz-pos(3)) );
1223 traveltime = rho / t_CST::c;
1224 }
1225 double angle = traveltime * t_CST::omega;
1226 double cosa = cos(angle);
1227 double sina = sin(angle);
1228 BB(ii,1) = cosa * xx + sina * yy;
1229 BB(ii,2) = -sina * xx + cosa * yy;
1230 }
1231
1232 Matrix BBB;
1233 if (mm > 4) {
1234 SymmetricMatrix hlp; hlp << BB.t() * BB;
1235 BBB = hlp.i() * BB.t();
1236 }
1237 else {
1238 BBB = BB.i();
1239 }
1240 ColumnVector ee(mm); ee = 1.0;
1241 ColumnVector alpha(mm); alpha = 0.0;
1242 for (int ii = 1; ii <= mm; ii++) {
1243 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
1244 }
1245 ColumnVector BBBe = BBB * ee;
1246 ColumnVector BBBalpha = BBB * alpha;
1247 double aa = lorentz(BBBe, BBBe);
1248 double bb = lorentz(BBBe, BBBalpha)-1;
1249 double cc = lorentz(BBBalpha, BBBalpha);
1250 double root = sqrt(bb*bb-aa*cc);
1251
1252 Matrix hlpPos(4,2);
1253 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
1254 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
1255
1256 ColumnVector omc(2);
1257 for (int pp = 1; pp <= 2; pp++) {
1258 hlpPos(4,pp) = -hlpPos(4,pp);
1259 omc(pp) = BB(1,4) -
1260 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
1261 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
1262 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
1263 hlpPos(4,pp);
1264 }
1265 if ( fabs(omc(1)) > fabs(omc(2)) ) {
1266 pos = hlpPos.Column(2);
1267 }
1268 else {
1269 pos = hlpPos.Column(1);
1270 }
1271 }
1272}
1273
1274//
1275////////////////////////////////////////////////////////////////////////////
1276void t_pppFilter::cmpDOP(t_epoData* epoData) {
1277
1278 Tracer tracer("t_pppFilter::cmpDOP");
1279
1280 _numSat = 0;
1281 _pDop = 0.0;
1282
1283 if (_params.size() < 4) {
1284 return;
1285 }
1286
1287 const unsigned numPar = 4;
1288 Matrix AA(epoData->sizeAll(), numPar);
1289 QMapIterator<QString, t_satData*> it(epoData->satData);
1290 while (it.hasNext()) {
1291 it.next();
1292 t_satData* satData = it.value();
1293 _numSat += 1;
1294 for (unsigned iPar = 0; iPar < numPar; iPar++) {
1295 AA[_numSat-1][iPar] = _params[iPar]->partial(satData, false);
1296 }
1297 }
1298 if (_numSat < 4) {
1299 return;
1300 }
1301 AA = AA.Rows(1, _numSat);
1302 SymmetricMatrix NN; NN << AA.t() * AA;
1303 SymmetricMatrix QQ = NN.i();
1304
1305 _pDop = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
1306}
Note: See TracBrowser for help on using the repository browser.