00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef EKFILTER_IMPL_HPP
00028 #define EKFILTER_IMPL_HPP
00029
00032
00035 #define KALMAN_N_MODIFIED 1
00036
00039 #define KALMAN_NU_MODIFIED (1<<1)
00040
00043 #define KALMAN_NW_MODIFIED (1<<2)
00044
00047 #define KALMAN_M_MODIFIED (1<<3)
00048
00051 #define KALMAN_NV_MODIFIED (1<<4)
00052
00055 #define KALMAN_P_MODIFIED (1<<5)
00056
00059 #define KALMAN_LOWMASK ((1<<8) - 1)
00060
00063 #define KALMAN_A_MODIFIED (1<<8)
00064
00067 #define KALMAN_W_MODIFIED (1<<9)
00068
00071 #define KALMAN_Q_MODIFIED (1<<10)
00072
00075 #define KALMAN_MIDMASK ( ((1<<4) - 1) << 8 )
00076
00079 #define KALMAN_H_MODIFIED (1<<12)
00080
00083 #define KALMAN_V_MODIFIED (1<<13)
00084
00087 #define KALMAN_R_MODIFIED (1<<14)
00088
00091 #define KALMAN_HIGHMASK ( ((1<<4) - 1) << 12 )
00092
00093 namespace Kalman {
00094
00095 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00096 EKFilter<T, BEG, OQ, OVR, DBG>::EKFilter()
00097 : flags(0) {}
00098
00099 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00100 EKFilter<T, BEG, OQ, OVR, DBG>::EKFilter(K_UINT_32 n_, K_UINT_32 nu_,
00101 K_UINT_32 nw_, K_UINT_32 m_,
00102 K_UINT_32 nv_)
00103 : flags(0) {
00104 setDim(n_, nu_, nw_, m_, nv_);
00105 }
00106
00107 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00108 EKFilter<T, BEG, OQ, OVR, DBG>::~EKFilter() {}
00109
00110 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00111 void EKFilter<T, BEG, OQ, OVR, DBG>::setDim(K_UINT_32 n_, K_UINT_32 nu_,
00112 K_UINT_32 nw_, K_UINT_32 m_,
00113 K_UINT_32 nv_) {
00114 setSizeX(n_);
00115 setSizeU(nu_);
00116 setSizeW(nw_);
00117 setSizeZ(m_);
00118 setSizeV(nv_);
00119 }
00120
00121 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00122 K_UINT_32 EKFilter<T, BEG, OQ, OVR, DBG>::getSizeX() const {
00123 return n;
00124 }
00125
00126 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00127 K_UINT_32 EKFilter<T, BEG, OQ, OVR, DBG>::getSizeU() const {
00128 return nu;
00129 }
00130
00131 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00132 K_UINT_32 EKFilter<T, BEG, OQ, OVR, DBG>::getSizeW() const {
00133 return nw;
00134 }
00135
00136 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00137 K_UINT_32 EKFilter<T, BEG, OQ, OVR, DBG>::getSizeZ() const {
00138 return m;
00139 }
00140
00141 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00142 K_UINT_32 EKFilter<T, BEG, OQ, OVR, DBG>::getSizeV() const {
00143 return nv;
00144 }
00145
00146 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00147 void EKFilter<T, BEG, OQ, OVR, DBG>::setSizeX(K_UINT_32 n_) {
00148
00149
00150
00151 if (n_ != n) {
00152 flags |= KALMAN_N_MODIFIED;
00153 n = n_;
00154 }
00155 }
00156
00157 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00158 void EKFilter<T, BEG, OQ, OVR, DBG>::setSizeU(K_UINT_32 nu_) {
00159 if (nu_ != nu) {
00160 flags |= KALMAN_NU_MODIFIED;
00161 nu = nu_;
00162 }
00163 }
00164
00165 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00166 void EKFilter<T, BEG, OQ, OVR, DBG>::setSizeW(K_UINT_32 nw_) {
00167 if (nw_ != nw) {
00168 flags |= KALMAN_NW_MODIFIED;
00169 nw = nw_;
00170 }
00171 }
00172
00173 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00174 void EKFilter<T, BEG, OQ, OVR, DBG>::setSizeZ(K_UINT_32 m_) {
00175 if (m_ != m) {
00176 flags |= KALMAN_M_MODIFIED;
00177 m = m_;
00178 }
00179 }
00180
00181 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00182 void EKFilter<T, BEG, OQ, OVR, DBG>::setSizeV(K_UINT_32 nv_) {
00183 if (nv_ != nv) {
00184 flags |= KALMAN_NV_MODIFIED;
00185 nv = nv_;
00186 }
00187 }
00188
00189 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00190 void EKFilter<T, BEG, OQ, OVR, DBG>::init(Vector& x_, Matrix& P_) {
00191
00192
00193
00194 x.swap(x_);
00195 _P.swap(P_);
00196 flags |= KALMAN_P_MODIFIED;
00197 }
00198
00199 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00200 void EKFilter<T, BEG, OQ, OVR, DBG>::step(Vector& u_, const Vector& z_) {
00201 timeUpdateStep(u_);
00202 measureUpdateStep(z_);
00203 }
00204
00205 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00206 void EKFilter<T, BEG, OQ, OVR, DBG>::timeUpdateStep(Vector& u_) {
00207
00208
00209 K_UINT_32 i, j, k;
00210
00211 sizeUpdate();
00212 u.swap(u_);
00213
00214 makeCommonProcess();
00215 makeAImpl();
00216 makeWImpl();
00217 makeQImpl();
00218 makeProcess();
00219
00220 if (!OQ) {
00221
00222 if (flags & KALMAN_Q_MODIFIED) {
00223
00224 Q_ = Q;
00225 factor(Q_);
00226 upperInvert(Q_);
00227
00228 }
00229
00230 Q.swap(Q_);
00231
00232
00233
00234 if (flags & ( KALMAN_W_MODIFIED | KALMAN_Q_MODIFIED ) ) {
00235
00236 for (i = BEG; i < n + BEG; ++i) {
00237
00238 for (j = BEG; j < nw + BEG; ++j) {
00239
00240 W_(i,j) = W(i,j);
00241 for (k = BEG; k < j; ++k)
00242 W_(i,j) += W(i,k)*Q(j,k);
00243
00244 }
00245
00246 }
00247
00248 }
00249
00250 W.swap(W_);
00251
00252 }
00253
00254 timeUpdate();
00255
00256 if (!OQ) {
00257 Q.swap(Q_);
00258 W.swap(W_);
00259 }
00260
00261 u.swap(u_);
00262 flags &= ~KALMAN_MIDMASK;
00263 }
00264
00265 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00266 void EKFilter<T, BEG, OQ, OVR, DBG>::measureUpdateStep(const Vector& z_) {
00267
00268
00269 K_UINT_32 i, j, k;
00270
00271 sizeUpdate();
00272
00273 if (m == 0) {
00274 return;
00275 }
00276
00277 makeCommonMeasure();
00278 makeHImpl();
00279 makeVImpl();
00280 makeRImpl();
00281 makeMeasure();
00282
00283
00284
00285 for (i = BEG; i < m + BEG; ++i)
00286 dz(i) = z_(i) - z(i);
00287
00288 makeDZ();
00289
00290 if (OVR) {
00291
00292
00293
00294 if (flags & ( KALMAN_V_MODIFIED | KALMAN_R_MODIFIED ) ) {
00295
00296 for (i = BEG; i < m + BEG; ++i)
00297 R_(i,i) = V(i,i)*V(i,i)*R(i,i);
00298
00299 }
00300
00301 } else {
00302
00303
00304 if (flags & ( KALMAN_V_MODIFIED | KALMAN_R_MODIFIED ) ) {
00305
00306 _x.resize(nv);
00307
00308
00309 for (i = BEG; i < m + BEG; ++i) {
00310
00311
00312 for (j = BEG; j < nv + BEG; ++j) {
00313
00314 _x(j) = T(0.0);
00315 for (k = BEG; k < nv + BEG; ++k)
00316 _x(j) += V(i,k)*R(k,j);
00317
00318 }
00319
00320
00321 for (j = BEG; j < m + BEG; ++j) {
00322
00323 R_(i,j) = T(0.0);
00324 for (k = BEG; k < nv + BEG; ++k)
00325 R_(i,j) += _x(k)*V(j,k);
00326
00327 }
00328
00329 }
00330
00331
00332
00333 factor(R_);
00334
00335
00336 upperInvert(R_);
00337
00338 }
00339
00340 if (flags & ( KALMAN_H_MODIFIED | KALMAN_V_MODIFIED | KALMAN_R_MODIFIED ) ) {
00341
00342
00343 for (i = BEG; i < m + BEG; ++i) {
00344
00345 for (j = BEG; j < n + BEG; ++j) {
00346
00347 H_(i,j) = H(i,j);
00348 for (k = i + 1; k < m + BEG; ++k)
00349 H_(i,j) += R_(k,i)*H(k,j);
00350
00351 }
00352
00353 }
00354
00355 }
00356
00357 H.swap(H_);
00358
00359
00360 _x.resize(m);
00361
00362 for (i = BEG; i < m + BEG; ++i) {
00363
00364 _x(i) = dz(i);
00365 for (k = i + 1; k < m + BEG; ++k)
00366 _x(i) += R_(k,i)*dz(k);
00367
00368 }
00369
00370 dz.swap(_x);
00371
00372 }
00373
00374 _x.resize(n);
00375 _x = T(0.0);
00376 for (i = BEG; i < m + BEG; ++i) {
00377
00378 for (j = BEG; j < n + BEG; ++j)
00379 a(j) = H(i,j);
00380
00381 measureUpdate(dz(i), R_(i,i));
00382
00383 }
00384 for (i = BEG; i < n + BEG; ++i)
00385 x(i) += _x(i);
00386
00387 if (!OVR) {
00388 H.swap(H_);
00389 }
00390
00391 flags &= ~KALMAN_HIGHMASK;
00392 }
00393
00394 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00395 const EKFilter<T, BEG, OQ, OVR, DBG>::Vector& EKFilter<T, BEG, OQ, OVR, DBG>::predict(Vector& u_) {
00396
00397
00398
00399 sizeUpdate();
00400 u.swap(u_);
00401 _x = x;
00402
00403 makeCommonProcess();
00404 makeProcess();
00405
00406 x.swap(_x);
00407 u.swap(u_);
00408 return _x;
00409 }
00410
00411 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00412 const EKFilter<T, BEG, OQ, OVR, DBG>::Vector& EKFilter<T, BEG, OQ, OVR, DBG>::simulate() {
00413
00414 sizeUpdate();
00415 _x = z;
00416
00417 makeCommonMeasure();
00418 makeMeasure();
00419
00420 z.swap(_x);
00421 return _x;
00422 }
00423
00424 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00425 const EKFilter<T, BEG, OQ, OVR, DBG>::Vector& EKFilter<T, BEG, OQ, OVR, DBG>::getX() const {
00426 return x;
00427 }
00428
00429 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00430 const EKFilter<T, BEG, OQ, OVR, DBG>::Matrix& EKFilter<T, BEG, OQ, OVR, DBG>::calculateP() const {
00431
00432 if (!(flags & KALMAN_P_MODIFIED)) {
00433
00434 _P.resize(n, n);
00435
00436 for (K_UINT_32 i = BEG; i < n + BEG; ++i) {
00437
00438 _P(i,i) = U(i,i);
00439
00440 for (K_UINT_32 j = i + 1; j < n + BEG; ++j) {
00441
00442 _P(i,j) = U(i,j)*U(j,j);
00443 _P(i,i) += U(i,j)*_P(i,j);
00444
00445 for (K_UINT_32 k = j + 1; k < n + BEG; ++k) {
00446 _P(i,j) += U(i,k)*U(j,k)*U(k,k);
00447 }
00448
00449 _P(j,i) = _P(i,j);
00450
00451 }
00452
00453 }
00454
00455 }
00456
00457 return _P;
00458 }
00459
00460 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00461 void EKFilter<T, BEG, OQ, OVR, DBG>::NoModification() {
00462 modified_ = false;
00463 }
00464
00465 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00466 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseA() {
00467 NoModification();
00468 }
00469
00470 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00471 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseW() {
00472 NoModification();
00473 }
00474
00475 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00476 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseQ() {
00477 NoModification();
00478 }
00479
00480 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00481 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseH() {
00482 NoModification();
00483 }
00484
00485 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00486 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseV() {
00487 NoModification();
00488 }
00489
00490 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00491 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseR() {
00492 NoModification();
00493 }
00494
00495 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00496 void EKFilter<T, BEG, OQ, OVR, DBG>::makeCommonProcess() {}
00497
00498 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00499 void EKFilter<T, BEG, OQ, OVR, DBG>::makeCommonMeasure() {}
00500
00501 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00502 void EKFilter<T, BEG, OQ, OVR, DBG>::makeA() {
00503 NoModification();
00504 }
00505
00506 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00507 void EKFilter<T, BEG, OQ, OVR, DBG>::makeW() {
00508 NoModification();
00509 }
00510
00511 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00512 void EKFilter<T, BEG, OQ, OVR, DBG>::makeQ() {
00513 NoModification();
00514 }
00515
00516 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00517 void EKFilter<T, BEG, OQ, OVR, DBG>::makeH() {
00518 NoModification();
00519 }
00520
00521 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00522 void EKFilter<T, BEG, OQ, OVR, DBG>::makeV() {
00523 NoModification();
00524 }
00525
00526 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00527 void EKFilter<T, BEG, OQ, OVR, DBG>::makeR() {
00528 NoModification();
00529 }
00530
00531 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00532 void EKFilter<T, BEG, OQ, OVR, DBG>::makeDZ() {}
00533
00534 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00535 void EKFilter<T, BEG, OQ, OVR, DBG>::sizeUpdate() {
00536
00537 if (!flags) {
00538 return;
00539 }
00540
00541 if (flags & KALMAN_N_MODIFIED) {
00542 A.resize(n, n);
00543 makeBaseAImpl();
00544 }
00545
00546 if (flags & (KALMAN_N_MODIFIED | KALMAN_NW_MODIFIED) ) {
00547 nn = n + nw;
00548 a.resize(nn);
00549 v.resize(nn);
00550 d.resize(nn);
00551 if (!OQ)
00552 W_.resize(n, nw);
00553 W.resize(n, nw);
00554 makeBaseWImpl();
00555 }
00556
00557
00558
00559
00560
00561
00562
00563 if (flags & KALMAN_P_MODIFIED) {
00564
00565
00566
00567
00568 U.resize(n, nn);
00569 for (K_UINT_32 i = BEG; i < n + BEG; ++i)
00570 for (K_UINT_32 j = BEG; j < n + BEG; ++j)
00571 U(i,j) = _P(i,j);
00572
00573
00574 factor(U);
00575
00576 } else if (flags & KALMAN_NW_MODIFIED) {
00577
00578
00579
00580
00581
00582 _P.resize(n, nn);
00583 for (K_UINT_32 i = BEG; i < n + BEG; ++i)
00584 for (K_UINT_32 j = i; j < n + BEG; ++j)
00585 _P(i,j) = U(i,j);
00586 U.swap(_P);
00587 }
00588
00589 if (flags & KALMAN_NW_MODIFIED) {
00590 if (!OQ)
00591 Q_.resize(nw, nw);
00592 Q.resize(nw, nw);
00593 makeBaseQImpl();
00594 }
00595
00596 if (m != 0) {
00597
00598 if (flags & (KALMAN_N_MODIFIED | KALMAN_M_MODIFIED) ) {
00599 if (!OVR)
00600 H_.resize(m, n);
00601 H.resize(m, n);
00602 makeBaseHImpl();
00603 }
00604
00605 if (flags & (KALMAN_M_MODIFIED | KALMAN_NV_MODIFIED) ) {
00606 V.resize(m, nv);
00607 makeBaseVImpl();
00608 }
00609
00610 if (flags & KALMAN_NV_MODIFIED) {
00611 R.resize(nv, nv);
00612 makeBaseRImpl();
00613 }
00614
00615 if (flags & KALMAN_M_MODIFIED) {
00616 R_.resize(m, m);
00617 z.resize(m);
00618 dz.resize(m);
00619 }
00620
00621 }
00622
00623 flags &= ~KALMAN_LOWMASK;
00624 }
00625
00626 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00627 void EKFilter<T, BEG, OQ, OVR, DBG>::factor(Matrix& P_) {
00628
00629
00630
00631
00632
00633 T alpha, beta;
00634 K_UINT_32 i, j, k, N = P_.nrow();
00635 for(j = N - 1 + BEG; j > BEG; --j) {
00636 alpha = T(1.0)/P_(j,j);
00637 for(k = BEG; k < j; ++k) {
00638 beta = P_(k,j);
00639 P_(k,j) = alpha*beta;
00640 for(i = BEG; i <= k; ++i)
00641 P_(i,k) -= beta*P_(i,j);
00642 }
00643 }
00644 }
00645
00646 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00647 void EKFilter<T, BEG, OQ, OVR, DBG>::upperInvert(Matrix& P_) {
00648
00649 T val;
00650 K_UINT_32 i, j, k, N = P_.nrow();
00651 for (i = N - 2 + BEG; i >= BEG; --i) {
00652 for (k = i + 1; k < N + BEG; ++k) {
00653
00654 val = P_(i,k);
00655 for (j = i + 1; j <= k - 1; ++j)
00656 val += P_(i,j)*P_(k,j);
00657 P_(k,i) = -val;
00658
00659 }
00660 }
00661
00662 }
00663
00664
00665
00666
00667
00668
00669
00670 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00671 void EKFilter<T, BEG, OQ, OVR, DBG>::timeUpdate() {
00672
00673 K_UINT_32 i, j, k;
00674 T sigma, dinv;
00675
00676
00677
00678
00679
00680
00681
00682 for(j = n - 1 + BEG; j > BEG; --j) {
00683 for(i = BEG; i <= j; ++i)
00684 d(i) = U(i,j);
00685 for(i = BEG; i < n + BEG; ++i) {
00686 U(i,j) = A(i,j);
00687 for(k = BEG; k < j; ++k)
00688 U(i,j) += A(i,k)*d(k);
00689 }
00690 }
00691
00692 d(BEG) = U(BEG,BEG);
00693 for(j = BEG; j < n + BEG; ++j)
00694 U(j,BEG) = A(j,BEG);
00695
00696
00697
00698 for(i = BEG; i < nw + BEG; ++i) {
00699 d(i+n) = Q(i,i);
00700 for(j = BEG; j < n + BEG; ++j)
00701 U(j,i+n) = W(j,i);
00702 }
00703
00704
00705
00706 for(j = n - 1 + BEG; j >= BEG; --j) {
00707 sigma = T(0.0);
00708 for(k = BEG; k < nn + BEG; ++k) {
00709 v(k) = U(j,k);
00710 a(k) = d(k)*v(k);
00711 sigma += v(k)*a(k);
00712 }
00713 U(j,j) = sigma;
00714 if(j == BEG || sigma == T(0.0)) continue;
00715 dinv = T(1.0)/sigma;
00716 for(k = BEG; k < j; ++k) {
00717 sigma = T(0.0);
00718 for(i = BEG; i < nn + BEG; ++i)
00719 sigma += U(k,i)*a(i);
00720 sigma *= dinv;
00721 for(i = BEG; i < nn + BEG; ++i)
00722 U(k,i) -= sigma*v(i);
00723 U(j,k) = sigma;
00724 }
00725 }
00726
00727
00728 for(j = BEG + 1; j < n + BEG; ++j)
00729 for(i = BEG; i < j; ++i)
00730 U(i,j) = U(j,i);
00731 }
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00743 void EKFilter<T, BEG, OQ, OVR, DBG>::measureUpdate(T dz, T r) {
00744
00745 K_UINT_32 i, j, k;
00746 T alpha, gamma, beta, lambda;
00747
00748
00749 for (j = BEG; j < n + BEG; ++j)
00750 dz -= a(j)*_x(j);
00751
00752
00753
00754
00755
00756
00757 for(j = n - 1 + BEG; j > BEG; --j) {
00758 for(k = BEG; k < j; ++k)
00759 a(j) += U(k,j)*a(k);
00760 d(j) = U(j,j)*a(j);
00761 }
00762 d(BEG) = U(BEG,BEG)*a(BEG);
00763
00764
00765
00766 alpha = r+d(BEG)*a(BEG);
00767 gamma = T(1.0)/alpha;
00768 U(BEG,BEG) = r*gamma*U(BEG,BEG);
00769 for(j = BEG + 1; j < n + BEG; ++j) {
00770 beta = alpha;
00771 alpha += d(j)*a(j);
00772 lambda = -a(j)*gamma;
00773 gamma = T(1.0)/alpha;
00774 U(j,j) *= beta*gamma;
00775 for(i = BEG; i < j; ++i) {
00776 beta = U(i,j);
00777 U(i,j) = beta+d(i)*lambda;
00778 d(i) += d(j)*beta;
00779 }
00780 }
00781
00782
00783 dz *= gamma;
00784 for(j = BEG; j < n + BEG; ++j)
00785 _x(j) += d(j)*dz;
00786 }
00787
00788 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00789 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseAImpl() {
00790 modified_ = true;
00791 makeBaseA();
00792 if (modified_)
00793 flags |= KALMAN_A_MODIFIED;
00794 }
00795
00796 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00797 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseWImpl() {
00798 modified_ = true;
00799 makeBaseW();
00800 if (modified_)
00801 flags |= KALMAN_W_MODIFIED;
00802 }
00803
00804 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00805 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseQImpl() {
00806 modified_ = true;
00807 makeBaseQ();
00808 if (modified_)
00809 flags |= KALMAN_Q_MODIFIED;
00810 }
00811
00812 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00813 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseHImpl() {
00814 modified_ = true;
00815 makeBaseH();
00816 if (modified_)
00817 flags |= KALMAN_H_MODIFIED;
00818 }
00819
00820 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00821 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseVImpl() {
00822 modified_ = true;
00823 makeBaseV();
00824 if (modified_)
00825 flags |= KALMAN_V_MODIFIED;
00826 }
00827
00828 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00829 void EKFilter<T, BEG, OQ, OVR, DBG>::makeBaseRImpl() {
00830 modified_ = true;
00831 makeBaseR();
00832 if (modified_)
00833 flags |= KALMAN_R_MODIFIED;
00834 }
00835
00836 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00837 void EKFilter<T, BEG, OQ, OVR, DBG>::makeAImpl() {
00838 modified_ = true;
00839 makeA();
00840 if (modified_)
00841 flags |= KALMAN_A_MODIFIED;
00842 }
00843
00844 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00845 void EKFilter<T, BEG, OQ, OVR, DBG>::makeWImpl() {
00846 modified_ = true;
00847 makeW();
00848 if (modified_)
00849 flags |= KALMAN_W_MODIFIED;
00850 }
00851
00852 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00853 void EKFilter<T, BEG, OQ, OVR, DBG>::makeQImpl() {
00854 modified_ = true;
00855 makeQ();
00856 if (modified_)
00857 flags |= KALMAN_Q_MODIFIED;
00858 }
00859
00860 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00861 void EKFilter<T, BEG, OQ, OVR, DBG>::makeHImpl() {
00862 modified_ = true;
00863 makeH();
00864 if (modified_)
00865 flags |= KALMAN_H_MODIFIED;
00866 }
00867
00868 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00869 void EKFilter<T, BEG, OQ, OVR, DBG>::makeVImpl() {
00870 modified_ = true;
00871 makeV();
00872 if (modified_)
00873 flags |= KALMAN_V_MODIFIED;
00874 }
00875
00876 template<typename T, K_UINT_32 BEG, bool OQ, bool OVR, bool DBG>
00877 void EKFilter<T, BEG, OQ, OVR, DBG>::makeRImpl() {
00878 modified_ = true;
00879 makeR();
00880 if (modified_)
00881 flags |= KALMAN_R_MODIFIED;
00882 }
00883
00884 }
00885
00886 #endif