-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKalmanFilter.cpp
More file actions
22 lines (18 loc) · 832 Bytes
/
KalmanFilter.cpp
File metadata and controls
22 lines (18 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "KalmanFilter.h"
KalmanFilter::KalmanFilter(double process_variance, double measurement_variance) :
process_variance_(process_variance),
measurement_variance_(measurement_variance),
posteri_estimate_(0.0),
posteri_error_estimate_(1.0) {}
/*
* implemented from:
https://www.cs.unc.edu/~welch/media/pdf/kalman_intro.pdf
*/
double KalmanFilter::update(double measurement) {
double priori_estimate = posteri_estimate_;
double priori_error_estimate = posteri_error_estimate_ + process_variance_;
double blending_factor = priori_error_estimate / (priori_error_estimate + measurement_variance_);
posteri_estimate_ = priori_estimate + blending_factor * (measurement - priori_estimate);
posteri_error_estimate_ = (1 - blending_factor) * priori_error_estimate;
return posteri_estimate_;
}