Created
July 30, 2017 13:35
-
-
Save farhanhubble/05c94769508c66fdcb2985cce24eaf62 to your computer and use it in GitHub Desktop.
1 Dimensional Kalman Filter
This file contains 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
void filter(VectorXd &x, MatrixXd &P) { | |
for (unsigned int n = 0; n < measurements.size(); ++n) { | |
VectorXd z = measurements[n]; | |
//YOUR CODE HERE | |
// KF Prediction | |
VectorXd x_ = F*x + u; | |
MatrixXd P_ = F*P*F.transpose() + Q; | |
// KF Measurement step | |
VectorXd y = z - H*x_; | |
MatrixXd S = H*P_*H.transpose() + R; | |
MatrixXd K = P_ * H.transpose() * S.inverse(); | |
// new state | |
x = x_ + K*y; | |
P = (I-K*H)*P_; | |
std::cout << "x=" << std::endl << x << std::endl; | |
std::cout << "P=" << std::endl << P << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment