source: ntrip/trunk/BNC/src/PPP/pppFilter.cpp@ 9992

Last change on this file since 9992 was 9992, checked in by stuerze, 14 months ago

minor changes

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 27.7 KB
RevLine 
[7237]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppFilter
6 *
7 * Purpose: Filter Adjustment
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
[7267]13 * Changes:
[7237]14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <iomanip>
19#include <cmath>
20#include <newmat.h>
21#include <newmatio.h>
22#include <newmatap.h>
23
24#include "pppFilter.h"
25#include "bncutils.h"
26#include "pppParlist.h"
27#include "pppObsPool.h"
28#include "pppStation.h"
29
30using namespace BNC_PPP;
31using namespace std;
32
33// Constructor
34////////////////////////////////////////////////////////////////////////////
[9642]35t_pppFilter::t_pppFilter(t_pppObsPool *obsPool) {
[8905]36 _numSat = 0;
37 _obsPool = obsPool;
[9642]38 _refPrn = t_prn();
[8915]39 _datumTrafo = new t_datumTrafo();
[7237]40}
41
42// Destructor
43////////////////////////////////////////////////////////////////////////////
44t_pppFilter::~t_pppFilter() {
[8915]45 delete _datumTrafo;
[7237]46}
47
48// Process Single Epoch
49////////////////////////////////////////////////////////////////////////////
[9386]50t_irc t_pppFilter::processEpoch() {
[9642]51 _numSat = 0;
[7302]52 const double maxSolGap = 60.0;
[7237]53
54 // Vector of all Observations
55 // --------------------------
[9642]56 t_pppObsPool::t_epoch *epoch = _obsPool->lastEpoch();
[7237]57 if (!epoch) {
58 return failure;
59 }
[9642]60 vector<t_pppSatObs*> &allObs = epoch->obsVector();
[7237]61
62 // Time of the Epoch
63 // -----------------
64 _epoTime = epoch->epoTime();
65
[9642]66 if (!_firstEpoTime.valid() || !_lastEpoTimeOK.valid()
67 || (maxSolGap > 0.0 && _epoTime - _lastEpoTimeOK > maxSolGap)) {
[7237]68 _firstEpoTime = _epoTime;
69 }
70
[7267]71 string epoTimeStr = string(_epoTime);
72
[9642]73 const QMap<char, t_pppRefSat*> &refSatMap = epoch->refSatMap();
[9532]74
[8905]75 //--
[7237]76 // Set Parameters
[9508]77 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]78 return failure;
79 }
[9526]80
[9527]81 if (OPT->_obsModelType == OPT->DCMcodeBias ||
[9642]82 OPT->_obsModelType == OPT->DCMphaseBias) {
[9386]83#ifdef BNC_DEBUG_PPP
[9534]84 _parlist.printParams(_epoTime);
[9386]85#endif
[9527]86 }
[7237]87 // Status Vector, Variance-Covariance Matrix
88 // -----------------------------------------
[9642]89 ColumnVector xFltOld = _xFlt;
[7237]90 SymmetricMatrix QFltOld = _QFlt;
[9526]91 setStateVectorAndVarCovMatrix(xFltOld, QFltOld);
[8956]92
[8905]93 // Pre-Process Satellite Systems separately
94 // ----------------------------------------
95 bool preProcessing = false;
96 if (OPT->_obsModelType == OPT->DCMcodeBias ||
[9642]97 OPT->_obsModelType == OPT->DCMphaseBias) {
[8905]98 preProcessing = true;
[9642]99 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]100 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
101 char sys = usedSystems[iSys];
[9526]102 _refPrn.set(sys, 0);
103 if (OPT->_refSatRequired) {
104 _refPrn = refSatMap[sys]->prn();
105 }
[9642]106 vector<t_pppSatObs*> obsVector;
[8905]107 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9386]108 if (allObs[jj]->prn().system() == sys) {
[8905]109 obsVector.push_back(allObs[jj]);
110 }
111 }
[9431]112 if (iSys == 0) {
113 _datumTrafo->setFirstSystem(sys);
[9419]114 }
[9386]115 if (processSystem(OPT->LCs(sys), obsVector, _refPrn,
[9642]116 epoch->pseudoObsIono(), preProcessing) != success) {
[9583]117 LOG << sys << ": processSystem != success (pre-processing)" << endl;
[9386]118 _xFlt = xFltOld;
119 _QFlt = QFltOld;
[9532]120 _obsPool->deleteLastEpoch();
[9527]121 restoreState(2);
[8905]122 return failure;
123 }
124 }
[8956]125 // refSat change required?
126 // -----------------------
127 if (_obsPool->refSatChangeRequired()) {
128 _xFlt = xFltOld;
129 _QFlt = QFltOld;
130 return success;
[9642]131 } else if (!_obsPool->refSatChangeRequired()) {
[9419]132 initDatumTransformation(allObs, epoch->pseudoObsIono());
[8956]133 }
[8905]134 }
135
[7237]136 // Process Satellite Systems separately
137 // ------------------------------------
[8912]138 preProcessing = false;
[9642]139 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]140 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
141 char sys = usedSystems[iSys];
[9526]142 _refPrn.set(sys, 0);
[8910]143 if (OPT->_refSatRequired) {
[9508]144 _refPrn = refSatMap[sys]->prn();
[8910]145 }
[7267]146 unsigned int num = 0;
[7237]147 vector<t_pppSatObs*> obsVector;
148 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]149 if (allObs[jj]->prn().system() == sys) {
[7237]150 obsVector.push_back(allObs[jj]);
[9419]151 ++num;
[7237]152 }
153 }
[9431]154 if (iSys == 0 && OPT->_obsModelType == OPT->UncombPPP) {
155 _datumTrafo->setFirstSystem(sys);
[9419]156 }
[9642]157 LOG << epoTimeStr << " SATNUM " << sys << ' ' << right << setw(2) << num
158 << endl;
159 if (processSystem(OPT->LCs(sys), obsVector, _refPrn, epoch->pseudoObsIono(),
160 preProcessing) != success) {
[9537]161 LOG << "processSystem != success (fin-processing)" << endl;
162 if (OPT->_obsModelType == OPT->DCMcodeBias ||
[9699]163 OPT->_obsModelType == OPT->DCMphaseBias) {
[9590]164 _xFlt = xFltOld;
165 _QFlt = QFltOld;
[9537]166 _obsPool->deleteLastEpoch();
167 restoreState(3);
168 }
[7237]169 return failure;
170 }
171 }
[8912]172
173 // close epoch processing
174 // ----------------------
[9508]175 cmpDOP(allObs, refSatMap);
[9504]176 _parlist.printResult(_epoTime, _QFlt, _xFlt);
[9642]177 _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
[7237]178 return success;
179}
180
181// Process Selected LCs
182////////////////////////////////////////////////////////////////////////////
[9642]183t_irc t_pppFilter::processSystem(const vector<t_lc::type> &LCs,
184 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
185 bool pseudoObsIonoAvailable, bool preProcessing) {
[7237]186 LOG.setf(ios::fixed);
[9386]187 char sys = refPrn.system();
[7237]188
189 // Detect Cycle Slips
190 // ------------------
[8905]191 if (detectCycleSlips(LCs, obsVector, refPrn, preProcessing) != success) {
[7237]192 return failure;
193 }
[9398]194 if (preProcessing && _obsPool->refSatChangeRequired(sys)) {
[9386]195 return success;
196 }
[7237]197
[9642]198 ColumnVector xSav = _xFlt;
199 SymmetricMatrix QSav = _QFlt;
200 string epoTimeStr = string(_epoTime);
201 const vector<t_pppParam*> &params = _parlist.params();
[9524]202 unsigned nPar = _parlist.nPar();
[8965]203
[9642]204 unsigned usedLCs = LCs.size();
[8965]205 if (OPT->_pseudoObsIono && !pseudoObsIonoAvailable) {
[9642]206 usedLCs -= 1; // GIM not used
[8961]207 }
208 // max Obs
[9538]209 unsigned maxObs = obsVector.size() * usedLCs;
210
[8965]211 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
212 maxObs -= 1; // pseudo obs iono with respect to refSat
[8905]213 }
214
[7237]215 // Outlier Detection Loop
216 // ----------------------
217 for (unsigned iOutlier = 0; iOutlier < maxObs; iOutlier++) {
218
219 if (iOutlier > 0) {
220 _xFlt = xSav;
221 _QFlt = QSav;
222 }
223
224 // First-Design Matrix, Terms Observed-Computed, Weight Matrix
225 // -----------------------------------------------------------
[9642]226 Matrix AA(maxObs, nPar);
227 ColumnVector ll(maxObs);
228 DiagonalMatrix PP(maxObs);
229 PP = 0.0;
[8912]230
[7237]231 int iObs = -1;
232 vector<t_pppSatObs*> usedObs;
[9642]233 vector<t_lc::type> usedTypes;
[9386]234
235 // Real Observations
236 // =================
[9583]237 double nSat = 0;
[7237]238 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]239 t_pppSatObs *obs = obsVector[ii];
[9419]240 if (iOutlier == 0 && !preProcessing) {
241 obs->resetOutlier();
242 }
[7237]243 if (!obs->outlier()) {
[9583]244 nSat++;
[8905]245 for (unsigned jj = 0; jj < usedLCs; jj++) {
[7237]246 const t_lc::type tLC = LCs[jj];
[9642]247 if (tLC == t_lc::GIM) {
248 continue;
249 }
[7237]250 ++iObs;
251 usedObs.push_back(obs);
252 usedTypes.push_back(tLC);
[9524]253 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9642]254 const t_pppParam *par = params[iPar];
[8956]255 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[7237]256 }
[9642]257 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
[9967]258 - DotProduct(_x0, AA.Row(iObs + 1));
[7237]259 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
260 }
261 }
262 }
263
[9556]264 // Check number of observations
265 // ----------------------------
[9701]266 if (iObs == -1) {
[9992]267 LOG << " number of observations == " << iObs + 1 << "\n";
[9701]268 return failure;
[9699]269 }
[9625]270
[9967]271 if ((!iOutlier) &&
272 (OPT->_obsModelType == OPT->DCMcodeBias ||
273 OPT->_obsModelType == OPT->DCMphaseBias) && (!preProcessing)) {
[9642]274 _datumTrafo->updateIndices(sys, iObs + 1);
275 _datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, _parlist.nPar()), 1);
[9386]276 }
277
278 // Pseudo Obs Iono
279 // ================
280 if (OPT->_pseudoObsIono && pseudoObsIonoAvailable) {
281 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]282 t_pppSatObs *obs = obsVector[ii];
[9386]283 if (!obs->outlier()) {
284 for (unsigned jj = 0; jj < usedLCs; jj++) {
285 const t_lc::type tLC = LCs[jj];
286 if (tLC == t_lc::GIM && !obs->isReference()) {
287 ++iObs;
[9642]288 } else {
289 continue;
290 }
[9386]291 usedObs.push_back(obs);
292 usedTypes.push_back(tLC);
[9524]293 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9642]294 const t_pppParam *par = params[iPar];
[9386]295 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
296 }
[9642]297 ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC)
[9967]298 - DotProduct(_x0, AA.Row(iObs + 1));
[9386]299 PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
300 }
301 }
[8956]302 }
[8915]303 }
304
[9556]305 // Truncate matrices
306 // -----------------
[9642]307 AA = AA.Rows(1, iObs + 1);
308 ll = ll.Rows(1, iObs + 1);
309 PP = PP.SymSubMatrix(1, iObs + 1);
[7237]310
311 // Kalman update step
312 // ------------------
313 kalman(AA, ll, PP, _QFlt, _xFlt);
314
315 // Check Residuals
316 // ---------------
317 ColumnVector vv = AA * _xFlt - ll;
[9642]318 double maxOutlier = 0.0;
319 int maxOutlierIndex = -1;
320 t_lc::type maxOutlierLC = t_lc::dummy;
[7237]321 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
322 const t_lc::type tLC = usedTypes[ii];
323 double res = fabs(vv[ii]);
324 if (res > usedObs[ii]->maxRes(tLC)) {
325 if (res > fabs(maxOutlier)) {
[9642]326 maxOutlier = vv[ii];
[7237]327 maxOutlierIndex = ii;
[9642]328 maxOutlierLC = tLC;
[7237]329 }
330 }
331 }
332
333 // Mark outlier or break outlier detection loop
334 // --------------------------------------------
335 if (maxOutlierIndex > -1) {
[9642]336 t_pppSatObs *obs = usedObs[maxOutlierIndex];
337 t_pppParam *par = 0;
[9524]338 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9642]339 t_pppParam *hlp = params[iPar];
340 if (hlp->type() == t_pppParam::amb && hlp->prn() == obs->prn()
341 && hlp->tLC() == usedTypes[maxOutlierIndex]) {
[7237]342 par = hlp;
343 }
344 }
[8956]345 if (preProcessing) {
[9982]346 // for refSats no ambiguity parameter exists
[9642]347 if ((obs->prn() == refPrn)
[9699]348 && (t_lc::toString(maxOutlierLC) == "l1" ||
349 t_lc::toString(maxOutlierLC) == "l2")) {
[9642]350 _obsPool->setRefSatChangeRequired(sys, true);
351 LOG << epoTimeStr << " Outlier ("
352 << ((preProcessing) ? "pre-processing) " : "fin-processing) ")
353 << t_lc::toString(maxOutlierLC) << ' ' << obs->prn().toString()
354 << ' ' << setw(8) << setprecision(4) << maxOutlier << endl;
355 break;
[9982]356 } else {
357 obs->setOutlier();
358 }
[9642]359 } else { // fin-processing
[9556]360 LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
[9642]361 << obs->prn().toString() << ' ' << setw(8) << setprecision(4)
362 << maxOutlier << endl;
[8956]363 if (par) {
[9982]364 //if ( par->ambResetCandidate() || (OPT->_obsModelType == OPT->DCMcodeBias || OPT->_obsModelType == OPT->DCMphaseBias) ) {
365 resetAmb(par->prn(), obsVector, &QSav, &xSav);
366 //}
367 //else {
368 // par->setAmbResetCandidate();
369 // obs->setOutlier();
370 //}
[9704]371 }
[9703]372 else {
[7237]373 obs->setOutlier();
374 }
375 }
376 }
377 // Print Residuals
378 // ---------------
379 else {
[8905]380 if (!preProcessing) {
381 for (unsigned jj = 0; jj < LCs.size(); jj++) {
382 for (unsigned ii = 0; ii < usedObs.size(); ii++) {
383 const t_lc::type tLC = usedTypes[ii];
[9642]384 t_pppSatObs *obs = usedObs[ii];
[8905]385 if (tLC == LCs[jj]) {
386 obs->setRes(tLC, vv[ii]);
[9642]387 LOG << epoTimeStr << " RES " << left << setw(3)
[9699]388 << t_lc::toString(tLC) << right << ' '
389 << obs->prn().toString();
[9435]390 LOG << setw(9) << setprecision(4) << vv[ii] << endl;
[8905]391 }
[7237]392 }
393 }
394 }
395 break;
396 }
397 }
398 return success;
399}
400
401// Cycle-Slip Detection
402////////////////////////////////////////////////////////////////////////////
[9642]403t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type> &LCs,
404 const vector<t_pppSatObs*> &obsVector, const t_prn &refPrn,
405 bool preProcessing) {
[9972]406 const double SLIP = 100.0;
[9386]407 char sys = refPrn.system();
408 string epoTimeStr = string(_epoTime);
[9642]409 const vector<t_pppParam*> &params = _parlist.params();
[9524]410 unsigned nPar = _parlist.nPar();
[7237]411
412 for (unsigned ii = 0; ii < LCs.size(); ii++) {
[9642]413 const t_lc::type &tLC = LCs[ii];
[7237]414 if (t_lc::includesPhase(tLC)) {
415 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
[9642]416 const t_pppSatObs *obs = obsVector[iObs];
[7237]417
[7267]418 // Check set Slips and Jump Counters
[7237]419 // ---------------------------------
420 bool slip = false;
[9386]421
422 // in pre-processing only the reference satellite has to be checked
423 if (preProcessing && obs->prn() != refPrn) {
424 continue;
425 }
426
[7237]427 if (obs->slip()) {
[9642]428 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString()
429 << endl;
[7237]430 slip = true;
431 }
432
[9642]433 if (_slips[obs->prn()]._obsSlipCounter != -1
434 && _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
435 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) "
436 << obs->prn().toString() << endl;
[7237]437 slip = true;
438 }
[8956]439 if (!preProcessing) {
440 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
441 }
[9642]442 if (_slips[obs->prn()]._biasJumpCounter != -1
443 && _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
444 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) "
445 << obs->prn().toString() << endl;
[7237]446 slip = true;
447 }
[8956]448 if (!preProcessing) {
449 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
450 }
[7237]451 // Slip Set
[7267]452 // --------
[7237]453 if (slip) {
[8905]454 if (preProcessing) {
[9386]455 _obsPool->setRefSatChangeRequired(sys, true);
[9642]456 } else {
[8905]457 resetAmb(obs->prn(), obsVector);
458 }
[7237]459 }
[9992]460 /* Check Pre-Fit Residuals
[9982]461 // -----------------------
[7237]462 else {
[9982]463 if (refPrn != t_prn()) {
464 return success;
465 }
466 ColumnVector AA(nPar);
467 for (unsigned iPar = 0; iPar < nPar; iPar++) {
468 const t_pppParam *par = params[iPar];
469 AA[iPar] = par->partial(_epoTime, obs, tLC, refPrn);
470 }
471 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC)
472 - DotProduct(_x0, AA);
473 double vv = DotProduct(AA, _xFlt) - ll;
474 if (fabs(vv) > SLIP) {
475 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC)
476 << ' ' << obs->prn().toString() << ' ' << setw(8)
477 << setprecision(4) << vv << endl;
478 if (preProcessing) {
[9386]479 _obsPool->setRefSatChangeRequired(sys, true);
[9982]480 } else {
481 resetAmb(obs->prn(), obsVector);
[8905]482 }
[7237]483 }
[9992]484 }*/
[7237]485 }
486 }
487 }
488 return success;
489}
490
491// Reset Ambiguity Parameter (cycle slip)
492////////////////////////////////////////////////////////////////////////////
[9642]493t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*> &obsVector,
494 SymmetricMatrix *QSav, ColumnVector *xSav) {
[8965]495
[7237]496 t_irc irc = failure;
[9642]497 vector<t_pppParam*> &params = _parlist.params();
[7237]498 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
[9642]499 t_pppParam *par = params[iPar];
[7237]500 if (par->type() == t_pppParam::amb && par->prn() == prn) {
501 int ind = par->indexNew();
502 t_lc::type tLC = par->tLC();
503 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
[9642]504 delete par;
505 par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
[7237]506 par->setIndex(ind);
507 params[iPar] = par;
508 for (unsigned ii = 1; ii <= params.size(); ii++) {
[9642]509 _QFlt(ii, ind + 1) = 0.0;
[7237]510 if (QSav) {
[9642]511 (*QSav)(ii, ind + 1) = 0.0;
[7237]512 }
513 }
[9642]514 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
[7237]515 if (QSav) {
[9642]516 (*QSav)(ind + 1, ind + 1) = _QFlt(ind + 1, ind + 1);
[7237]517 }
518 _xFlt[ind] = 0.0;
519 if (xSav) {
520 (*xSav)[ind] = _xFlt[ind];
521 }
522 _x0[ind] = par->x0();
523 irc = success;
524 }
525 }
526
527 return irc;
528}
529
[9395]530// Add infinite noise to iono
[9386]531////////////////////////////////////////////////////////////////////////////
[9642]532t_irc t_pppFilter::addNoiseToPar(t_pppParam::e_type parType, char sys) {
[9386]533 t_irc irc = failure;
[9642]534 vector<t_pppParam*> &params = _parlist.params();
[9386]535 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
[9642]536 t_pppParam *par = params[iPar];
537 if (par->type() == parType && par->prn().system() == sys) {
[9386]538 int ind = par->indexNew();
[9659]539 LOG << string(_epoTime) << " ADD NOISE TO " << par->toString() << endl;
[9386]540 par->setIndex(ind);
[9642]541 _QFlt(ind + 1, ind + 1) = par->sigma0() * par->sigma0();
[9386]542 irc = success;
543 }
544 }
545
546 return irc;
547}
548
[7237]549// Compute various DOP Values
550////////////////////////////////////////////////////////////////////////////
[9642]551void t_pppFilter::cmpDOP(const vector<t_pppSatObs*> &obsVector,
552 const QMap<char, t_pppRefSat*> &refSatMap) {
[7237]553
554 _dop.reset();
555
556 try {
557 const unsigned numPar = 4;
558 Matrix AA(obsVector.size(), numPar);
559 _numSat = 0;
560 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]561 t_pppSatObs *obs = obsVector[ii];
[9508]562 char sys = obs->prn().system();
[8956]563 t_prn refPrn = t_prn();
564 if (OPT->_refSatRequired) {
[9508]565 refPrn = refSatMap[sys]->prn();
[8956]566 }
[7237]567 if (obs->isValid() && !obs->outlier()) {
568 ++_numSat;
569 for (unsigned iPar = 0; iPar < numPar; iPar++) {
[9642]570 const t_pppParam *par = _parlist.params()[iPar];
571 AA[_numSat - 1][iPar] = par->partial(_epoTime, obs, t_lc::c1, refPrn);
[7237]572 }
573 }
574 }
575 if (_numSat < 4) {
576 return;
577 }
578 AA = AA.Rows(1, _numSat);
[9642]579 SymmetricMatrix NN;
580 NN << AA.t() * AA;
[7237]581 SymmetricMatrix QQ = NN.i();
[7267]582
[9642]583 _dop.H = sqrt(QQ(1, 1) + QQ(2, 2));
584 _dop.V = sqrt(QQ(3, 3));
585 _dop.P = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3));
586 _dop.T = sqrt(QQ(4, 4));
587 _dop.G = sqrt(QQ(1, 1) + QQ(2, 2) + QQ(3, 3) + QQ(4, 4));
588 } catch (...) {
[7237]589 }
590}
591
[9526]592//
[7237]593////////////////////////////////////////////////////////////////////////////
[9642]594void t_pppFilter::predictCovCrdPart(const SymmetricMatrix &QFltOld) {
[7237]595
[9642]596 const vector<t_pppParam*> &params = _parlist.params();
[7237]597 if (params.size() < 3) {
598 return;
599 }
600
601 bool first = (params[0]->indexOld() < 0);
602
[9642]603 SymmetricMatrix Qneu(3);
604 Qneu = 0.0;
[7237]605 for (unsigned ii = 0; ii < 3; ii++) {
[9642]606 const t_pppParam *par = params[ii];
[7237]607 if (first) {
608 Qneu[ii][ii] = par->sigma0() * par->sigma0();
[9642]609 } else {
[7237]610 Qneu[ii][ii] = par->noise() * par->noise();
611 }
612 }
613
[9642]614 const t_pppStation *sta = PPP_CLIENT->staRover();
[7237]615 SymmetricMatrix Qxyz(3);
616 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
617
618 if (first) {
[9642]619 _QFlt.SymSubMatrix(1, 3) = Qxyz;
620 } else {
[7237]621 double dt = _epoTime - _firstEpoTime;
622 if (dt < OPT->_seedingTime) {
[9642]623 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3);
624 } else {
625 _QFlt.SymSubMatrix(1, 3) = QFltOld.SymSubMatrix(1, 3) + Qxyz;
[7237]626 }
627 }
628}
[8912]629
[9526]630//
631////////////////////////////////////////////////////////////////////////////
[9642]632void t_pppFilter::setStateVectorAndVarCovMatrix(const ColumnVector &xFltOld,
633 const SymmetricMatrix &QFltOld) {
[9526]634
[9642]635 const vector<t_pppParam*> &params = _parlist.params();
[9526]636 unsigned nPar = params.size();
637
[9642]638 _QFlt.ReSize(nPar);
639 _QFlt = 0.0;
640 _xFlt.ReSize(nPar);
641 _xFlt = 0.0;
642 _x0.ReSize(nPar);
643 _x0 = 0.0;
[9526]644
645 for (unsigned ii = 0; ii < nPar; ii++) {
[9642]646 t_pppParam *par1 = params[ii];
[9526]647 if (QFltOld.size() == 0) {
648 par1->resetIndex();
649 }
650 _x0[ii] = par1->x0();
651 int iOld = par1->indexOld();
652 if (iOld < 0) {
653 _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
[9642]654 } else {
[9526]655 _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
[9642]656 _xFlt[ii] = xFltOld[iOld];
[9526]657 for (unsigned jj = 0; jj < ii; jj++) {
[9642]658 t_pppParam *par2 = params[jj];
659 int jOld = par2->indexOld();
[9526]660 if (jOld >= 0) {
[9642]661 _QFlt[ii][jj] = QFltOld(iOld + 1, jOld + 1);
[9526]662 }
663 }
664 }
665 }
666 predictCovCrdPart(QFltOld);
667}
668
[8915]669// Compute datum transformation
[8912]670////////////////////////////////////////////////////////////////////////////
[9642]671t_irc t_pppFilter::datumTransformation(
672 const QMap<char, t_pppRefSat*> &refSatMap) {
[9508]673
[9419]674 // get last epoch
[9642]675 t_pppObsPool::t_epoch *epoch = _obsPool->lastEpoch();
[9419]676 if (!epoch) {
[9508]677 LOG << "t_pppFilter::datumTransformation: !lastEpoch" << endl;
[9386]678 return failure;
679 }
[9508]680 _epoTime = epoch->epoTime();
681 LOG.setf(ios::fixed);
682 LOG << string(_epoTime) << " DATUM TRANSFORMATION " << endl;
[9419]683
[9642]684 vector<t_pppSatObs*> &allObs = epoch->obsVector();
[9386]685
[9642]686 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch = epoch->refSatMap();
[9508]687
[9548]688 bool pseudoObsIono = epoch->pseudoObsIono();
[9508]689
[9419]690 // reset old and set new refSats in last epoch (ambiguities/GIM)
691 // =============================================================
[9642]692 if (resetRefSatellitesLastEpoch(allObs, refSatMap, refSatMapLastEpoch)
693 != true) {
694 LOG << "datumTransformation: resetRefSatellitesLastEpoch != success"
695 << endl;
[9548]696 return failure;
[9386]697 }
698
[9419]699 if (OPT->_obsModelType == OPT->UncombPPP) {
[9548]700 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9419]701 return success;
702 }
703
[9386]704 // set AA2
705 // =======
[9508]706 if (_parlist.set(_epoTime, allObs, refSatMap) != success) {
[9419]707 return failure;
708 }
[9526]709
[9386]710#ifdef BNC_DEBUG_PPP
[9534]711 _parlist.printParams(_epoTime);
[9386]712#endif
[9526]713
[9642]714 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]715 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
716 char sys = usedSystems[iSys];
[9508]717 t_prn refPrn = refSatMap[sys]->prn();
[9386]718 vector<t_pppSatObs*> obsVector;
719 for (unsigned jj = 0; jj < allObs.size(); jj++) {
720 if (allObs[jj]->prn().system() == sys) {
[9618]721 allObs[jj]->resetOutlier();
[9386]722 obsVector.push_back(allObs[jj]);
723 }
724 }
[9431]725 if (iSys == 0) {
726 _datumTrafo->setFirstSystem(sys);
[9419]727 }
[9386]728 vector<t_lc::type> LCs = OPT->LCs(sys);
729 unsigned usedLCs = LCs.size();
[9548]730 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9642]731 usedLCs -= 1; // GIM not used
[9386]732 }
733 // max Obs
[9538]734 unsigned maxObs = obsVector.size() * usedLCs;
[9419]735
[9548]736 if (OPT->_pseudoObsIono && pseudoObsIono) {
[9386]737 maxObs -= 1; // pseudo obs iono with respect to refSat
738 }
[9526]739
[9642]740 const vector<t_pppParam*> &params = _parlist.params();
[9526]741 unsigned nPar = _parlist.nPar();
742
[9642]743 Matrix AA(maxObs, nPar);
[9524]744
[9386]745 // Real Observations
746 // -----------------
747 int iObs = -1;
748 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
[9642]749 t_pppSatObs *obs = obsVector[ii];
[9419]750 for (unsigned jj = 0; jj < usedLCs; jj++) {
751 const t_lc::type tLC = LCs[jj];
[9642]752 if (tLC == t_lc::GIM) {
753 continue;
754 }
[9419]755 ++iObs;
[9524]756 for (unsigned iPar = 0; iPar < nPar; iPar++) {
[9642]757 const t_pppParam *par = params[iPar];
[9419]758 AA[iObs][iPar] = par->partial(_epoTime, obs, tLC, refPrn);
[9386]759 }
760 }
761 }
[9538]762
[9419]763 if (!iObs) {
764 continue;
765 }
[9982]766 _datumTrafo->updateIndices(sys, iObs + 1); //LOG << "AA Ncols/Nrows: " << AA.Ncols() << "/" << AA.Nrows() << " nPar: " << nPar << endl; //LOG << "AA.SubMatrix(1 .. " << iObs+1 << " , 1 .. " << nPar << ")" << endl;
[9642]767 if (_datumTrafo->prepareAA(AA.SubMatrix(1, iObs + 1, 1, nPar), 2)
768 != success) {
[9508]769 return failure;
770 }
[9386]771 }
[9419]772 _datumTrafo->updateNumObs();
[9386]773
774 // Datum Transformation
775 // ====================
776#ifdef BNC_DEBUG_PPP
[9548]777 //LOG << "AA1\n"; _datumTrafo->printMatrix(_datumTrafo->AA1(), _datumTrafo->numObs(), _datumTrafo->numPar());
778 //LOG << "AA2\n"; _datumTrafo->printMatrix(_datumTrafo->AA2(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]779#endif
[9642]780 if (_datumTrafo->computeTrafoMatrix() != success) {
[9419]781 return failure;
782 }
[9386]783#ifdef BNC_DEBUG_PPP
[9548]784 //LOG << "D21" << endl; _datumTrafo->printMatrix(_datumTrafo->D21(), _datumTrafo->numObs(), _datumTrafo->numPar());
[9386]785#endif
[9642]786 ColumnVector xFltOld = _xFlt;
[9386]787 SymmetricMatrix QFltOld = _QFlt;
788
[9419]789 _QFlt << _datumTrafo->D21() * QFltOld * _datumTrafo->D21().t();
[9642]790 _xFlt = _datumTrafo->D21() * xFltOld;
[9386]791
[9579]792#ifdef BNC_DEBUG_PPP
[9562]793 LOG << "xFltOld:\n" << xFltOld << endl;
794 LOG << "xFlt :\n" << _xFlt << endl;
[9579]795#endif
[9386]796
797 // Reset Ambiguities after Datum Transformation
798 // ============================================
[9431]799 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
800 char sys = usedSystems[iSys];
[9508]801 t_prn refPrnOld = refSatMapLastEpoch[sys]->prn();
802 t_prn refPrnNew = refSatMap[sys]->prn();
[9419]803 if (refPrnNew != refPrnOld) {
[9670]804 resetAmb(refPrnOld, allObs);/*
[9642]805 if (resetAmb(refPrnOld, allObs) == success) {
806 if (OPT->_obsModelType == OPT->DCMcodeBias) {
807 addNoiseToPar(t_pppParam::ion, sys);
808 } else if (OPT->_obsModelType == OPT->DCMphaseBias) {
[9656]809 if (sys == 'G') {
[9642]810 addNoiseToPar(t_pppParam::pBiasG1, sys);
811 addNoiseToPar(t_pppParam::pBiasG2, sys);
812 } else if (sys == 'R') {
813 addNoiseToPar(t_pppParam::pBiasR1, sys);
814 addNoiseToPar(t_pppParam::pBiasR2, sys);
815 } else if (sys == 'E') {
816 addNoiseToPar(t_pppParam::pBiasE1, sys);
817 addNoiseToPar(t_pppParam::pBiasE2, sys);
818 } else if (sys == 'C') {
819 addNoiseToPar(t_pppParam::pBiasC1, sys);
820 addNoiseToPar(t_pppParam::pBiasC2, sys);
821 }
822 }
[9670]823 }*/
[9386]824 }
825 }
826
827 // switch AA2 to AA1
828 // =================
829 _datumTrafo->switchAA();
830
[9548]831 _obsPool->putEpoch(_epoTime, allObs, pseudoObsIono, refSatMap);
[9508]832
[9386]833 return success;
[8912]834}
835
[9386]836// Init datum transformation
[8956]837////////////////////////////////////////////////////////////////////////////
[9642]838void t_pppFilter::initDatumTransformation(
839 const std::vector<t_pppSatObs*> &allObs, bool pseudoObsIono) {
[9395]840 unsigned trafoObs = 0;
[9642]841 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]842 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
843 char sys = usedSystems[iSys];
[9386]844 int satNum = 0;
845 for (unsigned jj = 0; jj < allObs.size(); jj++) {
[9419]846 if (allObs[jj]->prn().system() == sys) {
[9386]847 satNum++;
[8956]848 }
849 }
[9386]850 // all LCs
[9419]851 unsigned realUsedLCs = OPT->LCs(sys).size();
[9386]852 // exclude pseudo obs GIM
[9419]853 if (OPT->_pseudoObsIono && !pseudoObsIono) {
[9386]854 realUsedLCs -= 1;
855 }
[9538]856
[9395]857 trafoObs += satNum * realUsedLCs;
858
[9419]859 if (OPT->_pseudoObsIono && pseudoObsIono) {
860 trafoObs -= 1; // pseudo obs iono with respect to refSat
861 }
[8956]862 }
[9419]863 _datumTrafo->setNumObs(trafoObs);
[9504]864 _datumTrafo->setNumPar(_parlist.nPar());
[9386]865 _datumTrafo->initAA();
[8956]866}
[9386]867
868//
869//////////////////////////////////////////////////////////////////////////////
[9642]870bool t_pppFilter::resetRefSatellitesLastEpoch(
871 std::vector<t_pppSatObs*> &obsVector,
872 const QMap<char, t_pppRefSat*> &refSatMap,
873 const QMap<char, t_pppRefSat*> &refSatMapLastEpoch) {
[9431]874 bool resetRefSat;
[9386]875 // reference satellite definition per system
[9642]876 const QList<char> &usedSystems = _parlist.usedSystems();
[9431]877 for (int iSys = 0; iSys < usedSystems.size(); iSys++) {
878 resetRefSat = false;
879 char sys = usedSystems[iSys];
[9508]880 t_prn newPrn = refSatMap[sys]->prn();
881 t_prn oldPrn = refSatMapLastEpoch[sys]->prn();
[9386]882#ifdef BNC_DEBUG_PPP
[9508]883 if (oldPrn != newPrn) {
884 LOG << "oldRef: " << oldPrn.toString() << " => newRef " << newPrn.toString() << endl;
885 }
[9386]886#endif
887 vector<t_pppSatObs*>::iterator it = obsVector.begin();
888 while (it != obsVector.end()) {
[9642]889 t_pppSatObs *satObs = *it;
890 if (satObs->prn() == newPrn) {
[9386]891 resetRefSat = true;
892 satObs->setAsReference();
[9508]893 } else if (satObs->prn() == oldPrn) {
[9386]894 satObs->resetReference();
895 }
[9642]896 it++;
[9386]897 }
[9431]898 if (!resetRefSat) {
899 _obsPool->setRefSatChangeRequired(sys, true);
900 return resetRefSat;
901 }
[9386]902 }
903 return resetRefSat;
904}
Note: See TracBrowser for help on using the repository browser.