Last active
September 24, 2015 16:38
-
-
Save satoruhiga/777748 to your computer and use it in GitHub Desktop.
SimpleKalmanFilter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleKalmanFilter | |
{ | |
public: | |
float xhat, xhatminus; | |
float P, Pminus; | |
float _x, _p; | |
float Q, R, K; | |
SimpleKalmanFilter() | |
{ | |
_x = xhat = 0; | |
_p = Pminus = 1; | |
} | |
void init(float Q=1e-5, float R=0.01) | |
{ | |
this->Q = Q; | |
this->R = R; | |
} | |
float filter(float z) | |
{ | |
xhatminus = _x; | |
Pminus = _p + Q; | |
K = Pminus / (Pminus + R); | |
xhat = xhatminus + K * (z - xhatminus); | |
P = (1 - K) * Pminus; | |
_x = xhat; | |
_p = P; | |
return xhat; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment