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

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