Main Page | Modules | Namespace List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

kalmanfilter.h

Go to the documentation of this file.
00001 #ifndef TAG_FILTERKALMANFILTER_H
00002 #define TAG_FILTERKALMANFILTER_H
00003 
00004 #include <TooN/TooN.h>
00005 #include <TooN/helpers.h>
00006 #include <TooN/LU.h>
00007 
00008 namespace tag {
00009 
00083 template<class State, class Model>
00084 class KalmanFilter{
00085 public:
00086 
00087     typedef State state_type;
00088     typedef Model model_type;
00089 
00090     KalmanFilter(){
00091         TooN::Identity(identity);
00092     }
00093 
00096     void predict(double dt){
00097         model.updateState( state, dt );
00098         state.covariance = TooN::transformCovariance(model.getJacobian( state, dt ), state.covariance) + model.getNoiseCovariance( dt );
00099         TooN::Symmetrize(state.covariance);
00100     }
00101 
00104     template<class Measurement> void filter(Measurement & m){
00105         const TooN::Matrix<Measurement::M_DIMENSION,State::STATE_DIMENSION> & H = m.getMeasurementJacobian( state );
00106         const TooN::Matrix<Measurement::M_DIMENSION> & R = m.getMeasurementCovariance( state );
00107         TooN::Matrix<Measurement::M_DIMENSION> I = TooN::transformCovariance(H, state.covariance) + R;
00108         TooN::LU<Measurement::M_DIMENSION> lu(I);
00109         TooN::Matrix<State::STATE_DIMENSION, Measurement::M_DIMENSION> K = state.covariance * H.T() * lu.get_inverse();
00110         const TooN::Vector<Measurement::M_DIMENSION> & innovation = m.getInnovation( state );
00111         TooN::Vector<State::STATE_DIMENSION> stateInnovation = K * innovation;
00112         model.updateFromMeasurement( state, stateInnovation );
00113         state.covariance = (identity - K * H) * state.covariance;
00114         TooN::Symmetrize( state.covariance );
00115     }
00116 
00118     TooN::Matrix<State::STATE_DIMENSION> identity;
00120     State state;
00122     Model model;
00123 };
00124 
00125 } // namespace tag
00126 
00127 #endif

Generated on Wed Aug 8 14:30:35 2007 for TooN Algorithm Library - tag by  doxygen 1.3.9.1