source: ntrip/trunk/BNC/src/PPP_free/pppFilter.cpp@ 6115

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