# Kalman Filter for Static State & Single Measurement

** Published:**

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.

## Code

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:
`72`

- Initial estimate:
`68`

- Initial estimate error:
`2`

- Initial measurement:
`75`

- Measurement error:
`4`

The measured temperature values are `75`

, `71`

, `70`

, and `74`

.

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 |
---|---|---|---|---|---|

t-1 | - | - | 68 | 2 | - |

t | 75 | 4 | 70.33 | 1.33 | 0.33 |

t+1 | 71 | 4 | 70.5 | 1 | 0.25 |

t+2 | 70 | 4 | 70.4 | 0.8 | 0.2 |

t+3 | 74 | 4 | 71 | 0.66 | 0.17 |

According to the given data, the true value estimate is `71`

.