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

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