Kalman filter is an iterative mathematical process applied on consecutive data inputs to quickly estimate the true value (position, velocity, weight, temperature, etc) of the object being measured, when the measured values contain random error or uncertainty.
In this post, we’re going to look at how to implement Kalman filter in the context of static model where the true value of the object’s states are constant over time. In addition, for simplicity, we’ll only consider single measurement where there’s only one object’s state being measured.
You can find the Kalman filter implementation in Python on this repo.
How it works?
Suppose that we receive the following inputs prior to performing Kalman filter:
- Initial estimate
- Initial estimate error
- Measurement error (assumed to be constant over time)
There are three main calculations:
- Kalman gain:
previous_estimate_error / (previous_estimate_error + measurement_error)
- Current estimate:
previous_estimate + (kalman_gain * (measurement - previous_estimate))
- Current estimate error:
(1 - kalman_gain) * previous_estimate_error
For our example, suppose that we’d like to measure a temperature. Here are some basic information:
- The true temperature:
- Initial estimate:
- Initial estimate error:
- Initial measurement:
- Measurement error:
The measured temperature values are
We’d like to estimate the true temperature value based on the above data.
Performing Kalman filter calculation will yield the following results.
|Time||Measurement||Measurement Error||Estimate||Estimate Error||Kalman Gain|
According to the given data, the true value estimate is