source: ntrip/branches/BNC_2.12/src/PPP/pppFilter.cpp@ 8330

Last change on this file since 8330 was 8330, checked in by stuerze, 4 years ago

cycle slip log messages enlarged

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 13.5 KB
Line 
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
31using namespace BNC_PPP;
32using namespace std;
33
34// Constructor
35////////////////////////////////////////////////////////////////////////////
36t_pppFilter::t_pppFilter() {
37 _parlist = 0;
38}
39
40// Destructor
41////////////////////////////////////////////////////////////////////////////
42t_pppFilter::~t_pppFilter() {
43 delete _parlist;
44}
45
46// Process Single Epoch
47////////////////////////////////////////////////////////////////////////////
48t_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////////////////////////////////////////////////////////////////////////////
142t_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////////////////////////////////////////////////////////////////////////////
280t_irc t_pppFilter::detectCycleSlips(const vector<t_lc::type>& LCs,
281 const vector<t_pppSatObs*>& obsVector) {
282
283 const double SLIP = 20.0; // slip threshold
284 string epoTimeStr = string(_epoTime);
285 const vector<t_pppParam*>& params = _parlist->params();
286
287 for (unsigned ii = 0; ii < LCs.size(); ii++) {
288 const t_lc::type& tLC = LCs[ii];
289 if (t_lc::includesPhase(tLC)) {
290 for (unsigned iObs = 0; iObs < obsVector.size(); iObs++) {
291 const t_pppSatObs* obs = obsVector[iObs];
292
293 // Check set Slips and Jump Counters
294 // ---------------------------------
295 bool slip = false;
296
297 if (obs->slip()) {
298 LOG << epoTimeStr << "cycle slip set (obs) " << obs->prn().toString() << endl;
299 slip = true;
300 }
301
302 if (_slips[obs->prn()]._obsSlipCounter != -1 &&
303 _slips[obs->prn()]._obsSlipCounter > obs->slipCounter()) {
304 LOG << epoTimeStr << "cycle slip set (obsSlipCounter) " << obs->prn().toString() << endl;
305 slip = true;
306 }
307 _slips[obs->prn()]._obsSlipCounter = obs->slipCounter();
308
309 if (_slips[obs->prn()]._biasJumpCounter != -1 &&
310 _slips[obs->prn()]._biasJumpCounter != obs->biasJumpCounter()) {
311 LOG << epoTimeStr << "cycle slip set (biasJumpCounter) " << obs->prn().toString() << endl;
312 slip = true;
313 }
314 _slips[obs->prn()]._biasJumpCounter = obs->biasJumpCounter();
315
316 // Slip Set
317 // --------
318 if (slip) {
319 resetAmb(obs->prn(), obsVector);
320 }
321
322 // Check Pre-Fit Residuals
323 // -----------------------
324 else {
325 ColumnVector AA(params.size());
326 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
327 const t_pppParam* par = params[iPar];
328 AA[iPar] = par->partial(_epoTime, obs, tLC);
329 }
330
331 double ll = obs->obsValue(tLC) - obs->cmpValue(tLC) - DotProduct(_x0, AA);
332 double vv = DotProduct(AA, _xFlt) - ll;
333
334 if (fabs(vv) > SLIP) {
335 LOG << epoTimeStr << " cycle slip detected " << t_lc::toString(tLC) << ' '
336 << obs->prn().toString() << ' ' << setw(8) << setprecision(4) << vv << endl;
337 resetAmb(obs->prn(), obsVector);
338 }
339 }
340 }
341 }
342 }
343
344 return success;
345}
346
347// Reset Ambiguity Parameter (cycle slip)
348////////////////////////////////////////////////////////////////////////////
349t_irc t_pppFilter::resetAmb(t_prn prn, const vector<t_pppSatObs*>& obsVector,
350 SymmetricMatrix* QSav, ColumnVector* xSav) {
351 t_irc irc = failure;
352 vector<t_pppParam*>& params = _parlist->params();
353 for (unsigned iPar = 0; iPar < params.size(); iPar++) {
354 t_pppParam* par = params[iPar];
355 if (par->type() == t_pppParam::amb && par->prn() == prn) {
356 int ind = par->indexNew();
357 t_lc::type tLC = par->tLC();
358 LOG << string(_epoTime) << " RESET " << par->toString() << endl;
359 delete par; par = new t_pppParam(t_pppParam::amb, prn, tLC, &obsVector);
360 par->setIndex(ind);
361 params[iPar] = par;
362 for (unsigned ii = 1; ii <= params.size(); ii++) {
363 _QFlt(ii, ind+1) = 0.0;
364 if (QSav) {
365 (*QSav)(ii, ind+1) = 0.0;
366 }
367 }
368 _QFlt(ind+1,ind+1) = par->sigma0() * par->sigma0();
369 if (QSav) {
370 (*QSav)(ind+1,ind+1) = _QFlt(ind+1,ind+1);
371 }
372 _xFlt[ind] = 0.0;
373 if (xSav) {
374 (*xSav)[ind] = _xFlt[ind];
375 }
376 _x0[ind] = par->x0();
377 irc = success;
378 }
379 }
380
381 return irc;
382}
383
384// Compute various DOP Values
385////////////////////////////////////////////////////////////////////////////
386void t_pppFilter::cmpDOP(const vector<t_pppSatObs*>& obsVector) {
387
388 _dop.reset();
389
390 try {
391 const unsigned numPar = 4;
392 Matrix AA(obsVector.size(), numPar);
393 _numSat = 0;
394 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
395 t_pppSatObs* obs = obsVector[ii];
396 if (obs->isValid() && !obs->outlier()) {
397 ++_numSat;
398 for (unsigned iPar = 0; iPar < numPar; iPar++) {
399 const t_pppParam* par = _parlist->params()[iPar];
400 AA[_numSat-1][iPar] = par->partial(_epoTime, obs, t_lc::c1);
401 }
402 }
403 }
404 if (_numSat < 4) {
405 return;
406 }
407 AA = AA.Rows(1, _numSat);
408 SymmetricMatrix NN; NN << AA.t() * AA;
409 SymmetricMatrix QQ = NN.i();
410
411 _dop.H = sqrt(QQ(1,1) + QQ(2,2));
412 _dop.V = sqrt(QQ(3,3));
413 _dop.P = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3));
414 _dop.T = sqrt(QQ(4,4));
415 _dop.G = sqrt(QQ(1,1) + QQ(2,2) + QQ(3,3) + QQ(4,4));
416 }
417 catch (...) {
418 }
419}
420
421// Compute various DOP Values
422////////////////////////////////////////////////////////////////////////////
423void t_pppFilter::predictCovCrdPart(const SymmetricMatrix& QFltOld) {
424
425 const vector<t_pppParam*>& params = _parlist->params();
426 if (params.size() < 3) {
427 return;
428 }
429
430 bool first = (params[0]->indexOld() < 0);
431
432 SymmetricMatrix Qneu(3); Qneu = 0.0;
433 for (unsigned ii = 0; ii < 3; ii++) {
434 const t_pppParam* par = params[ii];
435 if (first) {
436 Qneu[ii][ii] = par->sigma0() * par->sigma0();
437 }
438 else {
439 Qneu[ii][ii] = par->noise() * par->noise();
440 }
441 }
442
443 const t_pppStation* sta = PPP_CLIENT->staRover();
444 SymmetricMatrix Qxyz(3);
445 covariNEU_XYZ(Qneu, sta->ellApr().data(), Qxyz);
446
447 if (first) {
448 _QFlt.SymSubMatrix(1,3) = Qxyz;
449 }
450 else {
451 double dt = _epoTime - _firstEpoTime;
452 if (dt < OPT->_seedingTime) {
453 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3);
454 }
455 else {
456 _QFlt.SymSubMatrix(1,3) = QFltOld.SymSubMatrix(1,3) + Qxyz;
457 }
458 }
459}
Note: See TracBrowser for help on using the repository browser.