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

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