Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kalman.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __Kalman_hh__
27 #define __Kalman_hh__
28 
29 #include <Base/Debug/Debug.hh>
30 #include <Base/Math/Matrix.hh>
31 #include <Base/Math/Vector.hh>
32 #include <MathAlgo/SVD.hh>
33 
34 namespace BIAS {
35 
36  /** @brief Classical Kalman filter. See http://www.cs.unc.edu/~welch/kalman/ for details.
37 
38  Initialize it by either
39  - either calling Init
40  - or calling the approbriate constructor
41  with the initial system state, the system matrix and the measurement matrix.
42 
43  Use it by consecutively call
44  - Predict()
45  - Update()
46 
47  Extract the prediction (prior) by calling GetState() and
48  GetCovariance() after the Predict() step.
49 
50  Extract the estimated system state by calling GetState() and
51  GetCovariance() after the Update() step.
52  @ingroup g_stateestimation
53  @author Felix Woelk 05/2005, untested so far */
54  class BIASStateEstimator_EXPORT Kalman : public Debug
55  {
56  public:
57  Kalman();
58 
59  Kalman(const Matrix<double>& SystemMatrix,
60  const Matrix<double>& MeasurementMatrix,
61  const Vector<double>& InitialSystemState,
62  const Matrix<double>& InitialSystemCovariance);
63 
64  ~Kalman();
65 
66  void Init(const Matrix<double>& SystemMatrix,
67  const Matrix<double>& MeasurementMatrix,
68  const Vector<double>& InitialSystemState,
69  const Matrix<double>& InitialSystemCovariance);
70 
71  /** Calculates the prediction using the system matrix A
72  @author woelk 05/2005 */
73  void Predict(const Matrix<double>& ProcessCovariance);
74 
75  /** Use this prediction function system in case of varying system matrix A.
76  @author woelk 05/2005 */
77  void Predict(const Matrix<double>& SystemMatrix,
78  const Matrix<double>& ProcessCovariance);
79 
80  /** Calculates the update step.
81  @author woelk 05/2005 */
82  void Update(const Vector<double>& Measurement,
83  const Matrix<double>& MeasurementCovariance);
84 
85  /** Returns the system state. It could be the prediction, if called after
86  the predict step or the posterior, if GetState is called after
87  the update step.
88  @author woelk 05/2005 */
89  inline void GetState(Vector<double>& state) const
90  { state = State_; }
91 
92  /** Returns the system state covariance. It could be the covariance of the
93  prediction, if called after the predict step or the covariance of the
94  posterior, if GetState is called after the update step.
95  @author woelk 05/2005 */
96  inline void GetCovariance(Matrix<double>& cov) const
97  { cov = Covariance_; }
98 
99  protected:
100  /// Contains either the prediction (prior) or Bayes optimal system estimate
101  /// (posterior) depending what function (Predict()/Update()) wascalled last
103  /// The covariance matrix corresponding to State_
105 
106  /// measurement matrix and transposed
108 
109  /// measurement matrix and transposed
111 
112  /// identity matrix
114 
115  /// dimensions of system space and measurement space
116  int SystemStateDim_, MeasurementDim_;
117 
118  /// needed for matrix inversion
120 
121  }; // class
122 
123 
124 
125 } // namespace
126 
127 
128 #endif // __Kalman_hh__
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
Matrix< double > Identity_
identity matrix
Definition: Kalman.hh:113
Matrix< double > AT_
Definition: Kalman.hh:110
int SystemStateDim_
dimensions of system space and measurement space
Definition: Kalman.hh:116
Classical Kalman filter.
Definition: Kalman.hh:54
void GetState(Vector< double > &state) const
Returns the system state.
Definition: Kalman.hh:89
Matrix< double > HT_
Definition: Kalman.hh:107
void GetCovariance(Matrix< double > &cov) const
Returns the system state covariance.
Definition: Kalman.hh:96
SVD svd_
needed for matrix inversion
Definition: Kalman.hh:119
Matrix< double > Covariance_
The covariance matrix corresponding to State_.
Definition: Kalman.hh:104
Vector< double > State_
Contains either the prediction (prior) or Bayes optimal system estimate (posterior) depending what fu...
Definition: Kalman.hh:102