Changeset 2933 in ntrip for trunk/BNC/combination/bnccomb.cpp


Ignore:
Timestamp:
Jan 29, 2011, 3:50:06 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/combination/bnccomb.cpp

    r2931 r2933  
    1515 * -----------------------------------------------------------------------*/
    1616
     17#include <newmatio.h>
    1718#include <iomanip>
    1819
     
    2122#include "cmbcaster.h"
    2223#include "bncsettings.h"
     24#include "bncmodel.h"
    2325
    2426using namespace std;
     27
     28// Constructor
     29////////////////////////////////////////////////////////////////////////////
     30cmbParam::cmbParam(cmbParam::parType typeIn, int indexIn,
     31                   const QString& acIn, const QString& prnIn) {
     32  type  = typeIn;
     33  index = indexIn;
     34  AC    = acIn;
     35  prn   = prnIn;
     36  xx    = 0.0;
     37}
     38
     39// Destructor
     40////////////////////////////////////////////////////////////////////////////
     41cmbParam::~cmbParam() {
     42}
     43
     44// Partial
     45////////////////////////////////////////////////////////////////////////////
     46double cmbParam::partial(const QString& acIn, t_corr* corr) {
     47 
     48  if      (type == offset) {
     49    if (AC == acIn && prn == corr->prn) {
     50      return 1.0;
     51    }
     52  }
     53  else if (type == clk) {
     54    if (prn == corr->prn) {
     55      return 1.0;
     56    }
     57  }
     58
     59  return 0.0;
     60}
     61
     62
    2563
    2664// Constructor
     
    4684
    4785  _caster = new cmbCaster();
    48 
    4986  connect(_caster, SIGNAL(error(const QByteArray)),
    5087          this, SLOT(slotError(const QByteArray)));
    51 
    5288  connect(_caster, SIGNAL(newMessage(const QByteArray)),
    5389          this, SLOT(slotMessage(const QByteArray)));
     90
     91  // Initialize Parameters
     92  // ---------------------
     93  int nextPar = 0;
     94  for (int iGps = 1; iGps <= 32; iGps++) {
     95    QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
     96    _params.push_back(new cmbParam(cmbParam::clk, ++nextPar, "", prn));
     97    QMapIterator<QString, cmbAC*> it(_ACs);
     98    while (it.hasNext()) {
     99      it.next();
     100      cmbAC* AC = it.value();
     101      _params.push_back(new cmbParam(cmbParam::offset, ++nextPar, AC->name,prn));
     102    }
     103  }
     104
     105  unsigned nPar = _params.size();
     106  _QQ.ReSize(nPar);
     107  _QQ = 0.0;
     108
     109  _sigClk0 = 100.0;
     110  _sigOff0 = 100.0;
     111
     112  for (int iPar = 1; iPar <= _params.size(); iPar++) {
     113    cmbParam* pp = _params[iPar-1];
     114    if      (pp->type == cmbParam::clk) {
     115      _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
     116    }
     117    else if (pp->type == cmbParam::offset) {
     118      _QQ(iPar,iPar) = _sigOff0 * _sigOff0;
     119    }
     120  }
    54121}
    55122
     
    243310void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
    244311
     312  // Predict Parameters Values, Add White Noise
     313  // ------------------------------------------
     314  for (int iPar = 1; iPar <= _params.size(); iPar++) {
     315    cmbParam* pp = _params[iPar-1];
     316    if      (pp->type == cmbParam::clk) {
     317      pp->xx = 0.0;
     318      for (int jj = 1; jj <= _params.size(); jj++) {
     319        _QQ(iPar, jj) = 0.0;
     320      }
     321     _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
     322    }
     323  }
     324
    245325  bncTime                resTime = epochs.first()->time;
    246326  QMap<QString, t_corr*> resCorr;
    247327
     328  int nPar = _params.size();
     329  int nObs = 0; 
     330
     331  ColumnVector x0(nPar);
     332  for (int iPar = 1; iPar <= _params.size(); iPar++) {
     333    cmbParam* pp = _params[iPar-1];
     334    x0(iPar) = pp->xx;
     335  }
     336
     337  // Count Observations
     338  // ------------------
    248339  QListIterator<cmbEpoch*> itEpo(epochs);
    249340  while (itEpo.hasNext()) {
    250341    cmbEpoch* epo = itEpo.next();
    251342    QMapIterator<QString, t_corr*> itCorr(epo->corr);
    252 
    253343    while (itCorr.hasNext()) {
    254344      itCorr.next();
    255       t_corr* corr = itCorr.value();
    256 
    257       //// beg test
    258       if (epo->acName == "BKG") {
    259         resCorr[corr->prn] = new t_corr(*corr);
     345      ++nObs;
     346    }
     347  }
     348
     349  if (nObs > 0) {
     350    Matrix         AA(nObs, nPar);
     351    ColumnVector   ll(nObs);
     352    DiagonalMatrix PP(nObs); PP = 1.0;
     353
     354    int iObs = 0;
     355    QListIterator<cmbEpoch*> itEpo(epochs);
     356    while (itEpo.hasNext()) {
     357      cmbEpoch* epo = itEpo.next();
     358      QMapIterator<QString, t_corr*> itCorr(epo->corr);
     359   
     360      while (itCorr.hasNext()) {
     361        itCorr.next();
     362        ++iObs;
     363        t_corr* corr = itCorr.value();
     364
     365        //// beg test
     366        if (epo->acName == "BKG") {
     367          resCorr[corr->prn] = new t_corr(*corr);
     368        }
     369        //// end test
     370
     371        for (int iPar = 1; iPar <= _params.size(); iPar++) {
     372          cmbParam* pp = _params[iPar-1];
     373          AA(iObs, iPar) = pp->partial(epo->acName, corr);
     374        }
     375
     376        ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
     377   
     378        printSingleCorr(epo->acName, corr);
     379        delete corr;
    260380      }
    261       //// end test
    262 
    263       printSingleCorr(epo->acName, corr);
    264       delete corr;
    265     }
     381    }
     382
     383    ColumnVector dx;
     384    bncModel::kalman(AA, ll, PP, _QQ, dx);
     385    ColumnVector vv = ll - AA * dx;
     386
     387    for (int iPar = 1; iPar <= _params.size(); iPar++) {
     388      cmbParam* pp = _params[iPar-1];
     389      pp->xx += dx(iPar);
     390    }
     391 
     392    cout << "ll = " << ll.t();
     393    cout << "dx = " << dx.t();
     394    cout << "vv = " << vv.t();
     395   
    266396  }
    267397
Note: See TracChangeset for help on using the changeset viewer.