KalmanFilter.H

Go to the documentation of this file.
00001 /*!@file Image/KalmanFilter.H implementation of a 2nd order linear Kalman Filter
00002  */
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/KalmanFilter.H $
00035 // $Id: KalmanFilter.H 6005 2005-11-29 18:49:14Z rjpeters $
00036 //
00037 
00038 #ifndef KALMANFILTER_H_DEFINED
00039 #define KALMANFILTER_H_DEFINED
00040 
00041 #include "Util/Types.H"
00042 #include "Image/Image.H"
00043 
00044 #define DEF_PNOISE 1.0F
00045 #define DEF_MNOISE 1.0F
00046 #define DEF_TSTEP  1.0F
00047 
00048 //! implementation of a 2nd order linear Kalman Filter
00049 /*! This class can be used for tracking. The state vector is second order,
00050   i.e. it maintains location, speed, and accelaration to generate
00051   predictions.*/
00052 class KalmanFilter
00053 {
00054 public:
00055 
00056   //! default constructor - need to call init before the filter can be used
00057   KalmanFilter();
00058 
00059   //! constructor that initializes the filter
00060   /*!@param initialM - the initial measurement used to jump start the filter
00061     @param pNoise - std of the (Gaussian) proess noise
00062     @param mNoise - std of the (Gaussian) measurement noise
00063     @param timeStep - the time interval between measurements (default: 1)*/
00064   KalmanFilter(float initialM, float pNoise = DEF_PNOISE,
00065                float mNoise = DEF_MNOISE, float timeStep = DEF_TSTEP);
00066 
00067   // default copy constructor and destructor are fine
00068 
00069   //! initialize the filter
00070   /*!@param initialM - the initial measurement used to jump start the filter
00071     @param pNoise - std of the (Gaussian) process noise
00072     @param mNoise - std of the (Gaussian) measurement noise
00073     @param timeStep - the time interval between measurements (default: 1)*/
00074   void init(float initialM, float pNoise = DEF_PNOISE,
00075             float mNoise = DEF_MNOISE, float timeStep = DEF_TSTEP);
00076 
00077   //! write the entire KalmanFilter to the output stream os
00078   void writeToStream(std::ostream& os) const;
00079 
00080   //! read the KalmanFilter from the input stream is
00081   void readFromStream(std::istream& is);
00082 
00083   //! returns a prediction for the next value
00084   float getEstimate() const;
00085 
00086   //! returns a prediction for the next value given a measurement
00087   float getEstimate(float measurement) const;
00088 
00089   //! returns the speed (second entry in the state vector)
00090   float getSpeed() const;
00091 
00092   //! returns the cost for associating measurement with this Kalman tracker
00093   float getCost(float measurement) const;
00094 
00095   //! update the filter for the next time step without a measurement (skipped value)
00096   float update();
00097 
00098   //! update the filter for the next time step with a measurement
00099   float update(float measurement);
00100 
00101   //! returns the current state vector [x, v, a]
00102   Image<float> getStateVector() const;
00103 
00104   //! returns the covariance matrix P
00105   Image<float> getCovariances() const;
00106 
00107   //! test whether the filter is initialized
00108   bool isInitialized() const;
00109 
00110 
00111 private:
00112   // update the Kalman matrix and the covariance matrices
00113   void updateFilter();
00114 
00115   // returns the predicted state vector without a measurement
00116   Image<float> getXEstimate() const;
00117 
00118   // returns the predicted state vector given a measurement
00119   Image<float> getXEstimate(float z) const;
00120 
00121 
00122   // a number of matrices used for the processing
00123   Image<float> x, I, M, K, P, H, HT, Phi, PhiT, Q;
00124   float itsPNoise, itsMNoise2;
00125   bool initialized;
00126 };
00127 
00128 #endif
00129 
00130 // ######################################################################
00131 /* So things look consistent in everyone's emacs... */
00132 /* Local Variables: */
00133 /* indent-tabs-mode: nil */
00134 /* End: */
Generated on Sun May 8 08:40:55 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3