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 | #include "pppClient.h"
|
---|
30 |
|
---|
31 | using namespace BNC_PPP;
|
---|
32 | using namespace std;
|
---|
33 |
|
---|
34 | // Constructor
|
---|
35 | ////////////////////////////////////////////////////////////////////////////
|
---|
36 | t_pppFilter::t_pppFilter() {
|
---|
37 | _parlist = 0;
|
---|
38 | }
|
---|
39 |
|
---|
40 | // Destructor
|
---|
41 | ////////////////////////////////////////////////////////////////////////////
|
---|
42 | t_pppFilter::~t_pppFilter() {
|
---|
43 | delete _parlist;
|
---|
44 | }
|
---|
45 |
|
---|
46 | // Process Single Epoch
|
---|
47 | ////////////////////////////////////////////////////////////////////////////
|
---|
48 | t_irc t_pppFilter::processEpoch(t_pppObsPool* obsPool) {
|
---|
49 |
|
---|
50 | _numSat = 0;
|
---|
51 | const double maxSolGap = 60.0;
|
---|
52 |
|
---|
53 | if (!_parlist) {
|
---|
54 | _parlist = new t_pppParlist();
|
---|
55 | }
|
---|
56 |
|
---|
57 | // Vector of all Observations
|
---|
58 | // --------------------------
|
---|
59 | t_pppObsPool::t_epoch* epoch = obsPool->lastEpoch();
|
---|
60 | if (!epoch) {
|
---|
61 | return failure;
|
---|
62 | }
|
---|
63 | vector<t_pppSatObs*>& allObs = epoch->obsVector();
|
---|
64 |
|
---|
65 | // Time of the Epoch
|
---|
66 | // -----------------
|
---|
67 | _epoTime = epoch->epoTime();
|
---|
68 |
|
---|
69 | if (!_firstEpoTime.valid() ||
|
---|
70 | !_lastEpoTimeOK.valid() ||
|
---|
71 | (maxSolGap > 0.0 && _epoTime - _lastEpoTimeOK > maxSolGap)) {
|
---|
72 | _firstEpoTime = _epoTime;
|
---|
73 | }
|
---|
74 |
|
---|
75 | string epoTimeStr = string(_epoTime);
|
---|
76 |
|
---|
77 | // Set Parameters
|
---|
78 | // --------------
|
---|
79 | _parlist->set(_epoTime, allObs);
|
---|
80 | const vector<t_pppParam*>& params = _parlist->params();
|
---|
81 |
|
---|
82 | // Status Vector, Variance-Covariance Matrix
|
---|
83 | // -----------------------------------------
|
---|
84 | ColumnVector xFltOld = _xFlt;
|
---|
85 | SymmetricMatrix QFltOld = _QFlt;
|
---|
86 |
|
---|
87 | _QFlt.ReSize(_parlist->nPar()); _QFlt = 0.0;
|
---|
88 | _xFlt.ReSize(_parlist->nPar()); _xFlt = 0.0;
|
---|
89 | _x0.ReSize(_parlist->nPar()); _x0 = 0.0;
|
---|
90 |
|
---|
91 | for (unsigned ii = 0; ii < params.size(); ii++) {
|
---|
92 | const t_pppParam* par1 = params[ii];
|
---|
93 |
|
---|
94 | _x0[ii] = par1->x0();
|
---|
95 |
|
---|
96 | int iOld = par1->indexOld();
|
---|
97 | if (iOld < 0) {
|
---|
98 | _QFlt[ii][ii] = par1->sigma0() * par1->sigma0(); // new parameter
|
---|
99 | }
|
---|
100 | else {
|
---|
101 | _QFlt[ii][ii] = QFltOld[iOld][iOld] + par1->noise() * par1->noise();
|
---|
102 | _xFlt[ii] = xFltOld[iOld];
|
---|
103 | for (unsigned jj = 0; jj < ii; jj++) {
|
---|
104 | const t_pppParam* par2 = params[jj];
|
---|
105 | int jOld = par2->indexOld();
|
---|
106 | if (jOld >= 0) {
|
---|
107 | _QFlt[ii][jj] = QFltOld(iOld+1,jOld+1);
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | predictCovCrdPart(QFltOld);
|
---|
114 |
|
---|
115 | // Process Satellite Systems separately
|
---|
116 | // ------------------------------------
|
---|
117 | for (unsigned iSys = 0; iSys < OPT->systems().size(); iSys++) {
|
---|
118 | char system = OPT->systems()[iSys];
|
---|
119 | unsigned int num = 0;
|
---|
120 | vector<t_pppSatObs*> obsVector;
|
---|
121 | for (unsigned jj = 0; jj < allObs.size(); jj++) {
|
---|
122 | if (allObs[jj]->prn().system() == system) {
|
---|
123 | obsVector.push_back(allObs[jj]);
|
---|
124 | num++;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | LOG << epoTimeStr << " SATNUM " << system << ' ' << right << setw(2) << num << endl;
|
---|
128 | if ( processSystem(OPT->LCs(system), obsVector) != success ) {
|
---|
129 | return failure;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | cmpDOP(allObs);
|
---|
134 |
|
---|
135 | _parlist->printResult(_epoTime, _QFlt, _xFlt);
|
---|
136 | _lastEpoTimeOK = _epoTime; // remember time of last successful epoch processing
|
---|
137 | return success;
|
---|
138 | }
|
---|
139 |
|
---|
140 | // Process Selected LCs
|
---|
141 | ////////////////////////////////////////////////////////////////////////////
|
---|
142 | t_irc t_pppFilter::processSystem(const vector<t_lc::type>& LCs,
|
---|
143 | const vector<t_pppSatObs*>& obsVector) {
|
---|
144 |
|
---|
145 | LOG.setf(ios::fixed);
|
---|
146 |
|
---|
147 | // Detect Cycle Slips
|
---|
148 | // ------------------
|
---|
149 | if (detectCycleSlips(LCs, obsVector) != success) {
|
---|
150 | return failure;
|
---|
151 | }
|
---|
152 |
|
---|
153 | ColumnVector xSav = _xFlt;
|
---|
154 | SymmetricMatrix QSav = _QFlt;
|
---|
155 | string epoTimeStr = string(_epoTime);
|
---|
156 | const vector<t_pppParam*>& params = _parlist->params();
|
---|
157 | unsigned maxObs = obsVector.size() * LCs.size();
|
---|
158 |
|
---|
159 | // Outlier Detection Loop
|
---|
160 | // ----------------------
|
---|
161 | for (unsigned iOutlier = 0; iOutlier < maxObs; iOutlier++) {
|
---|
162 |
|
---|
163 | if (iOutlier > 0) {
|
---|
164 | _xFlt = xSav;
|
---|
165 | _QFlt = QSav;
|
---|
166 | }
|
---|
167 |
|
---|
168 | // First-Design Matrix, Terms Observed-Computed, Weight Matrix
|
---|
169 | // -----------------------------------------------------------
|
---|
170 | Matrix AA(maxObs, _parlist->nPar());
|
---|
171 | ColumnVector ll(maxObs);
|
---|
172 | DiagonalMatrix PP(maxObs); PP = 0.0;
|
---|
173 |
|
---|
174 | int iObs = -1;
|
---|
175 | vector<t_pppSatObs*> usedObs;
|
---|
176 | vector<t_lc::type> usedTypes;
|
---|
177 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
178 | t_pppSatObs* obs = obsVector[ii];
|
---|
179 | if (!obs->outlier()) {
|
---|
180 | for (unsigned jj = 0; jj < LCs.size(); jj++) {
|
---|
181 | const t_lc::type tLC = LCs[jj];
|
---|
182 | ++iObs;
|
---|
183 | usedObs.push_back(obs);
|
---|
184 | usedTypes.push_back(tLC);
|
---|
185 | for (unsigned iPar = 0; iPar < params.size(); iPar++) {
|
---|
186 | const t_pppParam* par = params[iPar];
|
---|
187 | AA[iObs][iPar] = par->partial(_epoTime, obs, tLC);
|
---|
188 | }
|
---|
189 | ll[iObs] = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA.Row(iObs+1));
|
---|
190 | PP[iObs] = 1.0 / (obs->sigma(tLC) * obs->sigma(tLC));
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | // Check number of observations, truncate matrices
|
---|
196 | // -----------------------------------------------
|
---|
197 | if (iObs == -1) {
|
---|
198 | return failure;
|
---|
199 | }
|
---|
200 | AA = AA.Rows(1, iObs+1);
|
---|
201 | ll = ll.Rows(1, iObs+1);
|
---|
202 | PP = PP.SymSubMatrix(1, iObs+1);
|
---|
203 |
|
---|
204 | // Kalman update step
|
---|
205 | // ------------------
|
---|
206 | kalman(AA, ll, PP, _QFlt, _xFlt);
|
---|
207 |
|
---|
208 | // Check Residuals
|
---|
209 | // ---------------
|
---|
210 | ColumnVector vv = AA * _xFlt - ll;
|
---|
211 | double maxOutlier = 0.0;
|
---|
212 | int maxOutlierIndex = -1;
|
---|
213 | t_lc::type maxOutlierLC = t_lc::dummy;
|
---|
214 | for (unsigned ii = 0; ii < usedObs.size(); ii++) {
|
---|
215 | const t_lc::type tLC = usedTypes[ii];
|
---|
216 | double res = fabs(vv[ii]);
|
---|
217 | if (res > usedObs[ii]->maxRes(tLC)) {
|
---|
218 | if (res > fabs(maxOutlier)) {
|
---|
219 | maxOutlier = vv[ii];
|
---|
220 | maxOutlierIndex = ii;
|
---|
221 | maxOutlierLC = tLC;
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | // Mark outlier or break outlier detection loop
|
---|
227 | // --------------------------------------------
|
---|
228 | if (maxOutlierIndex > -1) {
|
---|
229 | t_pppSatObs* obs = usedObs[maxOutlierIndex];
|
---|
230 | t_pppParam* par = 0;
|
---|
231 | LOG << epoTimeStr << " Outlier " << t_lc::toString(maxOutlierLC) << ' '
|
---|
232 | << obs->prn().toString() << ' '
|
---|
233 | << setw(8) << setprecision(4) << maxOutlier << endl;
|
---|
234 | for (unsigned iPar = 0; iPar < params.size(); iPar++) {
|
---|
235 | t_pppParam* hlp = params[iPar];
|
---|
236 | if (hlp->type() == t_pppParam::amb && hlp->prn() == obs->prn() &&
|
---|
237 | hlp->tLC() == usedTypes[maxOutlierIndex]) {
|
---|
238 | par = hlp;
|
---|
239 | }
|
---|
240 | }
|
---|
241 | if (par) {
|
---|
242 | if (par->ambResetCandidate()) {
|
---|
243 | resetAmb(par->prn(), obsVector, &QSav, &xSav);
|
---|
244 | }
|
---|
245 | else {
|
---|
246 | par->setAmbResetCandidate();
|
---|
247 | obs->setOutlier();
|
---|
248 | }
|
---|
249 | }
|
---|
250 | else {
|
---|
251 | obs->setOutlier();
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | // Print Residuals
|
---|
256 | // ---------------
|
---|
257 | else {
|
---|
258 | for (unsigned jj = 0; jj < LCs.size(); jj++) {
|
---|
259 | for (unsigned ii = 0; ii < usedObs.size(); ii++) {
|
---|
260 | const t_lc::type tLC = usedTypes[ii];
|
---|
261 | t_pppSatObs* obs = usedObs[ii];
|
---|
262 | if (tLC == LCs[jj]) {
|
---|
263 | obs->setRes(tLC, vv[ii]);
|
---|
264 | LOG << epoTimeStr << " RES "
|
---|
265 | << left << setw(3) << t_lc::toString(tLC) << right << ' '
|
---|
266 | << obs->prn().toString().substr(0,3) << ' '
|
---|
267 | << setw(8) << setprecision(4) << vv[ii] << endl;
|
---|
268 | }
|
---|
269 | }
|
---|
270 | }
|
---|
271 | break;
|
---|
272 | }
|
---|
273 | }
|
---|
274 |
|
---|
275 | return success;
|
---|
276 | }
|
---|
277 |
|
---|
278 | // Cycle-Slip Detection
|
---|
279 | ////////////////////////////////////////////////////////////////////////////
|
---|
280 | t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type>& LCs,
|
---|
281 | const vector<t_pppSatObs*>& obsVector) {
|
---|
282 | const double SLIP = 20.0;
|
---|
283 | string epoTimeStr = string(_epoTime);
|
---|
284 | const vector<t_pppParam*>& params = _parlist->params();
|
---|
285 |
|
---|
286 | for (unsigned ii = 0; ii < LCs.size(); ii++) {
|
---|
287 | const t_lc::type& tLC = LCs[ii];
|
---|
288 | if (t_lc::includesPhase(tLC)) {
|
---|
289 | for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
|
---|
290 | const t_pppSatObs* obs = obsVector[iObs];
|
---|
291 |
|
---|
292 | // Check set Slips and Jump Counters
|
---|
293 | // ---------------------------------
|
---|
294 | bool slip = false;
|
---|
295 |
|
---|
296 | if (obs->slip()) {
|
---|
297 | LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString() << endl;
|
---|
298 | slip = true;
|
---|
299 | }
|
---|
300 |
|
---|
301 | if (_slips[obs->prn()]._obsSlipCounter != -1 &&
|
---|
302 | _slips[obs->prn()]._obsSlipCounter != obs->slipCounter()) {
|
---|
303 | LOG << epoTimeStr << "cycle slip set (obsSlipCounter) " << obs->prn().toString() << endl;
|
---|
304 | slip = true;
|
---|
305 | }
|
---|
306 | _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
|
---|
307 |
|
---|
308 | if (_slips[obs->prn()]._biasJumpCounter != -1 &&
|
---|
309 | _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
|
---|
310 | LOG << epoTimeStr << "cycle slip set (biasJumpCounter) " << obs->prn().toString() << endl;
|
---|
311 | slip = true;
|
---|
312 | }
|
---|
313 | _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
|
---|
314 |
|
---|
315 | // Slip Set
|
---|
316 | // --------
|
---|
317 | if (slip) {
|
---|
318 | resetAmb(obs->prn(), obsVector);
|
---|
319 | }
|
---|
320 |
|
---|
321 | // Check Pre-Fit Residuals
|
---|
322 | // -----------------------
|
---|
323 | else {
|
---|
324 | ColumnVector AA(params.size());
|
---|
325 | for (unsigned iPar = 0; iPar < params.size(); iPar++) {
|
---|
326 | const t_pppParam* par = params[iPar];
|
---|
327 | AA[iPar] = par->partial(_epoTime, obs, tLC);
|
---|
328 | }
|
---|
329 |
|
---|
330 | double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
|
---|
331 | double vv = DotProduct(AA, _xFlt) - ll;
|
---|
332 |
|
---|
333 | if (fabs(vv) > SLIP) {
|
---|
334 | LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
|
---|
335 | << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
|
---|
336 | resetAmb(obs->prn(), obsVector);
|
---|
337 | }
|
---|
338 | }
|
---|
339 | }
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | return success;
|
---|
344 | }
|
---|
345 |
|
---|
346 | // Reset Ambiguity Parameter (cycle slip)
|
---|
347 | ////////////////////////////////////////////////////////////////////////////
|
---|
348 | t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*>& obsVector,
|
---|
349 | SymmetricMatrix* QSav, ColumnVector* xSav) {
|
---|
350 | t_irc irc = failure;
|
---|
351 | vector<t_pppParam*>& params = _parlist->params();
|
---|
352 | for (unsigned iPar = 0; iPar < params.size(); iPar++) {
|
---|
353 | t_pppParam* par = params[iPar];
|
---|
354 | if (par->type() == t_pppParam::amb && par->prn() == prn) {
|
---|
355 | int ind = par->indexNew();
|
---|
356 | t_lc::type tLC = par->tLC();
|
---|
357 | LOG << string(_epoTime) << " RESET " << par->toString() << endl;
|
---|
358 | delete par; par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
|
---|
359 | par->setIndex(ind);
|
---|
360 | params[iPar] = par;
|
---|
361 | for (unsigned ii = 1; ii <= params.size(); ii++) {
|
---|
362 | _QFlt(ii, ind+1) = 0.0;
|
---|
363 | if (QSav) {
|
---|
364 | (*QSav)(ii, ind+1) = 0.0;
|
---|
365 | }
|
---|
366 | }
|
---|
367 | _QFlt(ind+1,ind+1) = par->sigma0() * par->sigma0();
|
---|
368 | if (QSav) {
|
---|
369 | (*QSav)(ind+1,ind+1) = _QFlt(ind+1,ind+1);
|
---|
370 | }
|
---|
371 | _xFlt[ind] = 0.0;
|
---|
372 | if (xSav) {
|
---|
373 | (*xSav)[ind] = _xFlt[ind];
|
---|
374 | }
|
---|
375 | _x0[ind] = par->x0();
|
---|
376 | irc = success;
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | return irc;
|
---|
381 | }
|
---|
382 |
|
---|
383 | // Compute various DOP Values
|
---|
384 | ////////////////////////////////////////////////////////////////////////////
|
---|
385 | void t_pppFilter::cmpDOP(const vector<t_pppSatObs*>& obsVector) {
|
---|
386 |
|
---|
387 | _dop.reset();
|
---|
388 |
|
---|
389 | try {
|
---|
390 | const unsigned numPar = 4;
|
---|
391 | Matrix AA(obsVector.size(), numPar);
|
---|
392 | _numSat = 0;
|
---|
393 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
394 | t_pppSatObs* obs = obsVector[ii];
|
---|
395 | if (obs->isValid() && !obs->outlier()) {
|
---|
396 | ++_numSat;
|
---|
397 | for (unsigned iPar = 0; iPar < numPar; iPar++) {
|
---|
398 | const t_pppParam* par = _parlist->params()[iPar];
|
---|
399 | AA[_numSat-1][iPar] = par->partial(_epoTime, obs, t_lc::c1);
|
---|
400 | }
|
---|
401 | }
|
---|
402 | }
|
---|
403 | if (_numSat < 4) {
|
---|
404 | return;
|
---|
405 | }
|
---|
406 | AA = AA.Rows(1, _numSat);
|
---|
407 | SymmetricMatrix NN; NN << AA.t() * AA;
|
---|
408 | SymmetricMatrix QQ = NN.i();
|
---|
409 |
|
---|
410 | _dop.H = sqrt(QQ(1,1) + QQ(2,2));
|
---|
411 | _dop.V = sqrt(QQ(3,3));
|
---|
412 | _dop.P = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
|
---|
413 | _dop.T = sqrt(QQ(4,4));
|
---|
414 | _dop.G = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3) + QQ(4,4));
|
---|
415 | }
|
---|
416 | catch (...) {
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | // Compute various DOP Values
|
---|
421 | ////////////////////////////////////////////////////////////////////////////
|
---|
422 | void t_pppFilter::predictCovCrdPart(const SymmetricMatrix& QFltOld) {
|
---|
423 |
|
---|
424 | const vector<t_pppParam*>& params = _parlist->params();
|
---|
425 | if (params.size() < 3) {
|
---|
426 | return;
|
---|
427 | }
|
---|
428 |
|
---|
429 | bool first = (params[0]->indexOld() < 0);
|
---|
430 |
|
---|
431 | SymmetricMatrix Qneu(3); Qneu = 0.0;
|
---|
432 | for (unsigned ii = 0; ii < 3; ii++) {
|
---|
433 | const t_pppParam* par = params[ii];
|
---|
434 | if (first) {
|
---|
435 | Qneu[ii][ii] = par->sigma0() * par->sigma0();
|
---|
436 | }
|
---|
437 | else {
|
---|
438 | Qneu[ii][ii] = par->noise() * par->noise();
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | const t_pppStation* sta = PPP_CLIENT->staRover();
|
---|
443 | SymmetricMatrix Qxyz(3);
|
---|
444 | covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
|
---|
445 |
|
---|
446 | if (first) {
|
---|
447 | _QFlt.SymSubMatrix(1,3) = Qxyz;
|
---|
448 | }
|
---|
449 | else {
|
---|
450 | double dt = _epoTime - _firstEpoTime;
|
---|
451 | if (dt < OPT->_seedingTime) {
|
---|
452 | _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3);
|
---|
453 | }
|
---|
454 | else {
|
---|
455 | _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3) + Qxyz;
|
---|
456 | }
|
---|
457 | }
|
---|
458 | }
|
---|