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