kalman-cpp
Implementation of Kalman Filter in C++
kf.h
Go to the documentation of this file.
1 
22 #ifndef KF_H
23 #define KF_H
24 
25 #define _USE_MATH_DEFINES
26 #include <math.h>
27 
28 #include <assert.h>
29 #include <armadillo>
30 
31 using namespace std;
32 using namespace arma;
33 
37 class KF {
38 public:
42  KF();
46  ~KF();
47 
56  void InitSystem (const mat& A, const mat& B, const mat& H, const mat& Q, const mat& R);
57 
64  void InitSystemState(const colvec& x0);
65 
72  void InitStateCovariance(const mat& P0);
73 
79  void Kalmanf(const colvec& u);
80 
89  void Kalmanf(const colvec& z, const colvec& u);
90 
95  colvec* GetCurrentState();
96 
102  colvec* GetCurrentOutput();
103 
108  colvec* GetCurrentEstimatedState();
109 
115  colvec* GetCurrentEstimatedOutput();
116 
117 private:
118 
119  mat A_;
120  mat B_;
121  mat H_;
122  mat Q_;
123  mat R_;
124  colvec v_;
125  colvec w_;
126 
127  mat sqrt_Q_;
128  mat sqrt_R_;
129 
130  colvec x_;
131  colvec z_;
132 
133  colvec x_m_;
134  colvec x_p_;
135 
136  mat P_p_;
137  mat P_m_;
138 
139  colvec z_m_;
140 };
141 
142 #endif
Kalman filter implementation, for a linear system.
Definition: kf.h:37
colvec * GetCurrentState()
Get current simulated true state.
Definition: kf.cpp:110
void InitStateCovariance(const mat &P0)
Initialize the state covariance. Must be called after InitSystem. If not called, covariance state is ...
Definition: kf.cpp:65
void InitSystemState(const colvec &x0)
Initialize the system states. Must be called after InitSystem. If not, called, system states are init...
Definition: kf.cpp:58
colvec * GetCurrentEstimatedOutput()
Get current estimated output. This is the filtered measurements, with less noise.
Definition: kf.cpp:125
void InitSystem(const mat &A, const mat &B, const mat &H, const mat &Q, const mat &R)
Define the system.
Definition: kf.cpp:20
colvec * GetCurrentOutput()
Get current simulated true output. This is analogous to the measurements.
Definition: kf.cpp:115
colvec * GetCurrentEstimatedState()
Get current estimated state.
Definition: kf.cpp:120
KF()
Constructor, nothing happens here.
Definition: kf.cpp:10
void Kalmanf(const colvec &u)
Do Kalman filter iteration step-by-step while simulating the system. Simulating the system is done to...
Definition: kf.cpp:71
~KF()
Destructor, nothing happens here.
Definition: kf.cpp:15