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_HPP
00028 #define EKFILTER_HPP
00029 
00032 
00033 #include <kfilter/kvector.hpp>
00034 #include <kfilter/kmatrix.hpp>
00035 
00036 namespace Kalman {
00037 
00039 
00149   template<typename T, K_UINT_32 BEG, bool OQ = false, 
00150            bool OVR = false, bool DBG = true>
00151   class EKFilter {
00152   public:
00153 
00154     typedef T type;     
00155 
00156     enum { beg = BEG    
00157     };
00158 
00159     typedef KVector<T, BEG, DBG> Vector;  
00160     typedef KMatrix<T, BEG, DBG> Matrix;  
00161 
00163 
00164 
00166     EKFilter();
00167     
00169 
00172     EKFilter(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_, 
00173              K_UINT_32 m_, K_UINT_32 nv_);
00174 
00176     virtual ~EKFilter();
00177 
00179 
00181 
00182 
00184     K_UINT_32 getSizeX() const;
00185 
00187     K_UINT_32 getSizeU() const;
00188 
00190     K_UINT_32 getSizeW() const;
00191 
00193     K_UINT_32 getSizeZ() const;
00194 
00196     K_UINT_32 getSizeV() const;
00197 
00199 
00207 
00208 
00209     
00210 
00212 
00219     void setDim(K_UINT_32 n_, K_UINT_32 nu_, K_UINT_32 nw_, 
00220                 K_UINT_32 m_, K_UINT_32 nv_);
00221 
00223 
00227     void setSizeX(K_UINT_32 n_);
00228 
00230     void setSizeU(K_UINT_32 nu_);
00231 
00233 
00237     void setSizeW(K_UINT_32 nw_);
00238 
00240     void setSizeZ(K_UINT_32 m_);
00241 
00243     void setSizeV(K_UINT_32 nv_);
00244 
00246 
00248 
00259     void init(Vector& x_, Matrix& P_);
00260 
00270 
00271 
00273 
00289     void step(Vector& u_, const Vector& z_);
00290 
00292 
00300     void timeUpdateStep(Vector& u_);
00301 
00303 
00314     void measureUpdateStep(const Vector& z_);
00315 
00317 
00334     const Vector& predict(Vector& u_);
00335 
00337 
00354     const Vector& simulate();
00355 
00357     const Vector& getX() const;
00358 
00360 
00371     const Matrix& calculateP() const;
00372 
00374 
00375   protected:
00376 
00378 
00389     void NoModification();
00390 
00391     
00392     
00415 
00416 
00418     virtual void makeBaseA();
00419 
00421     virtual void makeBaseW();
00422 
00424 
00428     virtual void makeBaseQ();
00429 
00431     virtual void makeBaseH();
00432 
00434 
00439     virtual void makeBaseV();
00440 
00442 
00447     virtual void makeBaseR();
00448 
00450 
00479 
00480 
00482 
00492     virtual void makeCommonProcess();
00493 
00495     virtual void makeA();
00496 
00498     virtual void makeW();
00499 
00501 
00505     virtual void makeQ();
00506 
00508 
00515     virtual void makeProcess() = 0;
00516     
00518 
00528     virtual void makeCommonMeasure();
00529 
00531     virtual void makeH();
00532 
00534 
00539     virtual void makeV();
00540 
00542 
00547     virtual void makeR();
00548 
00550 
00559     virtual void makeMeasure() = 0;
00560 
00562 
00569     virtual void makeDZ();
00570 
00572 
00574 
00579     virtual void sizeUpdate();
00580 
00582 
00583 
00586     Vector x;           
00587 
00590     Vector u;           
00591 
00594     Vector z;           
00595 
00599     Vector dz;          
00600 
00606     Matrix A;           
00607 
00613     Matrix W;           
00614 
00622     Matrix Q;           
00623 
00629     Matrix H;           
00630 
00638     Matrix V;           
00639 
00647     Matrix R;           
00648 
00650 
00655 
00656 
00657     K_UINT_32 n;        
00658     K_UINT_32 nu;       
00659     K_UINT_32 nw;       
00660     K_UINT_32  m;       
00661     K_UINT_32 nv;       
00662 
00664 
00665   private:
00666     
00668 
00676     static void factor(Matrix& P_);
00677 
00679 
00685     static void upperInvert(Matrix& P_);
00686 
00688 
00692     void timeUpdate();
00693 
00695 
00702     void measureUpdate(T dz, T r);
00703 
00709 
00710 
00712     void makeBaseAImpl();
00713 
00715     void makeBaseWImpl();
00716 
00718     void makeBaseQImpl();
00719 
00721     void makeBaseHImpl();
00722 
00724     void makeBaseVImpl();
00725 
00727     void makeBaseRImpl();
00728 
00730     void makeAImpl();
00731 
00733     void makeWImpl();
00734 
00736     void makeQImpl();
00737 
00739     void makeHImpl();
00740 
00742     void makeVImpl();
00743 
00745     void makeRImpl();
00746 
00748 
00759     Matrix U;           
00760 
00765     Matrix W_;          
00766 
00771     Matrix Q_;          
00772 
00781     Matrix H_;          
00782 
00795     Matrix R_;          
00796 
00797     Vector a;           
00798     Vector d;           
00799     Vector v;           
00800 
00803     K_UINT_32 nn;       
00804 
00805     mutable Matrix _P;  
00806     mutable Vector _x;  
00807 
00808     K_UINT_16 flags;    
00809     bool modified_;     
00810 
00811   };
00812 
00813 }
00814 
00815 #include <kfilter/ekfilter_impl.hpp>
00816 
00817 #endif
00818