source: ntrip/trunk/BNC/bncmodel.cpp@ 2781

Last change on this file since 2781 was 2781, checked in by mervart, 13 years ago
File size: 39.1 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: bncParam, bncModel
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 <newmatio.h>
44#include <sstream>
45
46#include "bncmodel.h"
47#include "bncapp.h"
48#include "bncpppclient.h"
49#include "bancroft.h"
50#include "bncutils.h"
51#include "bncsettings.h"
52#include "bnctides.h"
53
54using namespace std;
55
56const unsigned MINOBS = 4;
57const double MINELE_GPS = 10.0 * M_PI / 180.0;
58const double MINELE_GLO = 10.0 * M_PI / 180.0;
59const double MINELE_GAL = 10.0 * M_PI / 180.0;
60const double MAXRES_CODE_GPS = 10.0;
61const double MAXRES_PHASE_GPS = 0.10;
62const double MAXRES_PHASE_GLO = 0.05;
63const double MAXRES_CODE_GAL = 9999.0;
64const double MAXRES_PHASE_GAL = 9999.10;
65
66const double _sigP3_gal = 9999.0;
67const double _sigL3_gal = 0.10;
68
69// Constructor
70////////////////////////////////////////////////////////////////////////////
71bncParam::bncParam(bncParam::parType typeIn, int indexIn,
72 const QString& prnIn) {
73 type = typeIn;
74 index = indexIn;
75 prn = prnIn;
76 index_old = 0;
77 xx = 0.0;
78
79}
80
81// Destructor
82////////////////////////////////////////////////////////////////////////////
83bncParam::~bncParam() {
84}
85
86// Partial
87////////////////////////////////////////////////////////////////////////////
88double bncParam::partial(t_satData* satData, bool phase) {
89
90 // Coordinates
91 // -----------
92 if (type == CRD_X) {
93 return (xx - satData->xx(1)) / satData->rho;
94 }
95 else if (type == CRD_Y) {
96 return (xx - satData->xx(2)) / satData->rho;
97 }
98 else if (type == CRD_Z) {
99 return (xx - satData->xx(3)) / satData->rho;
100 }
101
102 // Receiver Clocks
103 // ---------------
104 else if (type == RECCLK) {
105 return 1.0;
106 }
107
108 // Troposphere
109 // -----------
110 else if (type == TROPO) {
111 return 1.0 / sin(satData->eleSat);
112 }
113
114 // Ambiguities
115 // -----------
116 else if (type == AMB_L3) {
117 if (phase && satData->prn == prn) {
118 return 1.0;
119 }
120 else {
121 return 0.0;
122 }
123 }
124
125 // Default return
126 // --------------
127 return 0.0;
128}
129
130// Constructor
131////////////////////////////////////////////////////////////////////////////
132bncModel::bncModel(QByteArray staID) {
133
134 _staID = staID;
135
136 bncSettings settings;
137
138 // Observation Sigmas
139 // ------------------
140 _sigP3 = 5.0;
141 if (!settings.value("pppSigmaCode").toString().isEmpty()) {
142 _sigP3 = settings.value("pppSigmaCode").toDouble();
143 }
144 _sigL3 = 0.02;
145 if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
146 _sigL3 = settings.value("pppSigmaPhase").toDouble();
147 }
148
149 // Parameter Sigmas
150 // ----------------
151 _sigCrd0 = 100.0;
152 if (!settings.value("pppSigCrd0").toString().isEmpty()) {
153 _sigCrd0 = settings.value("pppSigCrd0").toDouble();
154 }
155 _sigCrdP = 100.0;
156 if (!settings.value("pppSigCrdP").toString().isEmpty()) {
157 _sigCrdP = settings.value("pppSigCrdP").toDouble();
158 }
159 _sigTrp0 = 0.1;
160 if (!settings.value("pppSigTrp0").toString().isEmpty()) {
161 _sigTrp0 = settings.value("pppSigTrp0").toDouble();
162 }
163 _sigTrpP = 1e-6;
164 if (!settings.value("pppSigTrpP").toString().isEmpty()) {
165 _sigTrpP = settings.value("pppSigTrpP").toDouble();
166 }
167 _sigClk0 = 1000.0;
168 _sigAmb0 = 1000.0;
169
170 // Quick-Start Mode
171 // ----------------
172 _quickStart = 0;
173 if (settings.value("pppRefCrdX").toString() != "" &&
174 settings.value("pppRefCrdY").toString() != "" &&
175 settings.value("pppRefCrdZ").toString() != "" &&
176 !settings.value("pppQuickStart").toString().isEmpty()) {
177 _quickStart = settings.value("pppQuickStart").toDouble();
178 }
179
180 connect(this, SIGNAL(newMessage(QByteArray,bool)),
181 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
182
183 _usePhase = false;
184 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
185 _usePhase = true;
186 }
187
188 _estTropo = false;
189 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
190 _estTropo = true;
191 }
192
193 _xcBanc.ReSize(4); _xcBanc = 0.0;
194 _ellBanc.ReSize(3); _ellBanc = 0.0;
195
196 if (_usePhase &&
197 Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
198 _useGlonass = true;
199 }
200 else {
201 _useGlonass = false;
202 }
203
204 _useGalileo = true; // TODO
205
206 int nextPar = 0;
207 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
208 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
209 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
210 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
211 if (_estTropo) {
212 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
213 }
214
215 unsigned nPar = _params.size();
216
217 _QQ.ReSize(nPar);
218
219 _QQ = 0.0;
220
221 for (int iPar = 1; iPar <= _params.size(); iPar++) {
222 bncParam* pp = _params[iPar-1];
223 if (pp->isCrd()) {
224 _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
225 }
226 else if (pp->type == bncParam::RECCLK) {
227 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
228 }
229 else if (pp->type == bncParam::TROPO) {
230 _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
231 }
232 }
233
234 // NMEA Output
235 // -----------
236 QString nmeaFileName = settings.value("nmeaFile").toString();
237 if (nmeaFileName.isEmpty()) {
238 _nmeaFile = 0;
239 _nmeaStream = 0;
240 }
241 else {
242 expandEnvVar(nmeaFileName);
243 _nmeaFile = new QFile(nmeaFileName);
244 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
245 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
246 }
247 else {
248 _nmeaFile->open(QIODevice::WriteOnly);
249 }
250 _nmeaStream = new QTextStream();
251 _nmeaStream->setDevice(_nmeaFile);
252 }
253}
254
255// Destructor
256////////////////////////////////////////////////////////////////////////////
257bncModel::~bncModel() {
258 delete _nmeaStream;
259 delete _nmeaFile;
260 for (int ii = 0; ii < _posAverage.size(); ++ii) {
261 delete _posAverage[ii];
262 }
263}
264
265// Bancroft Solution
266////////////////////////////////////////////////////////////////////////////
267t_irc bncModel::cmpBancroft(t_epoData* epoData) {
268
269 if (epoData->sizeGPS() < MINOBS) {
270 _log += "bncModel::cmpBancroft: not enough data\n";
271 return failure;
272 }
273
274 Matrix BB(epoData->sizeGPS(), 4);
275
276 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
277 int iObs = 0;
278 while (it.hasNext()) {
279 ++iObs;
280 it.next();
281 QString prn = it.key();
282 t_satData* satData = it.value();
283 BB(iObs, 1) = satData->xx(1);
284 BB(iObs, 2) = satData->xx(2);
285 BB(iObs, 3) = satData->xx(3);
286 BB(iObs, 4) = satData->P3 + satData->clk;
287 }
288
289 bancroft(BB, _xcBanc);
290
291 // Ellipsoidal Coordinates
292 // ------------------------
293 xyz2ell(_xcBanc.data(), _ellBanc.data());
294
295 // Compute Satellite Elevations
296 // ----------------------------
297 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
298 while (iGPS.hasNext()) {
299 iGPS.next();
300 QString prn = iGPS.key();
301 t_satData* satData = iGPS.value();
302
303 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
304 double rho = rr.norm_Frobenius();
305
306 double neu[3];
307 xyz2neu(_ellBanc.data(), rr.data(), neu);
308
309 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
310 if (neu[2] < 0) {
311 satData->eleSat *= -1.0;
312 }
313 satData->azSat = atan2(neu[1], neu[0]);
314
315 if (satData->eleSat < MINELE_GPS) {
316 delete satData;
317 iGPS.remove();
318 }
319 }
320
321 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
322 while (iGlo.hasNext()) {
323 iGlo.next();
324 QString prn = iGlo.key();
325 t_satData* satData = iGlo.value();
326
327 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
328 double rho = rr.norm_Frobenius();
329
330 double neu[3];
331 xyz2neu(_ellBanc.data(), rr.data(), neu);
332
333 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
334 if (neu[2] < 0) {
335 satData->eleSat *= -1.0;
336 }
337 satData->azSat = atan2(neu[1], neu[0]);
338
339 if (satData->eleSat < MINELE_GLO) {
340 delete satData;
341 iGlo.remove();
342 }
343 }
344
345 QMutableMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
346 while (iGal.hasNext()) {
347 iGal.next();
348 QString prn = iGal.key();
349 t_satData* satData = iGal.value();
350
351 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
352 double rho = rr.norm_Frobenius();
353
354 double neu[3];
355 xyz2neu(_ellBanc.data(), rr.data(), neu);
356
357 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
358 if (neu[2] < 0) {
359 satData->eleSat *= -1.0;
360 }
361 satData->azSat = atan2(neu[1], neu[0]);
362
363 if (satData->eleSat < MINELE_GAL) {
364 delete satData;
365 iGal.remove();
366 }
367 }
368
369 return success;
370}
371
372// Computed Value
373////////////////////////////////////////////////////////////////////////////
374double bncModel::cmpValue(t_satData* satData, bool phase) {
375
376 ColumnVector xRec(3);
377 xRec(1) = x();
378 xRec(2) = y();
379 xRec(3) = z();
380
381 double rho0 = (satData->xx - xRec).norm_Frobenius();
382 double dPhi = t_CST::omega * rho0 / t_CST::c;
383
384 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
385 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
386 xRec(3) = z();
387
388 tides(_time, xRec);
389
390 satData->rho = (satData->xx - xRec).norm_Frobenius();
391
392 double tropDelay = delay_saast(satData->eleSat) +
393 trp() / sin(satData->eleSat);
394
395 double wind = 0.0;
396 if (phase) {
397 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
398 }
399
400 return satData->rho + clk() - satData->clk + tropDelay + wind;
401}
402
403// Tropospheric Model (Saastamoinen)
404////////////////////////////////////////////////////////////////////////////
405double bncModel::delay_saast(double Ele) {
406
407 double xyz[3];
408 xyz[0] = x();
409 xyz[1] = y();
410 xyz[2] = z();
411 double ell[3];
412 xyz2ell(xyz, ell);
413 double height = ell[2];
414
415 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
416 double TT = 18.0 - height * 0.0065 + 273.15;
417 double hh = 50.0 * exp(-6.396e-4 * height);
418 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
419
420 double h_km = height / 1000.0;
421
422 if (h_km < 0.0) h_km = 0.0;
423 if (h_km > 5.0) h_km = 5.0;
424 int ii = int(h_km + 1);
425 double href = ii - 1;
426
427 double bCor[6];
428 bCor[0] = 1.156;
429 bCor[1] = 1.006;
430 bCor[2] = 0.874;
431 bCor[3] = 0.757;
432 bCor[4] = 0.654;
433 bCor[5] = 0.563;
434
435 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
436
437 double zen = M_PI/2.0 - Ele;
438
439 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
440}
441
442// Prediction Step of the Filter
443////////////////////////////////////////////////////////////////////////////
444void bncModel::predict(t_epoData* epoData) {
445
446 bncSettings settings;
447
448 bool firstCrd = false;
449 if (x() == 0.0 && y() == 0.0 && z() == 0.0) {
450 firstCrd = true;
451 _startTime = QDateTime::currentDateTime();
452 }
453
454 // Use different white noise for Quick-Start mode
455 // ----------------------------------------------
456 double sigCrdP_used = _sigCrdP;
457 if ( _quickStart > 0.0 &&
458 _quickStart > _startTime.secsTo(QDateTime::currentDateTime()) ) {
459 sigCrdP_used = 0.0;
460 }
461
462 // Predict Parameter values, add white noise
463 // -----------------------------------------
464 for (int iPar = 1; iPar <= _params.size(); iPar++) {
465 bncParam* pp = _params[iPar-1];
466
467 // Coordinates
468 // -----------
469 if (pp->type == bncParam::CRD_X) {
470 if (firstCrd) {
471 if (settings.value("pppRefCrdX").toString() != "" &&
472 settings.value("pppRefCrdY").toString() != "" &&
473 settings.value("pppRefCrdZ").toString() != "") {
474 pp->xx = settings.value("pppRefCrdX").toDouble();
475 }
476 else {
477 pp->xx = _xcBanc(1);
478 }
479 }
480 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
481 }
482 else if (pp->type == bncParam::CRD_Y) {
483 if (firstCrd) {
484 if (settings.value("pppRefCrdX").toString() != "" &&
485 settings.value("pppRefCrdY").toString() != "" &&
486 settings.value("pppRefCrdZ").toString() != "") {
487 pp->xx = settings.value("pppRefCrdY").toDouble();
488 }
489 else {
490 pp->xx = _xcBanc(2);
491 }
492 }
493 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
494 }
495 else if (pp->type == bncParam::CRD_Z) {
496 if (firstCrd) {
497 if (settings.value("pppRefCrdX").toString() != "" &&
498 settings.value("pppRefCrdY").toString() != "" &&
499 settings.value("pppRefCrdZ").toString() != "") {
500 pp->xx = settings.value("pppRefCrdZ").toDouble();
501 }
502 else {
503 pp->xx = _xcBanc(3);
504 }
505 }
506 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
507 }
508
509 // Receiver Clocks
510 // ---------------
511 else if (pp->type == bncParam::RECCLK) {
512 pp->xx = _xcBanc(4);
513 for (int jj = 1; jj <= _params.size(); jj++) {
514 _QQ(iPar, jj) = 0.0;
515 }
516 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
517 }
518
519 // Tropospheric Delay
520 // ------------------
521 else if (pp->type == bncParam::TROPO) {
522 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
523 }
524 }
525
526 // Add New Ambiguities if necessary
527 // --------------------------------
528 if (_usePhase) {
529
530 // Make a copy of QQ and xx, set parameter indices
531 // -----------------------------------------------
532 SymmetricMatrix QQ_old = _QQ;
533
534 for (int iPar = 1; iPar <= _params.size(); iPar++) {
535 _params[iPar-1]->index_old = _params[iPar-1]->index;
536 _params[iPar-1]->index = 0;
537 }
538
539 // Remove Ambiguity Parameters without observations
540 // ------------------------------------------------
541 int iPar = 0;
542 QMutableVectorIterator<bncParam*> it(_params);
543 while (it.hasNext()) {
544 bncParam* par = it.next();
545 bool removed = false;
546 if (par->type == bncParam::AMB_L3) {
547 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
548 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
549 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
550 removed = true;
551 delete par;
552 it.remove();
553 }
554 }
555 if (! removed) {
556 ++iPar;
557 par->index = iPar;
558 }
559 }
560
561 // Add new ambiguity parameters
562 // ----------------------------
563 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
564 while (iGPS.hasNext()) {
565 iGPS.next();
566 QString prn = iGPS.key();
567 t_satData* satData = iGPS.value();
568 bool found = false;
569 for (int iPar = 1; iPar <= _params.size(); iPar++) {
570 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
571 _params[iPar-1]->prn == prn) {
572 found = true;
573 break;
574 }
575 }
576 if (!found) {
577 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
578 _params.push_back(par);
579 par->xx = satData->L3 - cmpValue(satData, true);
580 }
581 }
582
583 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
584 while (iGlo.hasNext()) {
585 iGlo.next();
586 QString prn = iGlo.key();
587 t_satData* satData = iGlo.value();
588 bool found = false;
589 for (int iPar = 1; iPar <= _params.size(); iPar++) {
590 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
591 _params[iPar-1]->prn == prn) {
592 found = true;
593 break;
594 }
595 }
596 if (!found) {
597 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
598 _params.push_back(par);
599 par->xx = satData->L3 - cmpValue(satData, true);
600 }
601 }
602
603 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
604 while (iGal.hasNext()) {
605 iGal.next();
606 QString prn = iGal.key();
607 t_satData* satData = iGal.value();
608 bool found = false;
609 for (int iPar = 1; iPar <= _params.size(); iPar++) {
610 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
611 _params[iPar-1]->prn == prn) {
612 found = true;
613 break;
614 }
615 }
616 if (!found) {
617 bncParam* par = new bncParam(bncParam::AMB_L3, _params.size()+1, prn);
618 _params.push_back(par);
619 par->xx = satData->L3 - cmpValue(satData, true);
620 }
621 }
622
623 int nPar = _params.size();
624 _QQ.ReSize(nPar); _QQ = 0.0;
625 for (int i1 = 1; i1 <= nPar; i1++) {
626 bncParam* p1 = _params[i1-1];
627 if (p1->index_old != 0) {
628 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
629 for (int i2 = 1; i2 <= nPar; i2++) {
630 bncParam* p2 = _params[i2-1];
631 if (p2->index_old != 0) {
632 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
633 }
634 }
635 }
636 }
637
638 for (int ii = 1; ii <= nPar; ii++) {
639 bncParam* par = _params[ii-1];
640 if (par->index_old == 0) {
641 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
642 }
643 par->index_old = par->index;
644 }
645 }
646}
647
648// Update Step of the Filter (currently just a single-epoch solution)
649////////////////////////////////////////////////////////////////////////////
650t_irc bncModel::update(t_epoData* epoData) {
651
652 bncSettings settings;
653
654 _log.clear();
655
656 _time = epoData->tt;
657
658 _log += "Single Point Positioning of Epoch "
659 + QByteArray(_time.timestr(1).c_str()) +
660 "\n--------------------------------------------------------------\n";
661
662 SymmetricMatrix QQsav;
663 ColumnVector dx;
664 ColumnVector vv;
665
666 // Loop over all outliers
667 // ----------------------
668 do {
669
670 // Bancroft Solution
671 // -----------------
672 if (cmpBancroft(epoData) != success) {
673 emit newMessage(_log, false);
674 return failure;
675 }
676
677 // Status Prediction
678 // -----------------
679 predict(epoData);
680
681 // Create First-Design Matrix
682 // --------------------------
683 unsigned nPar = _params.size();
684 unsigned nObs = 0;
685 if (_usePhase) {
686 nObs = 2 * (epoData->sizeGPS() + epoData->sizeGal()) + epoData->sizeGlo();
687 }
688 else {
689 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
690 }
691
692 if (nObs < nPar) {
693 _log += "bncModel::update: nObs < nPar\n";
694 emit newMessage(_log, false);
695 return failure;
696 }
697
698 Matrix AA(nObs, nPar); // first design matrix
699 ColumnVector ll(nObs); // tems observed-computed
700 DiagonalMatrix PP(nObs); PP = 0.0;
701
702 unsigned iObs = 0;
703
704 // GPS code and (optionally) phase observations
705 // --------------------------------------------
706 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
707 while (itGPS.hasNext()) {
708 ++iObs;
709 itGPS.next();
710 QString prn = itGPS.key();
711 t_satData* satData = itGPS.value();
712
713 ll(iObs) = satData->P3 - cmpValue(satData, false);
714 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
715 for (int iPar = 1; iPar <= _params.size(); iPar++) {
716 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
717 }
718
719 if (_usePhase) {
720 ++iObs;
721 ll(iObs) = satData->L3 - cmpValue(satData, true);
722 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
723 for (int iPar = 1; iPar <= _params.size(); iPar++) {
724 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
725 _params[iPar-1]->prn == prn) {
726 ll(iObs) -= _params[iPar-1]->xx;
727 }
728 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
729 }
730 }
731 }
732
733 // Glonass phase observations
734 // --------------------------
735 if (_usePhase) {
736 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
737 while (itGlo.hasNext()) {
738 ++iObs;
739 itGlo.next();
740 QString prn = itGlo.key();
741 t_satData* satData = itGlo.value();
742
743 ll(iObs) = satData->L3 - cmpValue(satData, true);
744 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
745 for (int iPar = 1; iPar <= _params.size(); iPar++) {
746 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
747 _params[iPar-1]->prn == prn) {
748 ll(iObs) -= _params[iPar-1]->xx;
749 }
750 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
751 }
752 }
753 }
754
755 // Galileo code and (optionally) phase observations
756 // ------------------------------------------------
757 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
758 while (itGal.hasNext()) {
759 ++iObs;
760 itGal.next();
761 QString prn = itGal.key();
762 t_satData* satData = itGal.value();
763
764 ll(iObs) = satData->P3 - cmpValue(satData, false);
765 PP(iObs,iObs) = 1.0 / (_sigP3_gal * _sigP3_gal);
766 for (int iPar = 1; iPar <= _params.size(); iPar++) {
767 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
768 }
769
770 if (_usePhase) {
771 ++iObs;
772 ll(iObs) = satData->L3 - cmpValue(satData, true);
773 PP(iObs,iObs) = 1.0 / (_sigL3_gal * _sigL3_gal);
774 for (int iPar = 1; iPar <= _params.size(); iPar++) {
775 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
776 _params[iPar-1]->prn == prn) {
777 ll(iObs) -= _params[iPar-1]->xx;
778 }
779 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
780 }
781 }
782 }
783
784 // Compute Filter Update
785 // ---------------------
786 QQsav = _QQ;
787
788 kalman(AA, ll, PP, _QQ, dx);
789
790 vv = ll - AA * dx;
791
792 ostringstream strA;
793 strA.setf(ios::fixed);
794 ColumnVector vv_code(epoData->sizeGPS());
795 ColumnVector vv_phase(epoData->sizeGPS());
796 ColumnVector vv_glo(epoData->sizeGlo());
797 ColumnVector vv_gal_code(epoData->sizeGal());
798 ColumnVector vv_gal_phase(epoData->sizeGal());
799
800 for (unsigned iobs = 1; iobs <= epoData->sizeGPS(); ++iobs) {
801 if (_usePhase) {
802 vv_code(iobs) = vv(2*iobs-1);
803 vv_phase(iobs) = vv(2*iobs);
804 }
805 else {
806 vv_code(iobs) = vv(iobs);
807 }
808 }
809 if (_useGlonass) {
810 for (unsigned iobs = 1; iobs <= epoData->sizeGlo(); ++iobs) {
811 vv_glo(iobs) = vv(2*epoData->sizeGPS()+iobs);
812 }
813 }
814 if (_useGalileo) {
815 for (unsigned iobs = 1; iobs <= epoData->sizeGal(); ++iobs) {
816 if (_usePhase) {
817 vv_gal_code(iobs) = vv(2*iobs-1);
818 vv_gal_phase(iobs) = vv(2*iobs);
819 }
820 else {
821 vv_gal_code(iobs) = vv(iobs);
822 }
823 }
824 }
825
826 strA << "residuals code " << setw(8) << setprecision(3) << vv_code.t();
827 if (_usePhase) {
828 strA << "residuals phase " << setw(8) << setprecision(3) << vv_phase.t();
829 }
830 if (_useGlonass) {
831 strA << "residuals glo " << setw(8) << setprecision(3) << vv_glo.t();
832 }
833 if (_useGalileo) {
834 strA << "res Galileo P " << setw(8) << setprecision(3) << vv_gal_code.t();
835 if (_usePhase) {
836 strA << "res Galileo C " << setw(8) << setprecision(3) << vv_gal_phase.t();
837 }
838 }
839 _log += strA.str().c_str();
840
841 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
842 epoData->satDataGlo, epoData->satDataGal) != 0);
843
844 // Remember the Epoch-specific Results for the computation of means
845 // ----------------------------------------------------------------
846 pppPos* newPos = new pppPos;
847 newPos->time = epoData->tt;
848
849 // Set Solution Vector
850 // -------------------
851 ostringstream strB;
852 strB.setf(ios::fixed);
853 QVectorIterator<bncParam*> itPar(_params);
854 while (itPar.hasNext()) {
855 bncParam* par = itPar.next();
856 par->xx += dx(par->index);
857
858 if (par->type == bncParam::RECCLK) {
859 strB << "\n clk = " << setw(6) << setprecision(3) << par->xx
860 << " +- " << setw(6) << setprecision(3)
861 << sqrt(_QQ(par->index,par->index));
862 }
863 else if (par->type == bncParam::AMB_L3) {
864 strB << "\n amb " << par->prn.toAscii().data() << " = "
865 << setw(6) << setprecision(3) << par->xx
866 << " +- " << setw(6) << setprecision(3)
867 << sqrt(_QQ(par->index,par->index));
868 }
869 else if (par->type == bncParam::TROPO) {
870 double aprTrp = delay_saast(M_PI/2.0);
871 strB << "\n trp = " << par->prn.toAscii().data()
872 << setw(7) << setprecision(3) << aprTrp << " "
873 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
874 << " +- " << setw(6) << setprecision(3)
875 << sqrt(_QQ(par->index,par->index));
876 newPos->xnt[6] = aprTrp + par->xx;
877 }
878 }
879 strB << '\n';
880 _log += strB.str().c_str();
881 emit newMessage(_log, false);
882
883 // Final Message (both log file and screen)
884 // ----------------------------------------
885 ostringstream strC;
886 strC.setf(ios::fixed);
887 strC << _staID.data() << " PPP "
888 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
889 << setw(14) << setprecision(3) << x() << " +- "
890 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
891 << setw(14) << setprecision(3) << y() << " +- "
892 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
893 << setw(14) << setprecision(3) << z() << " +- "
894 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
895
896 // NEU Output
897 // ----------
898 if (settings.value("pppRefCrdX").toString() != "" &&
899 settings.value("pppRefCrdY").toString() != "" &&
900 settings.value("pppRefCrdZ").toString() != "") {
901
902 double xyzRef[3];
903 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
904 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
905 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
906
907 newPos->xnt[0] = x() - xyzRef[0];
908 newPos->xnt[1] = y() - xyzRef[1];
909 newPos->xnt[2] = z() - xyzRef[2];
910
911 double ellRef[3];
912 xyz2ell(xyzRef, ellRef);
913 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
914
915 strC << " NEU "
916 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
917 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
918 << setw(8) << setprecision(3) << newPos->xnt[5];
919
920 }
921
922 emit newMessage(QByteArray(strC.str().c_str()), true);
923
924 if (settings.value("pppAverage").toString() == "") {
925 delete newPos;
926 }
927 else {
928
929 _posAverage.push_back(newPos);
930
931 // Time Span for Average Computation
932 // ---------------------------------
933 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
934 if (tRangeAverage < 0) {
935 tRangeAverage = 0;
936 }
937 if (tRangeAverage > 86400) {
938 tRangeAverage = 86400;
939 }
940
941 // Compute the Mean
942 // ----------------
943 ColumnVector mean(7); mean = 0.0;
944
945 QMutableVectorIterator<pppPos*> it(_posAverage);
946 while (it.hasNext()) {
947 pppPos* pp = it.next();
948 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
949 delete pp;
950 it.remove();
951 }
952 else {
953 for (int ii = 0; ii < 7; ++ii) {
954 mean[ii] += pp->xnt[ii];
955 }
956 }
957 }
958
959 int nn = _posAverage.size();
960
961 if (nn > 0) {
962
963 mean /= nn;
964
965 // Compute the Deviation
966 // ---------------------
967 ColumnVector std(7); std = 0.0;
968 QVectorIterator<pppPos*> it2(_posAverage);
969 while (it2.hasNext()) {
970 pppPos* pp = it2.next();
971 for (int ii = 0; ii < 7; ++ii) {
972 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
973 }
974 }
975 for (int ii = 0; ii < 7; ++ii) {
976 std[ii] = sqrt(std[ii] / nn);
977 }
978
979 ostringstream strD; strD.setf(ios::fixed);
980 strD << _staID.data() << " AVE-XYZ "
981 << epoData->tt.timestr(1) << " "
982 << setw(13) << setprecision(3) << mean[0] << " +- "
983 << setw(6) << setprecision(3) << std[0] << " "
984 << setw(14) << setprecision(3) << mean[1] << " +- "
985 << setw(6) << setprecision(3) << std[1] << " "
986 << setw(14) << setprecision(3) << mean[2] << " +- "
987 << setw(6) << setprecision(3) << std[2];
988 emit newMessage(QByteArray(strD.str().c_str()), true);
989
990 ostringstream strE; strE.setf(ios::fixed);
991 strE << _staID.data() << " AVE-NEU "
992 << epoData->tt.timestr(1) << " "
993 << setw(13) << setprecision(3) << mean[3] << " +- "
994 << setw(6) << setprecision(3) << std[3] << " "
995 << setw(14) << setprecision(3) << mean[4] << " +- "
996 << setw(6) << setprecision(3) << std[4] << " "
997 << setw(14) << setprecision(3) << mean[5] << " +- "
998 << setw(6) << setprecision(3) << std[5];
999
1000 emit newMessage(QByteArray(strE.str().c_str()), true);
1001
1002 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
1003 ostringstream strF; strF.setf(ios::fixed);
1004 strF << _staID.data() << " AVE-TRP "
1005 << epoData->tt.timestr(1) << " "
1006 << setw(13) << setprecision(3) << mean[6] << " +- "
1007 << setw(6) << setprecision(3) << std[6] << endl;
1008 emit newMessage(QByteArray(strF.str().c_str()), true);
1009 }
1010 }
1011 }
1012
1013 // NMEA Output
1014 // -----------
1015 double xyz[3];
1016 xyz[0] = x();
1017 xyz[1] = y();
1018 xyz[2] = z();
1019 double ell[3];
1020 xyz2ell(xyz, ell);
1021 double phiDeg = ell[0] * 180 / M_PI;
1022 double lamDeg = ell[1] * 180 / M_PI;
1023
1024 char phiCh = 'N';
1025 if (phiDeg < 0) {
1026 phiDeg = -phiDeg;
1027 phiCh = 'S';
1028 }
1029 char lamCh = 'E';
1030 if (lamDeg < 0) {
1031 lamDeg = -lamDeg;
1032 lamCh = 'W';
1033 }
1034
1035 string datestr = epoData->tt.datestr(0); // yyyymmdd
1036 ostringstream strRMC;
1037 strRMC.setf(ios::fixed);
1038 strRMC << "GPRMC,"
1039 << epoData->tt.timestr(0,0) << ",A,"
1040 << setw(2) << setfill('0') << int(phiDeg)
1041 << setw(6) << setprecision(3) << setfill('0')
1042 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1043 << setw(3) << setfill('0') << int(lamDeg)
1044 << setw(6) << setprecision(3) << setfill('0')
1045 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
1046 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
1047 << datestr[2] << datestr[3] << ",,";
1048
1049 writeNMEAstr(QString(strRMC.str().c_str()));
1050
1051 double dop = 2.0; // TODO
1052
1053 ostringstream strGGA;
1054 strGGA.setf(ios::fixed);
1055 strGGA << "GPGGA,"
1056 << epoData->tt.timestr(0,0) << ','
1057 << setw(2) << setfill('0') << int(phiDeg)
1058 << setw(10) << setprecision(7) << setfill('0')
1059 << fmod(60*phiDeg,60) << ',' << phiCh << ','
1060 << setw(3) << setfill('0') << int(lamDeg)
1061 << setw(10) << setprecision(7) << setfill('0')
1062 << fmod(60*lamDeg,60) << ',' << lamCh
1063 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
1064 << setw(3) << setprecision(1) << dop << ','
1065 << setprecision(3) << ell[2] << ",M,0.0,M,,";
1066
1067 writeNMEAstr(QString(strGGA.str().c_str()));
1068
1069 return success;
1070}
1071
1072// Outlier Detection
1073////////////////////////////////////////////////////////////////////////////
1074int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
1075 const ColumnVector& vv,
1076 QMap<QString, t_satData*>& satDataGPS,
1077 QMap<QString, t_satData*>& satDataGlo,
1078 QMap<QString, t_satData*>& satDataGal) {
1079
1080 double vvMaxCodeGPS = 0.0;
1081 double vvMaxPhaseGPS = 0.0;
1082 double vvMaxPhaseGlo = 0.0;
1083 double vvMaxCodeGal = 0.0;
1084 double vvMaxPhaseGal = 0.0;
1085 QMutableMapIterator<QString, t_satData*> itMaxCodeGPS(satDataGPS);
1086 QMutableMapIterator<QString, t_satData*> itMaxPhaseGPS(satDataGPS);
1087 QMutableMapIterator<QString, t_satData*> itMaxPhaseGlo(satDataGlo);
1088 QMutableMapIterator<QString, t_satData*> itMaxCodeGal(satDataGPS);
1089 QMutableMapIterator<QString, t_satData*> itMaxPhaseGal(satDataGPS);
1090
1091 int ii = 0;
1092
1093 // GPS code and (optionally) phase residuals
1094 // -----------------------------------------
1095 QMutableMapIterator<QString, t_satData*> itGPS(satDataGPS);
1096 while (itGPS.hasNext()) {
1097 itGPS.next();
1098 ++ii;
1099
1100 if (vvMaxCodeGPS == 0.0 || fabs(vv(ii)) > vvMaxCodeGPS) {
1101 vvMaxCodeGPS = fabs(vv(ii));
1102 itMaxCodeGPS = itGPS;
1103 }
1104
1105 if (_usePhase) {
1106 ++ii;
1107 if (vvMaxPhaseGPS == 0.0 || fabs(vv(ii)) > vvMaxPhaseGPS) {
1108 vvMaxPhaseGPS = fabs(vv(ii));
1109 itMaxPhaseGPS = itGPS;
1110 }
1111 }
1112 }
1113
1114 // Glonass phase residuals
1115 // -----------------------
1116 if (_usePhase) {
1117 QMutableMapIterator<QString, t_satData*> itGlo(satDataGlo);
1118 while (itGlo.hasNext()) {
1119 itGlo.next();
1120 ++ii;
1121 if (vvMaxPhaseGlo == 0.0 || fabs(vv(ii)) > vvMaxPhaseGlo) {
1122 vvMaxPhaseGlo = fabs(vv(ii));
1123 itMaxPhaseGlo = itGlo;
1124 }
1125 }
1126 }
1127
1128 // Galileo code and (optionally) phase residuals
1129 // ---------------------------------------------
1130 QMutableMapIterator<QString, t_satData*> itGal(satDataGal);
1131 while (itGal.hasNext()) {
1132 itGal.next();
1133 ++ii;
1134
1135 if (vvMaxCodeGal == 0.0 || fabs(vv(ii)) > vvMaxCodeGal) {
1136 vvMaxCodeGal = fabs(vv(ii));
1137 itMaxCodeGal = itGal;
1138 }
1139
1140 if (_usePhase) {
1141 ++ii;
1142 if (vvMaxPhaseGal == 0.0 || fabs(vv(ii)) > vvMaxPhaseGal) {
1143 vvMaxPhaseGal = fabs(vv(ii));
1144 itMaxPhaseGal = itGal;
1145 }
1146 }
1147 }
1148
1149 if (vvMaxPhaseGlo > MAXRES_PHASE_GLO) {
1150 QString prn = itMaxPhaseGlo.key();
1151 t_satData* satData = itMaxPhaseGlo.value();
1152 delete satData;
1153 itMaxPhaseGlo.remove();
1154 _QQ = QQsav;
1155
1156 _log += "Outlier Phase " + prn.toAscii() + " "
1157 + QByteArray::number(vvMaxPhaseGlo, 'f', 3) + "\n";
1158
1159 return 1;
1160 }
1161
1162 else if (vvMaxCodeGPS > MAXRES_CODE_GPS) {
1163 QString prn = itMaxCodeGPS.key();
1164 t_satData* satData = itMaxCodeGPS.value();
1165 delete satData;
1166 itMaxCodeGPS.remove();
1167 _QQ = QQsav;
1168
1169 _log += "Outlier Code " + prn.toAscii() + " "
1170 + QByteArray::number(vvMaxCodeGPS, 'f', 3) + "\n";
1171
1172 return 1;
1173 }
1174 else if (vvMaxPhaseGPS > MAXRES_PHASE_GPS) {
1175 QString prn = itMaxPhaseGPS.key();
1176 t_satData* satData = itMaxPhaseGPS.value();
1177 delete satData;
1178 itMaxPhaseGPS.remove();
1179 _QQ = QQsav;
1180
1181 _log += "Outlier Phase " + prn.toAscii() + " "
1182 + QByteArray::number(vvMaxPhaseGPS, 'f', 3) + "\n";
1183
1184 return 1;
1185 }
1186
1187 else if (vvMaxCodeGal > MAXRES_CODE_GAL) {
1188 QString prn = itMaxCodeGal.key();
1189 t_satData* satData = itMaxCodeGal.value();
1190 delete satData;
1191 itMaxCodeGal.remove();
1192 _QQ = QQsav;
1193
1194 _log += "Outlier Code " + prn.toAscii() + " "
1195 + QByteArray::number(vvMaxCodeGal, 'f', 3) + "\n";
1196
1197 return 1;
1198 }
1199 else if (vvMaxPhaseGal > MAXRES_PHASE_GAL) {
1200 QString prn = itMaxPhaseGal.key();
1201 t_satData* satData = itMaxPhaseGal.value();
1202 delete satData;
1203 itMaxPhaseGal.remove();
1204 _QQ = QQsav;
1205
1206 _log += "Outlier Phase " + prn.toAscii() + " "
1207 + QByteArray::number(vvMaxPhaseGal, 'f', 3) + "\n";
1208
1209 return 1;
1210 }
1211
1212 return 0;
1213}
1214
1215//
1216////////////////////////////////////////////////////////////////////////////
1217void bncModel::writeNMEAstr(const QString& nmStr) {
1218
1219 unsigned char XOR = 0;
1220 for (int ii = 0; ii < nmStr.length(); ii++) {
1221 XOR ^= (unsigned char) nmStr[ii].toAscii();
1222 }
1223
1224 QString outStr = '$' + nmStr
1225 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
1226
1227 if (_nmeaStream) {
1228 *_nmeaStream << outStr;
1229 _nmeaStream->flush();
1230 }
1231
1232 emit newNMEAstr(outStr.toAscii());
1233}
1234
1235////
1236//////////////////////////////////////////////////////////////////////////////
1237void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1238 const DiagonalMatrix& PP,
1239 SymmetricMatrix& QQ, ColumnVector& dx) {
1240
1241 int nObs = AA.Nrows();
1242 int nPar = AA.Ncols();
1243
1244 UpperTriangularMatrix SS = Cholesky(QQ).t();
1245
1246 Matrix SA = SS*AA.t();
1247 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1248 for (int ii = 1; ii <= nObs; ++ii) {
1249 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1250 }
1251
1252 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1253 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1254
1255 UpperTriangularMatrix UU;
1256 QRZ(SRF, UU);
1257
1258 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1259 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1260 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1261
1262 UpperTriangularMatrix SHi = SH_rt.i();
1263
1264 Matrix KT = SHi * YY;
1265 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1266
1267 dx = KT.t() * ll;
1268 QQ << (SS.t() * SS);
1269}
1270
1271// Phase Wind-Up Correction
1272///////////////////////////////////////////////////////////////////////////
1273double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1274 const ColumnVector& rRec) {
1275
1276 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1277
1278 // First time - initialize to zero
1279 // -------------------------------
1280 if (!_windUpTime.contains(prn)) {
1281 _windUpTime[prn] = Mjd;
1282 _windUpSum[prn] = 0.0;
1283 }
1284
1285 // Compute the correction for new time
1286 // -----------------------------------
1287 else if (_windUpTime[prn] != Mjd) {
1288 _windUpTime[prn] = Mjd;
1289
1290 // Unit Vector GPS Satellite --> Receiver
1291 // --------------------------------------
1292 ColumnVector rho = rRec - rSat;
1293 rho /= rho.norm_Frobenius();
1294
1295 // GPS Satellite unit Vectors sz, sy, sx
1296 // -------------------------------------
1297 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1298
1299 ColumnVector xSun = Sun(Mjd);
1300 xSun /= xSun.norm_Frobenius();
1301
1302 ColumnVector sy = crossproduct(sz, xSun);
1303 ColumnVector sx = crossproduct(sy, sz);
1304
1305 // Effective Dipole of the GPS Satellite Antenna
1306 // ---------------------------------------------
1307 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1308 - crossproduct(rho, sy);
1309
1310 // Receiver unit Vectors rx, ry
1311 // ----------------------------
1312 ColumnVector rx(3);
1313 ColumnVector ry(3);
1314
1315 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1316 double neu[3];
1317
1318 neu[0] = 1.0;
1319 neu[1] = 0.0;
1320 neu[2] = 0.0;
1321 neu2xyz(recEll, neu, rx.data());
1322
1323 neu[0] = 0.0;
1324 neu[1] = -1.0;
1325 neu[2] = 0.0;
1326 neu2xyz(recEll, neu, ry.data());
1327
1328 // Effective Dipole of the Receiver Antenna
1329 // ----------------------------------------
1330 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1331 + crossproduct(rho, ry);
1332
1333 // Resulting Effect
1334 // ----------------
1335 double alpha = DotProduct(dipSat,dipRec) /
1336 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1337
1338 if (alpha > 1.0) alpha = 1.0;
1339 if (alpha < -1.0) alpha = -1.0;
1340
1341 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1342
1343 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1344 dphi = -dphi;
1345 }
1346
1347 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1348 }
1349
1350 return _windUpSum[prn];
1351}
Note: See TracBrowser for help on using the repository browser.