source: ntrip/trunk/BNC/src/PPP_SSR_I/pppFilter.cpp@ 9485

Last change on this file since 9485 was 9485, checked in by stuerze, 17 months ago

minor changes

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 42.0 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_pppParam, t_pppFilter
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43#include <sstream>
44#include <newmatio.h>
45#include <newmatap.h>
46
47#include "pppFilter.h"
48#include "pppClient.h"
49#include "bncutils.h"
50#include "bncantex.h"
51#include "pppOptions.h"
52#include "pppModel.h"
53
54using namespace BNC_PPP;
55using namespace std;
56
57const double GLONASS_WEIGHT_FACTOR = 5.0;
58const double BDS_WEIGHT_FACTOR = 2.0; // 5.0;
59
60#define LOG (_pppClient->log())
61#define OPT (_pppClient->opt())
62
63// Constructor
64////////////////////////////////////////////////////////////////////////////
65t_pppParam::t_pppParam(t_pppParam::parType typeIn, int indexIn,
66 const QString& prnIn) {
67 type = typeIn;
68 index = indexIn;
69 prn = prnIn;
70 index_old = 0;
71 xx = 0.0;
72 numEpo = 0;
73}
74
75// Destructor
76////////////////////////////////////////////////////////////////////////////
77t_pppParam::~t_pppParam() {
78}
79
80// Partial
81////////////////////////////////////////////////////////////////////////////
82double t_pppParam::partial(t_satData* satData, bool phase) {
83
84 Tracer tracer("t_pppParam::partial");
85
86 // Coordinates
87 // -----------
88 if (type == CRD_X) {
89 return (xx - satData->xx(1)) / satData->rho;
90 }
91 else if (type == CRD_Y) {
92 return (xx - satData->xx(2)) / satData->rho;
93 }
94 else if (type == CRD_Z) {
95 return (xx - satData->xx(3)) / satData->rho;
96 }
97
98 // Receiver Clocks
99 // ---------------
100 else if (type == RECCLK) {
101 return 1.0;
102 }
103
104 // Troposphere
105 // -----------
106 else if (type == TROPO) {
107 return 1.0 / sin(satData->eleSat);
108 }
109
110 // Glonass Offset
111 // --------------
112 else if (type == GLONASS_OFFSET) {
113 if (satData->prn[0] == 'R') {
114 return 1.0;
115 }
116 else {
117 return 0.0;
118 }
119 }
120
121 // Galileo Offset
122 // --------------
123 else if (type == GALILEO_OFFSET) {
124 if (satData->prn[0] == 'E') {
125 return 1.0;
126 }
127 else {
128 return 0.0;
129 }
130 }
131
132 // BDS Offset
133 // ----------
134 else if (type == BDS_OFFSET) {
135 if (satData->prn[0] == 'C') {
136 return 1.0;
137 }
138 else {
139 return 0.0;
140 }
141 }
142
143 // Ambiguities
144 // -----------
145 else if (type == AMB_L3) {
146 if (phase && satData->prn == prn) {
147 return 1.0;
148 }
149 else {
150 return 0.0;
151 }
152 }
153
154 // Default return
155 // --------------
156 return 0.0;
157}
158
159// Constructor
160////////////////////////////////////////////////////////////////////////////
161t_pppFilter::t_pppFilter(t_pppClient* pppClient) {
162
163 _pppClient = pppClient;
164 _tides = new t_tides();
165
166 // Antenna Name, ANTEX File
167 // ------------------------
168 _antex = 0;
169 if (!OPT->_antexFileName.empty()) {
170 _antex = new bncAntex(OPT->_antexFileName.c_str());
171 }
172
173 // Bancroft Coordinates
174 // --------------------
175 _xcBanc.ReSize(4); _xcBanc = 0.0;
176 _ellBanc.ReSize(3); _ellBanc = 0.0;
177
178 // Save copy of data (used in outlier detection)
179 // ---------------------------------------------
180 _epoData_sav = new t_epoData();
181
182 // Some statistics
183 // ---------------
184 _neu.ReSize(3); _neu = 0.0;
185 _numSat = 0;
186 _hDop = 0.0;
187}
188
189// Destructor
190////////////////////////////////////////////////////////////////////////////
191t_pppFilter::~t_pppFilter() {
192 delete _tides;
193 delete _antex;
194 for (int iPar = 1; iPar <= _params.size(); iPar++) {
195 delete _params[iPar-1];
196 }
197 for (int iPar = 1; iPar <= _params_sav.size(); iPar++) {
198 delete _params_sav[iPar-1];
199 }
200 delete _epoData_sav;
201}
202
203// Reset Parameters and Variance-Covariance Matrix
204////////////////////////////////////////////////////////////////////////////
205void t_pppFilter::reset() {
206
207 Tracer tracer("t_pppFilter::reset");
208
209 double lastTrp = 0.0;
210 for (int ii = 0; ii < _params.size(); ii++) {
211 t_pppParam* pp = _params[ii];
212 if (pp->type == t_pppParam::TROPO) {
213 lastTrp = pp->xx;
214 }
215 delete pp;
216 }
217 _params.clear();
218
219 int nextPar = 0;
220 _params.push_back(new t_pppParam(t_pppParam::CRD_X, ++nextPar, ""));
221 _params.push_back(new t_pppParam(t_pppParam::CRD_Y, ++nextPar, ""));
222 _params.push_back(new t_pppParam(t_pppParam::CRD_Z, ++nextPar, ""));
223 _params.push_back(new t_pppParam(t_pppParam::RECCLK, ++nextPar, ""));
224 if (OPT->estTrp()) {
225 _params.push_back(new t_pppParam(t_pppParam::TROPO, ++nextPar, ""));
226 }
227 if (OPT->useSystem('R')) {
228 _params.push_back(new t_pppParam(t_pppParam::GLONASS_OFFSET, ++nextPar, ""));
229 }
230 if (OPT->useSystem('E')) {
231 _params.push_back(new t_pppParam(t_pppParam::GALILEO_OFFSET, ++nextPar, ""));
232 }
233 if (OPT->useSystem('C')) {
234 _params.push_back(new t_pppParam(t_pppParam::BDS_OFFSET, ++nextPar, ""));
235 }
236
237 _QQ.ReSize(_params.size());
238 _QQ = 0.0;
239 for (int iPar = 1; iPar <= _params.size(); iPar++) {
240 t_pppParam* pp = _params[iPar-1];
241 pp->xx = 0.0;
242 if (pp->isCrd()) {
243 _QQ(iPar,iPar) = OPT->_aprSigCrd(1) * OPT->_aprSigCrd(1);
244 }
245 else if (pp->type == t_pppParam::RECCLK) {
246 _QQ(iPar,iPar) = OPT->_aprSigClk * OPT->_aprSigClk;
247 }
248 else if (pp->type == t_pppParam::TROPO) {
249 _QQ(iPar,iPar) = OPT->_aprSigTrp * OPT->_aprSigTrp;
250 pp->xx = lastTrp;
251 }
252 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
253 _QQ(iPar,iPar) = 1000.0 * 1000.0;
254 }
255 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
256 _QQ(iPar,iPar) = 1000.0 * 1000.0;
257 }
258 else if (pp->type == t_pppParam::BDS_OFFSET) {
259 _QQ(iPar,iPar) = 1000.0 * 1000.0;
260 }
261 }
262}
263
264// Bancroft Solution
265////////////////////////////////////////////////////////////////////////////
266t_irc t_pppFilter::cmpBancroft(t_epoData* epoData) {
267
268 Tracer tracer("t_pppFilter::cmpBancroft");
269
270 if (int(epoData->sizeSys('G')) < OPT->_minObs) {
271 LOG << "t_pppFilter::cmpBancroft: not enough data\n";
272 return failure;
273 }
274
275 Matrix BB(epoData->sizeSys('G'), 4);
276
277 QMapIterator<QString, t_satData*> it(epoData->satData);
278 int iObsBanc = 0;
279 while (it.hasNext()) {
280 it.next();
281 t_satData* satData = it.value();
282 if (satData->system() == 'G') {
283 ++iObsBanc;
284 QString prn = it.key();
285 BB(iObsBanc, 1) = satData->xx(1);
286 BB(iObsBanc, 2) = satData->xx(2);
287 BB(iObsBanc, 3) = satData->xx(3);
288 BB(iObsBanc, 4) = satData->P3 + satData->clk;
289 }
290 }
291
292 bancroft(BB, _xcBanc);
293
294 if (std::isnan(_xcBanc(1)) ||
295 std::isnan(_xcBanc(2)) ||
296 std::isnan(_xcBanc(3))) {
297 return failure;
298 }
299
300 // Ellipsoidal Coordinates
301 // ------------------------
302 xyz2ell(_xcBanc.data(), _ellBanc.data());
303
304 // Compute Satellite Elevations
305 // ----------------------------
306 QMutableMapIterator<QString, t_satData*> im(epoData->satData);
307 while (im.hasNext()) {
308 im.next();
309 t_satData* satData = im.value();
310 cmpEle(satData);
311 if (satData->eleSat < OPT->_minEle) {
312 delete satData;
313 im.remove();
314 }
315 }
316
317 return success;
318}
319
320// Computed Value
321////////////////////////////////////////////////////////////////////////////
322double t_pppFilter::cmpValue(t_satData* satData, bool phase) {
323
324 Tracer tracer("t_pppFilter::cmpValue");
325
326 ColumnVector xRec(3);
327 xRec(1) = x();
328 xRec(2) = y();
329 xRec(3) = z();
330
331 double rho0 = (satData->xx - xRec).NormFrobenius();
332 double dPhi = t_CST::omega * rho0 / t_CST::c;
333
334 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
335 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
336 xRec(3) = z();
337
338 xRec += _tides->earth(_time, xRec);
339
340 satData->rho = (satData->xx - xRec).NormFrobenius();
341
342 double tropDelay = delay_saast(satData->eleSat) +
343 trp() / sin(satData->eleSat);
344
345 double wind = 0.0;
346 if (phase) {
347 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
348 }
349
350 double offset = 0.0;
351
352 t_frequency::type frqA;
353 t_frequency::type frqB;
354
355 if (satData->prn[0] == 'R') {
356 offset = Glonass_offset();
357 frqA = t_frequency::R1;
358 frqB = t_frequency::R2;
359 }
360 else if (satData->prn[0] == 'E') {
361 offset = Galileo_offset();
362 frqA = t_frequency::E1;
363 frqB = t_frequency::E5;
364 }
365 else if (satData->prn[0] == 'C') {
366 offset = Bds_offset();
367 frqA = t_frequency::C2;
368 frqB = t_frequency::C6;
369 }
370 else {
371 frqA = t_frequency::G1;
372 frqB = t_frequency::G2;
373 }
374
375 double phaseCenter = 0.0;
376
377 if (_antex) {
378
379 // Satellite correction
380 // ---------------------
381 double elTx,azTx;
382
383 // LOS unit vector satellite --> receiver
384 ColumnVector rho = xRec - satData->xx;
385 rho /= rho.norm_Frobenius();
386
387 // Sun unit vector
388 ColumnVector xSun = t_astro::Sun(satData->tt.mjddec());
389 xSun /= xSun.norm_Frobenius();
390
391 // Satellite unit vectors sz, sy, sx
392 ColumnVector sz = -satData->xx / satData->xx.norm_Frobenius();
393 ColumnVector sy = crossproduct(sz, xSun);
394 ColumnVector sx = crossproduct(sy, sz);
395
396 sx /= sx.norm_Frobenius();
397 sy /= sy.norm_Frobenius();
398
399 // LOS vector in satellite frame
400 ColumnVector u(3);
401 u(1) = dotproduct(sx, rho);
402 u(2) = dotproduct(sy, rho);
403 u(3) = dotproduct(sz, rho);
404
405 // Azimuth and elevation in satellite antenna frame
406 elTx = atan2(u(3),sqrt(pow(u(2),2)+pow(u(1),2)));
407 azTx = atan2(u(2),u(1));
408
409 bool found;
410 if (OPT->_isAPC) {
411 phaseCenter += satData->lkB * _antex->satCorr(satData->prn, frqA, elTx, azTx, found);
412 }
413 else {
414 phaseCenter += satData->lkA * _antex->satCorr(satData->prn, frqA, elTx, azTx, found);
415 }
416 if (!found) {
417 LOG << "ANTEX: antenna >" << satData->prn.mid(0,3).toStdString() << " " << frqA << "< not found\n";
418 }
419
420 phaseCenter += satData->lkB * _antex->satCorr(satData->prn, frqB, elTx, azTx, found);
421 if (!found) {
422 LOG << "ANTEX: antenna >" << satData->prn.mid(0,3).toStdString() << " " << frqB << "< not found\n";
423 }
424
425 // Receiver correction
426 // -------------------
427
428 phaseCenter += satData->lkA * _antex->rcvCorr(OPT->_antNameRover, frqA,
429 satData->eleSat, satData->azSat, found);
430 if (!found) {
431 phaseCenter += satData->lkA * _antex->rcvCorr(OPT->_antNameRover, t_frequency::G1,
432 satData->eleSat, satData->azSat, found);
433 }
434 if (!found) {
435 LOG << "ANTEX: antenna >" << OPT->_antNameRover << " " << frqA << "< not found\n";
436 }
437
438 phaseCenter += satData->lkB * _antex->rcvCorr(OPT->_antNameRover, frqB,
439 satData->eleSat, satData->azSat, found);
440 if (!found) {
441 phaseCenter += satData->lkB * _antex->rcvCorr(OPT->_antNameRover, t_frequency::G2,
442 satData->eleSat, satData->azSat, found);
443 }
444 if (!found) {
445 LOG << "ANTEX: antenna >" << OPT->_antNameRover << " " << frqB << "< not found\n";
446 }
447 }
448
449 double antennaOffset = 0.0;
450 double cosa = cos(satData->azSat);
451 double sina = sin(satData->azSat);
452 double cose = cos(satData->eleSat);
453 double sine = sin(satData->eleSat);
454 antennaOffset = -OPT->_neuEccRover(1) * cosa*cose
455 -OPT->_neuEccRover(2) * sina*cose
456 -OPT->_neuEccRover(3) * sine;
457
458 return satData->rho + phaseCenter + antennaOffset + clk()
459 + offset - satData->clk + tropDelay + wind;
460}
461
462// Tropospheric Model (Saastamoinen)
463////////////////////////////////////////////////////////////////////////////
464double t_pppFilter::delay_saast(double Ele) {
465
466 Tracer tracer("t_pppFilter::delay_saast");
467
468 double xyz[3];
469 xyz[0] = x();
470 xyz[1] = y();
471 xyz[2] = z();
472 double ell[3];
473 xyz2ell(xyz, ell);
474 double height = ell[2];
475 // Prevent pp from causing segmentation fault (Loukis)
476 if (height > 40000.0 ) {
477 return 0.000000001;
478 }
479
480 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
481 double TT = 18.0 - height * 0.0065 + 273.15;
482 double hh = 50.0 * exp(-6.396e-4 * height);
483 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
484
485 double h_km = height / 1000.0;
486
487 if (h_km < 0.0) h_km = 0.0;
488 if (h_km > 5.0) h_km = 5.0;
489 int ii = int(h_km + 1);
490 double href = ii - 1;
491
492 double bCor[6];
493 bCor[0] = 1.156;
494 bCor[1] = 1.006;
495 bCor[2] = 0.874;
496 bCor[3] = 0.757;
497 bCor[4] = 0.654;
498 bCor[5] = 0.563;
499
500 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
501
502 double zen = M_PI/2.0 - Ele;
503
504 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
505}
506
507// Prediction Step of the Filter
508////////////////////////////////////////////////////////////////////////////
509void t_pppFilter::predict(int iPhase, t_epoData* epoData) {
510
511 Tracer tracer("t_pppFilter::predict");
512
513 if (iPhase == 0) {
514
515 const double maxSolGap = 60.0;
516
517 bool firstCrd = false;
518 if (!_lastTimeOK.valid() || (maxSolGap > 0.0 && _time - _lastTimeOK > maxSolGap)) {
519 firstCrd = true;
520 _startTime = epoData->tt;
521 reset();
522 }
523
524 // Use different white noise for Quick-Start mode
525 // ----------------------------------------------
526 double sigCrdP_used = OPT->_noiseCrd(1);
527 if ( OPT->_seedingTime > 0.0 && OPT->_seedingTime > (epoData->tt - _startTime) ) {
528 sigCrdP_used = 0.0;
529 }
530
531 // Predict Parameter values, add white noise
532 // -----------------------------------------
533 for (int iPar = 1; iPar <= _params.size(); iPar++) {
534 t_pppParam* pp = _params[iPar-1];
535
536 // Coordinates
537 // -----------
538 if (pp->type == t_pppParam::CRD_X) {
539 if (firstCrd) {
540 if (OPT->xyzAprRoverSet()) {
541 pp->xx = OPT->_xyzAprRover[0];
542 }
543 else {
544 pp->xx = _xcBanc(1);
545 }
546 }
547 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
548 }
549 else if (pp->type == t_pppParam::CRD_Y) {
550 if (firstCrd) {
551 if (OPT->xyzAprRoverSet()) {
552 pp->xx = OPT->_xyzAprRover[1];
553 }
554 else {
555 pp->xx = _xcBanc(2);
556 }
557 }
558 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
559 }
560 else if (pp->type == t_pppParam::CRD_Z) {
561 if (firstCrd) {
562 if (OPT->xyzAprRoverSet()) {
563 pp->xx = OPT->_xyzAprRover[2];
564 }
565 else {
566 pp->xx = _xcBanc(3);
567 }
568 }
569 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
570 }
571
572 // Receiver Clocks
573 // ---------------
574 else if (pp->type == t_pppParam::RECCLK) {
575 pp->xx = _xcBanc(4);
576 for (int jj = 1; jj <= _params.size(); jj++) {
577 _QQ(iPar, jj) = 0.0;
578 }
579 _QQ(iPar,iPar) = OPT->_aprSigClk * OPT->_aprSigClk;
580 }
581
582 // Tropospheric Delay
583 // ------------------
584 else if (pp->type == t_pppParam::TROPO) {
585 _QQ(iPar,iPar) += OPT->_noiseTrp * OPT->_noiseTrp;
586 }
587
588 // Glonass Offset
589 // --------------
590 else if (pp->type == t_pppParam::GLONASS_OFFSET) {
591 pp->xx = 0.0;
592 for (int jj = 1; jj <= _params.size(); jj++) {
593 _QQ(iPar, jj) = 0.0;
594 }
595 _QQ(iPar,iPar) = 1000.0 * 1000.0;
596 }
597
598 // Galileo Offset
599 // --------------
600 else if (pp->type == t_pppParam::GALILEO_OFFSET) {
601 if (_QQ(iPar,iPar)>pow(1000.0,2))
602 _QQ(iPar,iPar) = 1000.0 * 1000.0;
603 else
604 _QQ(iPar,iPar) += 0.1 * 0.1;
605 }
606
607 // BDS Offset
608 // ----------
609 else if (pp->type == t_pppParam::BDS_OFFSET) {
610 if (_QQ(iPar,iPar)>pow(1000.0,2))
611 _QQ(iPar,iPar) = 1000.0 * 1000.0;
612 else
613 _QQ(iPar,iPar) += 0.1 * 0.1;
614 }
615 }
616 }
617
618 // Add New Ambiguities if necessary
619 // --------------------------------
620 if (OPT->ambLCs('G').size() || OPT->ambLCs('R').size() ||
621 OPT->ambLCs('E').size() || OPT->ambLCs('C').size()) {
622
623 // Make a copy of QQ and xx, set parameter indices
624 // -----------------------------------------------
625 SymmetricMatrix QQ_old = _QQ;
626
627 for (int iPar = 1; iPar <= _params.size(); iPar++) {
628 _params[iPar-1]->index_old = _params[iPar-1]->index;
629 _params[iPar-1]->index = 0;
630 }
631
632 // Remove Ambiguity Parameters without observations
633 // ------------------------------------------------
634 int iPar = 0;
635 QMutableVectorIterator<t_pppParam*> im(_params);
636 while (im.hasNext()) {
637 t_pppParam* par = im.next();
638 bool removed = false;
639 if (par->type == t_pppParam::AMB_L3) {
640 if (epoData->satData.find(par->prn) == epoData->satData.end()) {
641 removed = true;
642 delete par;
643 im.remove();
644 }
645 }
646 if (! removed) {
647 ++iPar;
648 par->index = iPar;
649 }
650 }
651
652 // Add new ambiguity parameters
653 // ----------------------------
654 QMapIterator<QString, t_satData*> it(epoData->satData);
655 while (it.hasNext()) {
656 it.next();
657 t_satData* satData = it.value();
658 addAmb(satData);
659 }
660
661 int nPar = _params.size();
662 _QQ.ReSize(nPar); _QQ = 0.0;
663 for (int i1 = 1; i1 <= nPar; i1++) {
664 t_pppParam* p1 = _params[i1-1];
665 if (p1->index_old != 0) {
666 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
667 for (int i2 = 1; i2 <= nPar; i2++) {
668 t_pppParam* p2 = _params[i2-1];
669 if (p2->index_old != 0) {
670 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
671 }
672 }
673 }
674 }
675
676 for (int ii = 1; ii <= nPar; ii++) {
677 t_pppParam* par = _params[ii-1];
678 if (par->index_old == 0) {
679 _QQ(par->index, par->index) = OPT->_aprSigAmb * OPT->_aprSigAmb;
680 }
681 par->index_old = par->index;
682 }
683 }
684}
685
686// Update Step of the Filter (currently just a single-epoch solution)
687////////////////////////////////////////////////////////////////////////////
688t_irc t_pppFilter::update(t_epoData* epoData) {
689
690 Tracer tracer("t_pppFilter::update");
691
692 _time = epoData->tt; // current epoch time
693
694 if (OPT->useOrbClkCorr()) {
695 LOG << "Precise Point Positioning of Epoch " << _time.datestr() << "_" << _time.timestr(3)
696 << "\n---------------------------------------------------------------\n";
697 }
698 else {
699 LOG << "Single Point Positioning of Epoch " << _time.datestr() << "_" << _time.timestr(3)
700 << "\n---------------------------------------------------------------\n";
701 }
702
703 // Outlier Detection Loop
704 // ----------------------
705 if (update_p(epoData) != success) {
706 return failure;
707 }
708
709 // Set Solution Vector
710 // -------------------
711 LOG.setf(ios::fixed);
712 QVectorIterator<t_pppParam*> itPar(_params);
713 while (itPar.hasNext()) {
714 t_pppParam* par = itPar.next();
715 if (par->type == t_pppParam::RECCLK) {
716 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
717 << " CLK " << setw(10) << setprecision(3) << par->xx
718 << " +- " << setw(6) << setprecision(3)
719 << sqrt(_QQ(par->index,par->index));
720 }
721 else if (par->type == t_pppParam::AMB_L3) {
722 ++par->numEpo;
723 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
724 << " AMB " << par->prn.mid(0,3).toLatin1().data() << " "
725 << setw(10) << setprecision(3) << par->xx
726 << " +- " << setw(6) << setprecision(3)
727 << sqrt(_QQ(par->index,par->index))
728 << " epo = " << par->numEpo;
729 }
730 else if (par->type == t_pppParam::TROPO) {
731 double aprTrp = delay_saast(M_PI/2.0);
732 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
733 << " TRP " << par->prn.mid(0,3).toLatin1().data()
734 << setw(7) << setprecision(3) << aprTrp << " "
735 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
736 << " +- " << setw(6) << setprecision(3)
737 << sqrt(_QQ(par->index,par->index));
738 }
739 else if (par->type == t_pppParam::GLONASS_OFFSET) {
740 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
741 << " OFFGLO " << setw(10) << setprecision(3) << par->xx
742 << " +- " << setw(6) << setprecision(3)
743 << sqrt(_QQ(par->index,par->index));
744 }
745 else if (par->type == t_pppParam::GALILEO_OFFSET) {
746 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
747 << " OFFGAL " << setw(10) << setprecision(3) << par->xx
748 << " +- " << setw(6) << setprecision(3)
749 << sqrt(_QQ(par->index,par->index));
750 }
751 else if (par->type == t_pppParam::BDS_OFFSET) {
752 LOG << "\n" << _time.datestr() << "_" << _time.timestr(3)
753 << " OFFBDS " << setw(10) << setprecision(3) << par->xx
754 << " +- " << setw(6) << setprecision(3)
755 << sqrt(_QQ(par->index,par->index));
756 }
757 }
758
759 LOG << endl << endl;
760
761 // Compute dilution of precision
762 // -----------------------------
763 cmpDOP(epoData);
764
765 // Final Message (both log file and screen)
766 // ----------------------------------------
767 LOG << epoData->tt.datestr() << "_" << epoData->tt.timestr(3)
768 << " " << OPT->_roverName
769 << " X = "
770 << setprecision(4) << x() << " +- "
771 << setprecision(4) << sqrt(_QQ(1,1))
772
773 << " Y = "
774 << setprecision(4) << y() << " +- "
775 << setprecision(4) << sqrt(_QQ(2,2))
776
777 << " Z = "
778 << setprecision(4) << z() << " +- "
779 << setprecision(4) << sqrt(_QQ(3,3));
780
781 // NEU Output
782 // ----------
783 if (OPT->xyzAprRoverSet()) {
784 SymmetricMatrix QQxyz = _QQ.SymSubMatrix(1,3);
785
786 ColumnVector xyz(3);
787 xyz(1) = x() - OPT->_xyzAprRover[0];
788 xyz(2) = y() - OPT->_xyzAprRover[1];
789 xyz(3) = z() - OPT->_xyzAprRover[2];
790
791 ColumnVector ellRef(3);
792 xyz2ell(OPT->_xyzAprRover.data(), ellRef.data());
793 xyz2neu(ellRef.data(), xyz.data(), _neu.data());
794
795 SymmetricMatrix QQneu(3);
796 covariXYZ_NEU(QQxyz, ellRef.data(), QQneu);
797
798 LOG << " dN = "
799 << setprecision(4) << _neu[0] << " +- "
800 << setprecision(4) << sqrt(QQneu[0][0])
801
802 << " dE = "
803 << setprecision(4) << _neu[1] << " +- "
804 << setprecision(4) << sqrt(QQneu[1][1])
805
806 << " dU = "
807 << setprecision(4) << _neu[2] << " +- "
808 << setprecision(4) << sqrt(QQneu[2][2]) << endl << endl;
809 }
810 else {
811 LOG << endl << endl;
812 }
813
814 _lastTimeOK = _time; // remember time of last successful update
815 return success;
816}
817
818// Iono combi noise factor
819////////////////////////////////////////////////////////////////////////////
820double ionFac(const QString prn, QMap<QString, t_satData*>& satData) {
821 if (satData.contains(prn))
822 return sqrt(pow(satData.value(prn)->lkA,2) +
823 pow(satData.value(prn)->lkB,2) );
824 else
825 return 0.0;
826};
827
828// Outlier Detection
829////////////////////////////////////////////////////////////////////////////
830QString t_pppFilter::outlierDetection(int iPhase, const ColumnVector& vv,
831 QMap<QString, t_satData*>& satData) {
832
833 Tracer tracer("t_pppFilter::outlierDetection");
834
835 QString prnGPS;
836 QString prnGlo;
837
838 double ionFacGPS;
839 double ionFacGLO;
840
841 double maxResGPS = 0.0; // GPS + Galileo
842 double maxResGlo = 0.0; // GLONASS + BDS
843
844 findMaxRes(vv, satData, prnGPS, prnGlo, maxResGPS, maxResGlo);
845
846 ionFacGLO = ionFac(prnGlo,satData);
847 if (iPhase == 0)
848 ionFacGLO *= (prnGlo[0]=='R'? GLONASS_WEIGHT_FACTOR : BDS_WEIGHT_FACTOR);
849 ionFacGPS = ionFac(prnGPS,satData);
850
851 if (iPhase == 1) {
852 if (maxResGlo > ionFacGLO * OPT->_maxResL1) {
853 LOG << "Outlier Phase " << prnGlo.mid(0,3).toLatin1().data() << ' ' << maxResGlo << endl;
854 return prnGlo;
855 }
856 else if (maxResGPS > ionFacGPS * OPT->_maxResL1) {
857 LOG << "Outlier Phase " << prnGPS.mid(0,3).toLatin1().data() << ' ' << maxResGPS << endl;
858 return prnGPS;
859 }
860 }
861 else if (iPhase == 0) {
862 if (maxResGlo > ionFacGLO * OPT->_maxResC1) {
863 LOG << "Outlier Code " << prnGlo.mid(0,3).toLatin1().data() << ' ' << maxResGlo << endl;
864 return prnGlo;
865 }
866 else if (maxResGPS > ionFacGPS * OPT->_maxResC1) {
867 LOG << "Outlier Code " << prnGPS.mid(0,3).toLatin1().data() << ' ' << maxResGPS << endl;
868 return prnGPS;
869 }
870 }
871
872 return QString();
873}
874
875// Phase Wind-Up Correction
876///////////////////////////////////////////////////////////////////////////
877double t_pppFilter::windUp(const QString& prn, const ColumnVector& rSat,
878 const ColumnVector& rRec) {
879
880 Tracer tracer("t_pppFilter::windUp");
881
882 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
883
884 // First time - initialize to zero
885 // -------------------------------
886 if (!_windUpTime.contains(prn)) {
887 _windUpSum[prn] = 0.0;
888 }
889
890 // Compute the correction for new time
891 // -----------------------------------
892 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
893 _windUpTime[prn] = Mjd;
894
895 // Unit Vector GPS Satellite --> Receiver
896 // --------------------------------------
897 ColumnVector rho = rRec - rSat;
898 rho /= rho.NormFrobenius();
899
900 // GPS Satellite unit Vectors sz, sy, sx
901 // -------------------------------------
902 ColumnVector sz = -rSat / rSat.NormFrobenius();
903
904 ColumnVector xSun = t_astro::Sun(Mjd);
905 xSun /= xSun.NormFrobenius();
906
907 ColumnVector sy = crossproduct(sz, xSun);
908 ColumnVector sx = crossproduct(sy, sz);
909
910 // Effective Dipole of the GPS Satellite Antenna
911 // ---------------------------------------------
912 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
913 - crossproduct(rho, sy);
914
915 // Receiver unit Vectors rx, ry
916 // ----------------------------
917 ColumnVector rx(3);
918 ColumnVector ry(3);
919
920 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
921 double neu[3];
922
923 neu[0] = 1.0;
924 neu[1] = 0.0;
925 neu[2] = 0.0;
926 neu2xyz(recEll, neu, rx.data());
927
928 neu[0] = 0.0;
929 neu[1] = -1.0;
930 neu[2] = 0.0;
931 neu2xyz(recEll, neu, ry.data());
932
933 // Effective Dipole of the Receiver Antenna
934 // ----------------------------------------
935 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
936 + crossproduct(rho, ry);
937
938 // Resulting Effect
939 // ----------------
940 double alpha = DotProduct(dipSat,dipRec) /
941 (dipSat.NormFrobenius() * dipRec.NormFrobenius());
942
943 if (alpha > 1.0) alpha = 1.0;
944 if (alpha < -1.0) alpha = -1.0;
945
946 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
947
948 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
949 dphi = -dphi;
950 }
951
952 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
953 }
954
955 return _windUpSum[prn];
956}
957
958//
959///////////////////////////////////////////////////////////////////////////
960void t_pppFilter::cmpEle(t_satData* satData) {
961 Tracer tracer("t_pppFilter::cmpEle");
962 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
963 double rho = rr.NormFrobenius();
964
965 double neu[3];
966 xyz2neu(_ellBanc.data(), rr.data(), neu);
967
968 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
969 if (neu[2] < 0) {
970 satData->eleSat *= -1.0;
971 }
972 satData->azSat = atan2(neu[1], neu[0]);
973}
974
975//
976///////////////////////////////////////////////////////////////////////////
977void t_pppFilter::addAmb(t_satData* satData) {
978 Tracer tracer("t_pppFilter::addAmb");
979 if (!OPT->ambLCs(satData->system()).size()){
980 return;
981 }
982 bool found = false;
983 for (int iPar = 1; iPar <= _params.size(); iPar++) {
984 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
985 _params[iPar-1]->prn == satData->prn) {
986 found = true;
987 break;
988 }
989 }
990 if (!found) {
991 t_pppParam* par = new t_pppParam(t_pppParam::AMB_L3,
992 _params.size()+1, satData->prn);
993 _params.push_back(par);
994 par->xx = satData->L3 - cmpValue(satData, true);
995 }
996}
997
998//
999///////////////////////////////////////////////////////////////////////////
1000void t_pppFilter::addObs(int iPhase, unsigned& iObs, t_satData* satData,
1001 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1002
1003 Tracer tracer("t_pppFilter::addObs");
1004
1005 const double ELEWGHT = 20.0;
1006 double ellWgtCoef = 1.0;
1007 double eleD = satData->eleSat * 180.0 / M_PI;
1008 if (eleD < ELEWGHT) {
1009 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
1010 }
1011
1012 // Remember Observation Index
1013 // --------------------------
1014 ++iObs;
1015 satData->obsIndex = iObs;
1016
1017 // Iono-free combination noise factor
1018 // ----------------------------------
1019 double ionFac = sqrt(pow(satData->lkA,2) + pow(satData->lkB,2));
1020
1021 // Phase Observations
1022 // ------------------
1023
1024 if (iPhase == 1) {
1025 double sigL3 = ionFac * ellWgtCoef * OPT->_sigmaL1;
1026 if (satData->system() == 'R') {
1027 sigL3 *= GLONASS_WEIGHT_FACTOR;
1028 }
1029 if (satData->system() == 'C') {
1030 sigL3 *= BDS_WEIGHT_FACTOR;
1031 }
1032 satData->L3sig = sigL3;
1033 ll(iObs) = satData->L3 - cmpValue(satData, true);
1034 PP(iObs,iObs) = 1.0 / (sigL3 * sigL3);
1035 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1036 if (_params[iPar-1]->type == t_pppParam::AMB_L3 &&
1037 _params[iPar-1]->prn == satData->prn) {
1038 ll(iObs) -= _params[iPar-1]->xx;
1039 }
1040 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1041 }
1042 }
1043
1044 // Code Observations
1045 // -----------------
1046 else {
1047 double sigP3 = ionFac * ellWgtCoef * OPT->_sigmaC1;
1048 if (satData->system() == 'R') {
1049 sigP3 *= GLONASS_WEIGHT_FACTOR;
1050 }
1051 if (satData->system() == 'C') {
1052 sigP3 *= BDS_WEIGHT_FACTOR;
1053 }
1054 satData->P3sig = sigP3;
1055 ll(iObs) = satData->P3 - cmpValue(satData, false);
1056 PP(iObs,iObs) = 1.0 / (sigP3 * sigP3);
1057 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1058 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1059 }
1060 }
1061}
1062
1063//
1064///////////////////////////////////////////////////////////////////////////
1065QByteArray t_pppFilter::printRes(int iPhase, const ColumnVector& vv,
1066 const QMap<QString, t_satData*>& satDataMap) {
1067
1068 Tracer tracer("t_pppFilter::printRes");
1069
1070 ostringstream str;
1071 str.setf(ios::fixed);
1072 bool useObs;
1073 QMapIterator<QString, t_satData*> it(satDataMap);
1074 while (it.hasNext()) {
1075 it.next();
1076 t_satData* satData = it.value();
1077 (iPhase == 0) ? useObs = OPT->codeLCs(satData->system()).size() :
1078 useObs = OPT->ambLCs(satData->system()).size();
1079 if (satData->obsIndex != 0 && useObs) {
1080 str << _time.datestr() << "_" << _time.timestr(3)
1081 << " RES " << satData->prn.mid(0,3).toLatin1().data()
1082 << (iPhase ? " L3 " : " P3 ")
1083 << setw(9) << setprecision(4) << vv(satData->obsIndex) << " "
1084 << setprecision(3)
1085 << setw(7) << (iPhase? satData->L3sig : satData->P3sig) << " "
1086 << setprecision(1)
1087 << setw(5) <<satData->eleSat * 180 / M_PI
1088 << endl;
1089 }
1090 }
1091
1092 return QByteArray(str.str().c_str());
1093}
1094
1095//
1096///////////////////////////////////////////////////////////////////////////
1097void t_pppFilter::findMaxRes(const ColumnVector& vv,
1098 const QMap<QString, t_satData*>& satData,
1099 QString& prnGPS, QString& prnGlo,
1100 double& maxResGPS, double& maxResGlo) {
1101
1102 Tracer tracer("t_pppFilter::findMaxRes");
1103
1104 maxResGPS = 0.0;
1105 maxResGlo = 0.0;
1106
1107 QMapIterator<QString, t_satData*> it(satData);
1108 while (it.hasNext()) {
1109 it.next();
1110 t_satData* satData = it.value();
1111 if (satData->obsIndex != 0) {
1112 QString prn = satData->prn;
1113 if (prn[0] == 'R' || prn[0] == 'C') {
1114 if (fabs(vv(satData->obsIndex)) > maxResGlo) {
1115 maxResGlo = fabs(vv(satData->obsIndex));
1116 prnGlo = prn;
1117 }
1118 }
1119 else {
1120 if (fabs(vv(satData->obsIndex)) > maxResGPS) {
1121 maxResGPS = fabs(vv(satData->obsIndex));
1122 prnGPS = prn;
1123 }
1124 }
1125 }
1126 }
1127}
1128
1129// Update Step (private - loop over outliers)
1130////////////////////////////////////////////////////////////////////////////
1131t_irc t_pppFilter::update_p(t_epoData* epoData) {
1132
1133 Tracer tracer("t_pppFilter::update_p");
1134
1135 // Save Variance-Covariance Matrix, and Status Vector
1136 // --------------------------------------------------
1137 rememberState(epoData);
1138
1139 QString lastOutlierPrn;
1140
1141 // Try with all satellites, then with all minus one, etc.
1142 // ------------------------------------------------------
1143 while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
1144
1145 QByteArray strResCode;
1146 QByteArray strResPhase;
1147
1148 // Bancroft Solution
1149 // -----------------
1150 if (cmpBancroft(epoData) != success) {
1151 break;
1152 }
1153
1154 // First update using code observations, then phase observations
1155 // -------------------------------------------------------------
1156 bool usePhase = OPT->ambLCs('G').size() || OPT->ambLCs('R').size() ||
1157 OPT->ambLCs('E').size() || OPT->ambLCs('C').size() ;
1158
1159 char sys[] ={'G', 'R', 'E', 'C'};
1160
1161 bool satnumPrinted[] = {false, false, false, false};
1162
1163 for (int iPhase = 0; iPhase <= (usePhase ? 1 : 0); iPhase++) {
1164
1165 // Status Prediction
1166 // -----------------
1167 predict(iPhase, epoData);
1168
1169 // Create First-Design Matrix
1170 // --------------------------
1171 unsigned nPar = _params.size();
1172 unsigned nObs = 0;
1173 nObs = epoData->sizeAll();
1174 bool useObs = false;
1175 for (unsigned ii = 0; ii < sizeof(sys); ii++) {
1176 const char s = sys[ii];
1177 (iPhase == 0) ? useObs = OPT->codeLCs(s).size() : useObs = OPT->ambLCs(s).size();
1178 if (!useObs) {
1179 nObs -= epoData->sizeSys(s);
1180 }
1181 else {
1182 if (!satnumPrinted[ii]) {
1183 satnumPrinted[ii] = true;
1184 LOG << _time.datestr() << "_" << _time.timestr(3)
1185 << " SATNUM " << s << ' ' << right << setw(2)
1186 << epoData->sizeSys(s) << endl;
1187 }
1188 }
1189 }
1190
1191 if (int(nObs) < OPT->_minObs) {
1192 restoreState(epoData);
1193 return failure;
1194 }
1195
1196 // Prepare first-design Matrix, vector observed-computed
1197 // -----------------------------------------------------
1198 Matrix AA(nObs, nPar); // first design matrix
1199 ColumnVector ll(nObs); // terms observed-computed
1200 DiagonalMatrix PP(nObs); PP = 0.0;
1201
1202 unsigned iObs = 0;
1203 QMapIterator<QString, t_satData*> it(epoData->satData);
1204
1205 while (it.hasNext()) {
1206 it.next();
1207 t_satData* satData = it.value();
1208 QString prn = satData->prn;
1209 (iPhase == 0) ? useObs = OPT->codeLCs(satData->system()).size() :
1210 useObs = OPT->ambLCs(satData->system()).size();
1211 if (useObs) {
1212 addObs(iPhase, iObs, satData, AA, ll, PP);
1213 } else {
1214 satData->obsIndex = 0;
1215 }
1216 }
1217
1218 // Compute Filter Update
1219 // ---------------------
1220 ColumnVector dx(nPar); dx = 0.0;
1221 kalman(AA, ll, PP, _QQ, dx);
1222 ColumnVector vv = ll - AA * dx;
1223
1224 // Print Residuals
1225 // ---------------
1226 if (iPhase == 0) {
1227 strResCode = printRes(iPhase, vv, epoData->satData);
1228 }
1229 else {
1230 strResPhase = printRes(iPhase, vv, epoData->satData);
1231 }
1232
1233 // Check the residuals
1234 // -------------------
1235 lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
1236
1237 // No Outlier Detected
1238 // -------------------
1239 if (lastOutlierPrn.isEmpty()) {
1240
1241 QVectorIterator<t_pppParam*> itPar(_params);
1242 while (itPar.hasNext()) {
1243 t_pppParam* par = itPar.next();
1244 par->xx += dx(par->index);
1245 }
1246
1247 if (!usePhase || iPhase == 1) {
1248 if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
1249 LOG << "Neglected PRNs: ";
1250 if (!_outlierGPS.isEmpty()) {
1251 LOG << _outlierGPS.last().mid(0,3).toLatin1().data() << ' ';
1252 }
1253 QStringListIterator itGlo(_outlierGlo);
1254 while (itGlo.hasNext()) {
1255 QString prn = itGlo.next();
1256 LOG << prn.mid(0,3).toLatin1().data() << ' ';
1257 }
1258 LOG << endl;
1259 }
1260 LOG << strResCode.data() << strResPhase.data();
1261
1262 return success;
1263 }
1264 }
1265
1266 // Outlier Found
1267 // -------------
1268 else {
1269 restoreState(epoData);
1270 break;
1271 }
1272
1273 } // for iPhase
1274
1275 } // while selectSatellites
1276
1277 restoreState(epoData);
1278 return failure;
1279}
1280
1281// Remember Original State Vector and Variance-Covariance Matrix
1282////////////////////////////////////////////////////////////////////////////
1283void t_pppFilter::rememberState(t_epoData* epoData) {
1284
1285 _QQ_sav = _QQ;
1286
1287 QVectorIterator<t_pppParam*> itSav(_params_sav);
1288 while (itSav.hasNext()) {
1289 t_pppParam* par = itSav.next();
1290 delete par;
1291 }
1292 _params_sav.clear();
1293
1294 QVectorIterator<t_pppParam*> it(_params);
1295 while (it.hasNext()) {
1296 t_pppParam* par = it.next();
1297 _params_sav.push_back(new t_pppParam(*par));
1298 }
1299
1300 _epoData_sav->deepCopy(epoData);
1301}
1302
1303// Restore Original State Vector and Variance-Covariance Matrix
1304////////////////////////////////////////////////////////////////////////////
1305void t_pppFilter::restoreState(t_epoData* epoData) {
1306
1307 _QQ = _QQ_sav;
1308
1309 QVectorIterator<t_pppParam*> it(_params);
1310 while (it.hasNext()) {
1311 t_pppParam* par = it.next();
1312 delete par;
1313 }
1314 _params.clear();
1315
1316 QVectorIterator<t_pppParam*> itSav(_params_sav);
1317 while (itSav.hasNext()) {
1318 t_pppParam* par = itSav.next();
1319 _params.push_back(new t_pppParam(*par));
1320 }
1321
1322 epoData->deepCopy(_epoData_sav);
1323}
1324
1325//
1326////////////////////////////////////////////////////////////////////////////
1327t_irc t_pppFilter::selectSatellites(const QString& lastOutlierPrn,
1328 QMap<QString, t_satData*>& satData) {
1329
1330 // First Call
1331 // ----------
1332 if (lastOutlierPrn.isEmpty()) {
1333 _outlierGPS.clear();
1334 _outlierGlo.clear();
1335 return success;
1336 }
1337
1338 // Second and next trials
1339 // ----------------------
1340 else {
1341
1342 if (lastOutlierPrn[0] == 'R' || lastOutlierPrn[0] == 'C') {
1343 _outlierGlo << lastOutlierPrn;
1344 }
1345
1346 // Remove all Glonass Outliers
1347 // ---------------------------
1348 QStringListIterator it(_outlierGlo);
1349 while (it.hasNext()) {
1350 QString prn = it.next();
1351 if (satData.contains(prn)) {
1352 delete satData.take(prn);
1353 }
1354 }
1355
1356 if (lastOutlierPrn[0] == 'R' || lastOutlierPrn[0] == 'C') {
1357 _outlierGPS.clear();
1358 return success;
1359 }
1360
1361 // GPS Outlier appeared for the first time - try to delete it
1362 // ----------------------------------------------------------
1363 if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
1364 _outlierGPS << lastOutlierPrn;
1365 if (satData.contains(lastOutlierPrn)) {
1366 delete satData.take(lastOutlierPrn);
1367 }
1368 return success;
1369 }
1370
1371 }
1372
1373 return failure;
1374}
1375
1376//
1377////////////////////////////////////////////////////////////////////////////
1378double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
1379 return aa(1)*bb(1) + aa(2)*bb(2) + aa(3)*bb(3) - aa(4)*bb(4);
1380}
1381
1382//
1383////////////////////////////////////////////////////////////////////////////
1384void t_pppFilter::bancroft(const Matrix& BBpass, ColumnVector& pos) {
1385
1386 if (pos.Nrows() != 4) {
1387 pos.ReSize(4);
1388 }
1389 pos = 0.0;
1390
1391 for (int iter = 1; iter <= 2; iter++) {
1392 Matrix BB = BBpass;
1393 int mm = BB.Nrows();
1394 for (int ii = 1; ii <= mm; ii++) {
1395 double xx = BB(ii,1);
1396 double yy = BB(ii,2);
1397 double traveltime = 0.072;
1398 if (iter > 1) {
1399 double zz = BB(ii,3);
1400 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
1401 (yy-pos(2)) * (yy-pos(2)) +
1402 (zz-pos(3)) * (zz-pos(3)) );
1403 traveltime = rho / t_CST::c;
1404 }
1405 double angle = traveltime * t_CST::omega;
1406 double cosa = cos(angle);
1407 double sina = sin(angle);
1408 BB(ii,1) = cosa * xx + sina * yy;
1409 BB(ii,2) = -sina * xx + cosa * yy;
1410 }
1411
1412 Matrix BBB;
1413 if (mm > 4) {
1414 SymmetricMatrix hlp; hlp << BB.t() * BB;
1415 BBB = hlp.i() * BB.t();
1416 }
1417 else {
1418 BBB = BB.i();
1419 }
1420 ColumnVector ee(mm); ee = 1.0;
1421 ColumnVector alpha(mm); alpha = 0.0;
1422 for (int ii = 1; ii <= mm; ii++) {
1423 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
1424 }
1425 ColumnVector BBBe = BBB * ee;
1426 ColumnVector BBBalpha = BBB * alpha;
1427 double aa = lorentz(BBBe, BBBe);
1428 double bb = lorentz(BBBe, BBBalpha)-1;
1429 double cc = lorentz(BBBalpha, BBBalpha);
1430 double root = sqrt(bb*bb-aa*cc);
1431
1432 Matrix hlpPos(4,2);
1433 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
1434 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
1435
1436 ColumnVector omc(2);
1437 for (int pp = 1; pp <= 2; pp++) {
1438 hlpPos(4,pp) = -hlpPos(4,pp);
1439 omc(pp) = BB(1,4) -
1440 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
1441 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
1442 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
1443 hlpPos(4,pp);
1444 }
1445 if ( fabs(omc(1)) > fabs(omc(2)) ) {
1446 pos = hlpPos.Column(2);
1447 }
1448 else {
1449 pos = hlpPos.Column(1);
1450 }
1451 }
1452}
1453
1454//
1455////////////////////////////////////////////////////////////////////////////
1456void t_pppFilter::cmpDOP(t_epoData* epoData) {
1457
1458 Tracer tracer("t_pppFilter::cmpDOP");
1459
1460 _numSat = 0;
1461 _hDop = 0.0;
1462
1463 if (_params.size() < 4) {
1464 return;
1465 }
1466
1467 const unsigned numPar = 4;
1468 Matrix AA(epoData->sizeAll(), numPar);
1469 QMapIterator<QString, t_satData*> it(epoData->satData);
1470 while (it.hasNext()) {
1471 it.next();
1472 t_satData* satData = it.value();
1473 _numSat += 1;
1474 for (unsigned iPar = 0; iPar < numPar; iPar++) {
1475 AA[_numSat-1][iPar] = _params[iPar]->partial(satData, false);
1476 }
1477 }
1478 if (_numSat < 4) {
1479 return;
1480 }
1481 AA = AA.Rows(1, _numSat);
1482 SymmetricMatrix NN; NN << AA.t() * AA;
1483 SymmetricMatrix QQ = NN.i();
1484
1485 _hDop = sqrt(QQ(1,1) + QQ(2,2));
1486}
Note: See TracBrowser for help on using the repository browser.