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