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

Last change on this file since 6162 was 6162, checked in by mervart, 10 years ago
File size: 35.3 KB
RevLine 
[6054]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 *
[6093]29 * Class: t_pppParam, t_pppFilter
[6054]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>
[6094]43#include <sstream>
[6054]44#include <newmatio.h>
[6094]45#include <newmatap.h>
[6054]46
[6093]47#include "pppFilter.h"
[6061]48#include "pppClient.h"
[6054]49#include "bncutils.h"
50#include "bncantex.h"
[6059]51#include "pppOptions.h"
[6060]52#include "pppModel.h"
[6054]53
[6055]54using namespace BNC_PPP;
[6054]55using namespace std;
56
[6115]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;
[6054]61
[6100]62#define LOG (_pppClient->log())
63#define OPT (_pppClient->opt())
64
[6054]65// Constructor
66////////////////////////////////////////////////////////////////////////////
[6093]67t_pppParam::t_pppParam(t_pppParam::parType typeIn, int indexIn,
[6054]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////////////////////////////////////////////////////////////////////////////
[6093]79t_pppParam::~t_pppParam() {
[6054]80}
81
82// Partial
83////////////////////////////////////////////////////////////////////////////
[6093]84double t_pppParam::partial(t_satData* satData, bool phase) {
[6054]85
[6093]86 Tracer tracer("t_pppParam::partial");
[6054]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////////////////////////////////////////////////////////////////////////////
[6093]152t_pppFilter::t_pppFilter(t_pppClient* pppClient) {
[6054]153
154 _pppClient = pppClient;
[6060]155 _tides = new t_tides();
156
[6054]157 // Antenna Name, ANTEX File
158 // ------------------------
159 _antex = 0;
[6100]160 if (!OPT->_antexFileName.empty()) {
161 _antex = new bncAntex(OPT->_antexFileName.c_str());
[6054]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();
[6112]172
173 // Some statistics
174 // ---------------
175 _neu.ReSize(3); _neu = 0.0;
176 _numSat = 0;
177 _pDop = 0.0;
[6054]178}
179
180// Destructor
181////////////////////////////////////////////////////////////////////////////
[6093]182t_pppFilter::~t_pppFilter() {
[6060]183 delete _tides;
[6054]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////////////////////////////////////////////////////////////////////////////
[6093]196void t_pppFilter::reset() {
[6054]197
[6093]198 Tracer tracer("t_pppFilter::reset");
[6054]199
200 double lastTrp = 0.0;
201 for (int ii = 0; ii < _params.size(); ii++) {
[6093]202 t_pppParam* pp = _params[ii];
203 if (pp->type == t_pppParam::TROPO) {
[6054]204 lastTrp = pp->xx;
205 }
206 delete pp;
207 }
208 _params.clear();
209
210 int nextPar = 0;
[6093]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, ""));
[6100]215 if (OPT->estTrp()) {
[6093]216 _params.push_back(new t_pppParam(t_pppParam::TROPO, ++nextPar, ""));
[6054]217 }
[6100]218 if (OPT->useSystem('R')) {
[6093]219 _params.push_back(new t_pppParam(t_pppParam::GLONASS_OFFSET, ++nextPar, ""));
[6054]220 }
[6100]221 if (OPT->useSystem('E')) {
[6093]222 _params.push_back(new t_pppParam(t_pppParam::GALILEO_OFFSET, ++nextPar, ""));
[6054]223 }
224
225 _QQ.ReSize(_params.size());
226 _QQ = 0.0;
227 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[6093]228 t_pppParam* pp = _params[iPar-1];
[6054]229 pp->xx = 0.0;
230 if (pp->isCrd()) {
[6100]231 _QQ(iPar,iPar) = OPT->_aprSigCrd(1) * OPT->_aprSigCrd(1);
[6054]232 }
[6093]233 else if (pp->type == t_pppParam::RECCLK) {
[6100]234 _QQ(iPar,iPar) = OPT->_noiseClk * OPT->_noiseClk;
[6054]235 }
[6093]236 else if (pp->type == t_pppParam::TROPO) {
[6100]237 _QQ(iPar,iPar) = OPT->_aprSigTrp * OPT->_aprSigTrp;
[6054]238 pp->xx = lastTrp;
239 }
[6093]240 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
[6060]241 _QQ(iPar,iPar) = 1000.0 * 1000.0;
[6054]242 }
[6093]243 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
[6060]244 _QQ(iPar,iPar) = 1000.0 * 1000.0;
[6054]245 }
246 }
247}
248
249// Bancroft Solution
250////////////////////////////////////////////////////////////////////////////
[6093]251t_irc t_pppFilter::cmpBancroft(t_epoData* epoData) {
[6054]252
[6093]253 Tracer tracer("t_pppFilter::cmpBancroft");
[6054]254
[6115]255 if (epoData->sizeSys('G') < OPT->_minObs) {
[6100]256 LOG << "t_pppFilter::cmpBancroft: not enough data\n";
[6054]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);
[6115]290 if (satData->eleSat < OPT->_minEle) {
[6054]291 delete satData;
292 im.remove();
293 }
294 }
295
296 return success;
297}
298
299// Computed Value
300////////////////////////////////////////////////////////////////////////////
[6093]301double t_pppFilter::cmpValue(t_satData* satData, bool phase) {
[6054]302
[6093]303 Tracer tracer("t_pppFilter::cmpValue");
[6054]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
[6060]317 xRec += _tides->displacement(_time, xRec);
[6054]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;
[6100]340 phaseCenter = _antex->pco(QString(OPT->_antNameRover.c_str()), satData->eleSat, found);
[6054]341 if (!found) {
[6100]342 LOG << "ANTEX: antenna >" << OPT->_antNameRover << "< not found\n";
[6054]343 }
344 }
345
346 double antennaOffset = 0.0;
[6061]347 double cosa = cos(satData->azSat);
348 double sina = sin(satData->azSat);
349 double cose = cos(satData->eleSat);
350 double sine = sin(satData->eleSat);
[6100]351 antennaOffset = -OPT->_neuEccRover(1) * cosa*cose
352 -OPT->_neuEccRover(2) * sina*cose
353 -OPT->_neuEccRover(3) * sine;
[6054]354
355 return satData->rho + phaseCenter + antennaOffset + clk()
356 + offset - satData->clk + tropDelay + wind;
357}
358
359// Tropospheric Model (Saastamoinen)
360////////////////////////////////////////////////////////////////////////////
[6093]361double t_pppFilter::delay_saast(double Ele) {
[6054]362
[6093]363 Tracer tracer("t_pppFilter::delay_saast");
[6054]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////////////////////////////////////////////////////////////////////////////
[6093]402void t_pppFilter::predict(int iPhase, t_epoData* epoData) {
[6054]403
[6093]404 Tracer tracer("t_pppFilter::predict");
[6054]405
406 if (iPhase == 0) {
407
[6061]408 const double maxSolGap = 0.0;
409
[6054]410 bool firstCrd = false;
[6061]411 if (!_lastTimeOK.valid() || (maxSolGap > 0.0 && _time - _lastTimeOK > maxSolGap)) {
[6054]412 firstCrd = true;
413 _startTime = epoData->tt;
414 reset();
415 }
416
417 // Use different white noise for Quick-Start mode
418 // ----------------------------------------------
[6100]419 double sigCrdP_used = OPT->_noiseCrd(1);
420 if ( OPT->_seedingTime > 0.0 && OPT->_seedingTime > (epoData->tt - _startTime) ) {
[6054]421 sigCrdP_used = 0.0;
422 }
423
424 // Predict Parameter values, add white noise
425 // -----------------------------------------
426 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[6093]427 t_pppParam* pp = _params[iPar-1];
[6054]428
429 // Coordinates
430 // -----------
[6093]431 if (pp->type == t_pppParam::CRD_X) {
[6054]432 if (firstCrd) {
[6100]433 if (OPT->xyzAprRoverSet()) {
434 pp->xx = OPT->_xyzAprRover[0];
[6054]435 }
436 else {
437 pp->xx = _xcBanc(1);
438 }
439 }
440 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
441 }
[6093]442 else if (pp->type == t_pppParam::CRD_Y) {
[6054]443 if (firstCrd) {
[6100]444 if (OPT->xyzAprRoverSet()) {
445 pp->xx = OPT->_xyzAprRover[1];
[6054]446 }
447 else {
448 pp->xx = _xcBanc(2);
449 }
450 }
451 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
452 }
[6093]453 else if (pp->type == t_pppParam::CRD_Z) {
[6054]454 if (firstCrd) {
[6100]455 if (OPT->xyzAprRoverSet()) {
456 pp->xx = OPT->_xyzAprRover[2];
[6054]457 }
458 else {
459 pp->xx = _xcBanc(3);
460 }
461 }
462 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
463 }
464
465 // Receiver Clocks
466 // ---------------
[6093]467 else if (pp->type == t_pppParam::RECCLK) {
[6054]468 pp->xx = _xcBanc(4);
469 for (int jj = 1; jj <= _params.size(); jj++) {
470 _QQ(iPar, jj) = 0.0;
471 }
[6100]472 _QQ(iPar,iPar) = OPT->_noiseClk * OPT->_noiseClk;
[6054]473 }
474
475 // Tropospheric Delay
476 // ------------------
[6093]477 else if (pp->type == t_pppParam::TROPO) {
[6100]478 _QQ(iPar,iPar) += OPT->_noiseTrp * OPT->_noiseTrp;
[6054]479 }
480
481 // Glonass Offset
482 // --------------
[6093]483 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
[6061]484 pp->xx = 0.0;
485 for (int jj = 1; jj <= _params.size(); jj++) {
486 _QQ(iPar, jj) = 0.0;
[6054]487 }
[6061]488 _QQ(iPar,iPar) = 1000.0 * 1000.0;
[6054]489 }
490
491 // Galileo Offset
492 // --------------
[6093]493 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
[6061]494 _QQ(iPar,iPar) += 0.1 * 0.1;
[6054]495 }
496 }
497 }
498
499 // Add New Ambiguities if necessary
500 // --------------------------------
[6100]501 if (OPT->ambLCs('G').size() || OPT->ambLCs('R').size() || OPT->ambLCs('E').size()) {
[6054]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;
[6093]515 QMutableVectorIterator<t_pppParam*> im(_params);
[6054]516 while (im.hasNext()) {
[6093]517 t_pppParam* par = im.next();
[6054]518 bool removed = false;
[6093]519 if (par->type == t_pppParam::AMB_L3) {
[6054]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++) {
[6093]544 t_pppParam* p1 = _params[i1-1];
[6054]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++) {
[6093]548 t_pppParam* p2 = _params[i2-1];
[6054]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++) {
[6093]557 t_pppParam* par = _params[ii-1];
[6054]558 if (par->index_old == 0) {
[6100]559 _QQ(par->index, par->index) = OPT->_aprSigAmb * OPT->_aprSigAmb;
[6054]560 }
561 par->index_old = par->index;
562 }
563 }
564}
565
566// Update Step of the Filter (currently just a single-epoch solution)
567////////////////////////////////////////////////////////////////////////////
[6093]568t_irc t_pppFilter::update(t_epoData* epoData) {
[6054]569
[6093]570 Tracer tracer("t_pppFilter::update");
[6054]571
572 _time = epoData->tt; // current epoch time
573
[6100]574 if (OPT->useOrbClkCorr()) {
575 LOG << "Precise Point Positioning of Epoch " << _time.timestr(1)
576 << "\n---------------------------------------------------------------\n";
[6054]577 }
578 else {
[6100]579 LOG << "Single Point Positioning of Epoch " << _time.timestr(1)
580 << "\n--------------------------------------------------------------\n";
[6054]581 }
582
583 // Outlier Detection Loop
584 // ----------------------
585 if (update_p(epoData) != success) {
586 return failure;
587 }
588
589 // Set Solution Vector
590 // -------------------
[6100]591 LOG.setf(ios::fixed);
[6093]592 QVectorIterator<t_pppParam*> itPar(_params);
[6054]593 while (itPar.hasNext()) {
[6093]594 t_pppParam* par = itPar.next();
595 if (par->type == t_pppParam::RECCLK) {
[6100]596 LOG << "\n clk = " << setw(10) << setprecision(3) << par->xx
597 << " +- " << setw(6) << setprecision(3)
598 << sqrt(_QQ(par->index,par->index));
[6054]599 }
[6093]600 else if (par->type == t_pppParam::AMB_L3) {
[6054]601 ++par->numEpo;
[6100]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;
[6054]607 }
[6093]608 else if (par->type == t_pppParam::TROPO) {
[6054]609 double aprTrp = delay_saast(M_PI/2.0);
[6100]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));
[6054]615 }
[6093]616 else if (par->type == t_pppParam::GLONASS_OFFSET) {
[6100]617 LOG << "\n offGlo = " << setw(10) << setprecision(3) << par->xx
618 << " +- " << setw(6) << setprecision(3)
619 << sqrt(_QQ(par->index,par->index));
[6054]620 }
[6093]621 else if (par->type == t_pppParam::GALILEO_OFFSET) {
[6100]622 LOG << "\n offGal = " << setw(10) << setprecision(3) << par->xx
623 << " +- " << setw(6) << setprecision(3)
624 << sqrt(_QQ(par->index,par->index));
[6054]625 }
626 }
627
[6105]628 LOG << endl << endl;
[6100]629
[6112]630 // Compute dilution of precision
631 // -----------------------------
632 cmpDOP(epoData);
633
[6054]634 // Final Message (both log file and screen)
635 // ----------------------------------------
[6100]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));
[6054]644
645 // NEU Output
646 // ----------
[6100]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];
[6054]652
653 double ellRef[3];
[6100]654 xyz2ell(OPT->_xyzAprRover.data(), ellRef);
[6112]655 xyz2neu(ellRef, xyz, _neu.data());
[6054]656
[6100]657 LOG << " NEU "
[6112]658 << setw(8) << setprecision(3) << _neu[0] << " "
659 << setw(8) << setprecision(3) << _neu[1] << " "
660 << setw(8) << setprecision(3) << _neu[2] << endl << endl;
[6054]661 }
[6100]662 else {
[6105]663 LOG << endl << endl;
[6100]664 }
[6054]665
666 _lastTimeOK = _time; // remember time of last successful update
667 return success;
668}
669
670// Outlier Detection
671////////////////////////////////////////////////////////////////////////////
[6093]672QString t_pppFilter::outlierDetection(int iPhase, const ColumnVector& vv,
[6054]673 QMap<QString, t_satData*>& satData) {
674
[6093]675 Tracer tracer("t_pppFilter::outlierDetection");
[6054]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) {
[6115]684 if (maxResGlo > 2.98 * OPT->_maxResL1) {
[6100]685 LOG << "Outlier Phase " << prnGlo.toAscii().data() << ' ' << maxResGlo << endl;
[6054]686 return prnGlo;
687 }
[6115]688 else if (maxResGPS > 2.98 * OPT->_maxResL1) {
[6100]689 LOG << "Outlier Phase " << prnGPS.toAscii().data() << ' ' << maxResGPS << endl;
[6054]690 return prnGPS;
691 }
692 }
[6115]693 else if (iPhase == 0 && maxResGPS > 2.98 * OPT->_maxResC1) {
[6100]694 LOG << "Outlier Code " << prnGPS.toAscii().data() << ' ' << maxResGPS << endl;
[6054]695 return prnGPS;
696 }
697
698 return QString();
699}
700
701// Phase Wind-Up Correction
702///////////////////////////////////////////////////////////////////////////
[6093]703double t_pppFilter::windUp(const QString& prn, const ColumnVector& rSat,
[6054]704 const ColumnVector& rRec) {
705
[6093]706 Tracer tracer("t_pppFilter::windUp");
[6054]707
708 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
709
710 // First time - initialize to zero
711 // -------------------------------
712 if (!_windUpTime.contains(prn)) {
713 _windUpSum[prn] = 0.0;
714 }
715
716 // Compute the correction for new time
717 // -----------------------------------
718 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
719 _windUpTime[prn] = Mjd;
720
721 // Unit Vector GPS Satellite --> Receiver
722 // --------------------------------------
723 ColumnVector rho = rRec - rSat;
724 rho /= rho.norm_Frobenius();
725
726 // GPS Satellite unit Vectors sz, sy, sx
727 // -------------------------------------
728 ColumnVector sz = -rSat / rSat.norm_Frobenius();
729
[6063]730 ColumnVector xSun = t_astro::Sun(Mjd);
[6054]731 xSun /= xSun.norm_Frobenius();
732
733 ColumnVector sy = crossproduct(sz, xSun);
734 ColumnVector sx = crossproduct(sy, sz);
735
736 // Effective Dipole of the GPS Satellite Antenna
737 // ---------------------------------------------
738 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
739 - crossproduct(rho, sy);
740
741 // Receiver unit Vectors rx, ry
742 // ----------------------------
743 ColumnVector rx(3);
744 ColumnVector ry(3);
745
746 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
747 double neu[3];
748
749 neu[0] = 1.0;
750 neu[1] = 0.0;
751 neu[2] = 0.0;
752 neu2xyz(recEll, neu, rx.data());
753
754 neu[0] = 0.0;
755 neu[1] = -1.0;
756 neu[2] = 0.0;
757 neu2xyz(recEll, neu, ry.data());
758
759 // Effective Dipole of the Receiver Antenna
760 // ----------------------------------------
761 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
762 + crossproduct(rho, ry);
763
764 // Resulting Effect
765 // ----------------
766 double alpha = DotProduct(dipSat,dipRec) /
767 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
768
769 if (alpha > 1.0) alpha = 1.0;
770 if (alpha < -1.0) alpha = -1.0;
771
772 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
773
774 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
775 dphi = -dphi;
776 }
777
778 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
779 }
780
781 return _windUpSum[prn];
782}
783
784//
785///////////////////////////////////////////////////////////////////////////
[6093]786void t_pppFilter::cmpEle(t_satData* satData) {
787 Tracer tracer("t_pppFilter::cmpEle");
[6054]788 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
789 double rho = rr.norm_Frobenius();
790
791 double neu[3];
792 xyz2neu(_ellBanc.data(), rr.data(), neu);
793
794 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
795 if (neu[2] < 0) {
796 satData->eleSat *= -1.0;
797 }
798 satData->azSat = atan2(neu[1], neu[0]);
799}
800
801//
802///////////////////////////////////////////////////////////////////////////
[6093]803void t_pppFilter::addAmb(t_satData* satData) {
804 Tracer tracer("t_pppFilter::addAmb");
[6054]805 bool found = false;
806 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[6093]807 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
[6054]808 _params[iPar-1]->prn == satData->prn) {
809 found = true;
810 break;
811 }
812 }
813 if (!found) {
[6093]814 t_pppParam* par = new t_pppParam(t_pppParam::AMB_L3,
[6054]815 _params.size()+1, satData->prn);
816 _params.push_back(par);
817 par->xx = satData->L3 - cmpValue(satData, true);
818 }
819}
820
821//
822///////////////////////////////////////////////////////////////////////////
[6093]823void t_pppFilter::addObs(int iPhase, unsigned& iObs, t_satData* satData,
[6054]824 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
825
[6093]826 Tracer tracer("t_pppFilter::addObs");
[6054]827
828 const double ELEWGHT = 20.0;
829 double ellWgtCoef = 1.0;
830 double eleD = satData->eleSat * 180.0 / M_PI;
831 if (eleD < ELEWGHT) {
832 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
833 }
834
835 // Remember Observation Index
836 // --------------------------
837 ++iObs;
838 satData->obsIndex = iObs;
839
840 // Phase Observations
841 // ------------------
842 if (iPhase == 1) {
843 ll(iObs) = satData->L3 - cmpValue(satData, true);
[6100]844 double sigL3 = 2.98 * OPT->_sigmaL1;
[6054]845 if (satData->system() == 'R') {
846 sigL3 *= GLONASS_WEIGHT_FACTOR;
847 }
848 PP(iObs,iObs) = 1.0 / (sigL3 * sigL3) / (ellWgtCoef * ellWgtCoef);
849 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[6093]850 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
[6054]851 _params[iPar-1]->prn == satData->prn) {
852 ll(iObs) -= _params[iPar-1]->xx;
853 }
854 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
855 }
856 }
857
858 // Code Observations
859 // -----------------
860 else {
[6100]861 double sigP3 = 2.98 * OPT->_sigmaC1;
[6054]862 ll(iObs) = satData->P3 - cmpValue(satData, false);
[6064]863 PP(iObs,iObs) = 1.0 / (sigP3 * sigP3) / (ellWgtCoef * ellWgtCoef);
[6054]864 for (int iPar = 1; iPar <= _params.size(); iPar++) {
865 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
866 }
867 }
868}
869
870//
871///////////////////////////////////////////////////////////////////////////
[6093]872QByteArray t_pppFilter::printRes(int iPhase, const ColumnVector& vv,
[6054]873 const QMap<QString, t_satData*>& satDataMap) {
874
[6093]875 Tracer tracer("t_pppFilter::printRes");
[6054]876
877 ostringstream str;
878 str.setf(ios::fixed);
879
880 QMapIterator<QString, t_satData*> it(satDataMap);
881 while (it.hasNext()) {
882 it.next();
883 t_satData* satData = it.value();
884 if (satData->obsIndex != 0) {
885 str << _time.timestr(1)
886 << " RES " << satData->prn.toAscii().data()
887 << (iPhase ? " L3 " : " P3 ")
888 << setw(9) << setprecision(4) << vv(satData->obsIndex) << endl;
889 }
890 }
891
892 return QByteArray(str.str().c_str());
893}
894
895//
896///////////////////////////////////////////////////////////////////////////
[6093]897void t_pppFilter::findMaxRes(const ColumnVector& vv,
[6054]898 const QMap<QString, t_satData*>& satData,
899 QString& prnGPS, QString& prnGlo,
900 double& maxResGPS, double& maxResGlo) {
901
[6093]902 Tracer tracer("t_pppFilter::findMaxRes");
[6054]903
904 maxResGPS = 0.0;
905 maxResGlo = 0.0;
906
907 QMapIterator<QString, t_satData*> it(satData);
908 while (it.hasNext()) {
909 it.next();
910 t_satData* satData = it.value();
911 if (satData->obsIndex != 0) {
912 QString prn = satData->prn;
913 if (prn[0] == 'R') {
914 if (fabs(vv(satData->obsIndex)) > maxResGlo) {
915 maxResGlo = fabs(vv(satData->obsIndex));
916 prnGlo = prn;
917 }
918 }
919 else {
920 if (fabs(vv(satData->obsIndex)) > maxResGPS) {
921 maxResGPS = fabs(vv(satData->obsIndex));
922 prnGPS = prn;
923 }
924 }
925 }
926 }
927}
928
929// Update Step (private - loop over outliers)
930////////////////////////////////////////////////////////////////////////////
[6093]931t_irc t_pppFilter::update_p(t_epoData* epoData) {
[6054]932
[6093]933 Tracer tracer("t_pppFilter::update_p");
[6054]934
935 // Save Variance-Covariance Matrix, and Status Vector
936 // --------------------------------------------------
937 rememberState(epoData);
938
939 QString lastOutlierPrn;
940
941 // Try with all satellites, then with all minus one, etc.
942 // ------------------------------------------------------
943 while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
944
945 QByteArray strResCode;
946 QByteArray strResPhase;
947
948 // Bancroft Solution
949 // -----------------
950 if (cmpBancroft(epoData) != success) {
951 break;
952 }
953
954 // First update using code observations, then phase observations
955 // -------------------------------------------------------------
[6100]956 bool usePhase = OPT->ambLCs('G').size() || OPT->ambLCs('R').size() ||
957 OPT->ambLCs('E').size();
[6063]958
959 for (int iPhase = 0; iPhase <= (usePhase ? 1 : 0); iPhase++) {
[6054]960
961 // Status Prediction
962 // -----------------
963 predict(iPhase, epoData);
964
965 // Create First-Design Matrix
966 // --------------------------
967 unsigned nPar = _params.size();
968 unsigned nObs = 0;
969 if (iPhase == 0) {
970 nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
971 }
972 else {
973 nObs = epoData->sizeAll();
974 }
975
976 // Prepare first-design Matrix, vector observed-computed
977 // -----------------------------------------------------
978 Matrix AA(nObs, nPar); // first design matrix
979 ColumnVector ll(nObs); // tems observed-computed
980 DiagonalMatrix PP(nObs); PP = 0.0;
981
982 unsigned iObs = 0;
983 QMapIterator<QString, t_satData*> it(epoData->satData);
984 while (it.hasNext()) {
985 it.next();
986 t_satData* satData = it.value();
987 if (iPhase == 1 || satData->system() != 'R') {
988 QString prn = satData->prn;
989 addObs(iPhase, iObs, satData, AA, ll, PP);
990 }
991 }
992
993 // Compute Filter Update
994 // ---------------------
995 ColumnVector dx;
996 kalman(AA, ll, PP, _QQ, dx);
997 ColumnVector vv = ll - AA * dx;
998
999 // Print Residuals
1000 // ---------------
1001 if (iPhase == 0) {
1002 strResCode = printRes(iPhase, vv, epoData->satData);
1003 }
1004 else {
1005 strResPhase = printRes(iPhase, vv, epoData->satData);
1006 }
1007
1008 // Check the residuals
1009 // -------------------
1010 lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
1011
1012 // No Outlier Detected
1013 // -------------------
1014 if (lastOutlierPrn.isEmpty()) {
1015
[6093]1016 QVectorIterator<t_pppParam*> itPar(_params);
[6054]1017 while (itPar.hasNext()) {
[6093]1018 t_pppParam* par = itPar.next();
[6054]1019 par->xx += dx(par->index);
1020 }
1021
[6063]1022 if (!usePhase || iPhase == 1) {
[6054]1023 if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
[6100]1024 LOG << "Neglected PRNs: ";
[6054]1025 if (!_outlierGPS.isEmpty()) {
[6100]1026 LOG << _outlierGPS.last().toAscii().data() << ' ';
[6054]1027 }
1028 QStringListIterator itGlo(_outlierGlo);
1029 while (itGlo.hasNext()) {
1030 QString prn = itGlo.next();
[6100]1031 LOG << prn.toAscii().data() << ' ';
[6054]1032 }
1033 }
[6106]1034 LOG << strResCode.data() << strResPhase.data();
[6054]1035
1036 return success;
1037 }
1038 }
1039
1040 // Outlier Found
1041 // -------------
1042 else {
1043 restoreState(epoData);
1044 break;
1045 }
1046
1047 } // for iPhase
1048
1049 } // while selectSatellites
1050
1051 restoreState(epoData);
1052 return failure;
1053}
1054
1055// Remeber Original State Vector and Variance-Covariance Matrix
1056////////////////////////////////////////////////////////////////////////////
[6093]1057void t_pppFilter::rememberState(t_epoData* epoData) {
[6054]1058
1059 _QQ_sav = _QQ;
1060
[6093]1061 QVectorIterator<t_pppParam*> itSav(_params_sav);
[6054]1062 while (itSav.hasNext()) {
[6093]1063 t_pppParam* par = itSav.next();
[6054]1064 delete par;
1065 }
1066 _params_sav.clear();
1067
[6093]1068 QVectorIterator<t_pppParam*> it(_params);
[6054]1069 while (it.hasNext()) {
[6093]1070 t_pppParam* par = it.next();
1071 _params_sav.push_back(new t_pppParam(*par));
[6054]1072 }
1073
1074 _epoData_sav->deepCopy(epoData);
1075}
1076
1077// Restore Original State Vector and Variance-Covariance Matrix
1078////////////////////////////////////////////////////////////////////////////
[6093]1079void t_pppFilter::restoreState(t_epoData* epoData) {
[6054]1080
1081 _QQ = _QQ_sav;
1082
[6093]1083 QVectorIterator<t_pppParam*> it(_params);
[6054]1084 while (it.hasNext()) {
[6093]1085 t_pppParam* par = it.next();
[6054]1086 delete par;
1087 }
1088 _params.clear();
1089
[6093]1090 QVectorIterator<t_pppParam*> itSav(_params_sav);
[6054]1091 while (itSav.hasNext()) {
[6093]1092 t_pppParam* par = itSav.next();
1093 _params.push_back(new t_pppParam(*par));
[6054]1094 }
1095
1096 epoData->deepCopy(_epoData_sav);
1097}
1098
1099//
1100////////////////////////////////////////////////////////////////////////////
[6093]1101t_irc t_pppFilter::selectSatellites(const QString& lastOutlierPrn,
[6054]1102 QMap<QString, t_satData*>& satData) {
1103
1104 // First Call
1105 // ----------
1106 if (lastOutlierPrn.isEmpty()) {
1107 _outlierGPS.clear();
1108 _outlierGlo.clear();
1109 return success;
1110 }
1111
1112 // Second and next trials
1113 // ----------------------
1114 else {
1115
1116 if (lastOutlierPrn[0] == 'R') {
1117 _outlierGlo << lastOutlierPrn;
1118 }
1119
1120 // Remove all Glonass Outliers
1121 // ---------------------------
1122 QStringListIterator it(_outlierGlo);
1123 while (it.hasNext()) {
1124 QString prn = it.next();
1125 if (satData.contains(prn)) {
1126 delete satData.take(prn);
1127 }
1128 }
1129
1130 if (lastOutlierPrn[0] == 'R') {
1131 _outlierGPS.clear();
1132 return success;
1133 }
1134
1135 // GPS Outlier appeared for the first time - try to delete it
1136 // ----------------------------------------------------------
1137 if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
1138 _outlierGPS << lastOutlierPrn;
1139 if (satData.contains(lastOutlierPrn)) {
1140 delete satData.take(lastOutlierPrn);
1141 }
1142 return success;
1143 }
1144
1145 }
1146
1147 return failure;
1148}
[6089]1149
1150//
1151////////////////////////////////////////////////////////////////////////////
1152double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
1153 return aa(1)*bb(1) + aa(2)*bb(2) + aa(3)*bb(3) - aa(4)*bb(4);
1154}
1155
1156//
1157////////////////////////////////////////////////////////////////////////////
[6093]1158void t_pppFilter::bancroft(const Matrix& BBpass, ColumnVector& pos) {
[6089]1159
1160 if (pos.Nrows() != 4) {
1161 pos.ReSize(4);
1162 }
1163 pos = 0.0;
1164
1165 for (int iter = 1; iter <= 2; iter++) {
1166 Matrix BB = BBpass;
1167 int mm = BB.Nrows();
1168 for (int ii = 1; ii <= mm; ii++) {
1169 double xx = BB(ii,1);
1170 double yy = BB(ii,2);
1171 double traveltime = 0.072;
1172 if (iter > 1) {
1173 double zz = BB(ii,3);
1174 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
1175 (yy-pos(2)) * (yy-pos(2)) +
1176 (zz-pos(3)) * (zz-pos(3)) );
1177 traveltime = rho / t_CST::c;
1178 }
1179 double angle = traveltime * t_CST::omega;
1180 double cosa = cos(angle);
1181 double sina = sin(angle);
1182 BB(ii,1) = cosa * xx + sina * yy;
1183 BB(ii,2) = -sina * xx + cosa * yy;
1184 }
1185
1186 Matrix BBB;
1187 if (mm > 4) {
1188 SymmetricMatrix hlp; hlp << BB.t() * BB;
1189 BBB = hlp.i() * BB.t();
1190 }
1191 else {
1192 BBB = BB.i();
1193 }
1194 ColumnVector ee(mm); ee = 1.0;
1195 ColumnVector alpha(mm); alpha = 0.0;
1196 for (int ii = 1; ii <= mm; ii++) {
1197 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
1198 }
1199 ColumnVector BBBe = BBB * ee;
1200 ColumnVector BBBalpha = BBB * alpha;
1201 double aa = lorentz(BBBe, BBBe);
1202 double bb = lorentz(BBBe, BBBalpha)-1;
1203 double cc = lorentz(BBBalpha, BBBalpha);
1204 double root = sqrt(bb*bb-aa*cc);
1205
1206 Matrix hlpPos(4,2);
1207 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
1208 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
1209
1210 ColumnVector omc(2);
1211 for (int pp = 1; pp <= 2; pp++) {
1212 hlpPos(4,pp) = -hlpPos(4,pp);
1213 omc(pp) = BB(1,4) -
1214 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
1215 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
1216 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
1217 hlpPos(4,pp);
1218 }
1219 if ( fabs(omc(1)) > fabs(omc(2)) ) {
1220 pos = hlpPos.Column(2);
1221 }
1222 else {
1223 pos = hlpPos.Column(1);
1224 }
1225 }
1226}
1227
[6111]1228//
1229////////////////////////////////////////////////////////////////////////////
1230void t_pppFilter::cmpDOP(t_epoData* epoData) {
1231
1232 Tracer tracer("t_pppFilter::cmpDOP");
1233
1234 _numSat = 0;
1235 _pDop = 0.0;
1236
1237 if (_params.size() < 4) {
1238 return;
1239 }
1240
1241 const unsigned numPar = 4;
1242 Matrix AA(epoData->sizeAll(), numPar);
1243 QMapIterator<QString, t_satData*> it(epoData->satData);
1244 while (it.hasNext()) {
1245 it.next();
1246 t_satData* satData = it.value();
1247 _numSat += 1;
1248 for (unsigned iPar = 0; iPar < numPar; iPar++) {
1249 AA[_numSat-1][iPar] = _params[iPar]->partial(satData, false);
1250 }
1251 }
1252 if (_numSat < 4) {
1253 return;
1254 }
1255 AA = AA.Rows(1, _numSat);
1256 SymmetricMatrix NN; NN << AA.t() * AA;
1257 SymmetricMatrix QQ = NN.i();
1258
1259 _pDop = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
1260}
Note: See TracBrowser for help on using the repository browser.