Skip to content

Instantly share code, notes, and snippets.

@farhanhubble
Created July 30, 2017 13:35
Show Gist options
  • Save farhanhubble/05c94769508c66fdcb2985cce24eaf62 to your computer and use it in GitHub Desktop.
Save farhanhubble/05c94769508c66fdcb2985cce24eaf62 to your computer and use it in GitHub Desktop.
1 Dimensional Kalman Filter
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