Search code examples
kalman-filter

Estimating error with a Kalman Filter


I'm working on adding a simple 1-D Kalman Filter to an application to process some noisy input data and output a cleaned result.

The example code I'm using comes from the Single-Variable example section of this tutorial and this python code.

This is working well for calculating the resulting value, however, when I first read about Kalman Filters I was under the impression that they could also be used for giving some measurement about how much "error" is in the inputs.

As an example, say I'm measuring an value of 10 but my input has a large amount of error. My input data may look like 6, 11, 14, 5, 19, 5, etc (some gaussian distribution around 10).

But say I switch to a less-noisy measurement and the measurements are 9.7, 10.3, 10.1, 10.0, 9.8, 10.1.

In both cases, the Kalman Filter will theoretically converge to a proper measurement of 10. What I want is to also have it give me some sort of numerical value estimating how much error there was in these data streams.

I believe this should be quite possible with a Kalman Filter, however, I'm having trouble finding a resource describing this. How can I do this?


Solution

  • In fact the situation is quite the opposite: The KF's estimate of your process noise is not affected by your data at all. If you look at the predict/update steps of the KF you'll see that the P term is never influenced by your state or your measurements. It is computed from your estimate of the additive process noise Q and your estimate of the measurement noise R.

    If you have a dataset and want to measure it you can compute its mean and variance (which are what your state and process covariance represent). If you are talking about your input then you are talking about measuring the variance of your samples to set R.

    If your actual input measurements are actually less noisy than expected then you will get a less noisy state, but with greater latency than you would have if you had set expectations correctly in R.

    In a running filter you can look at your innovation sequence (the differences between the predicted and actual measurements) and compare them to your predicted innovation covariance (usually called S although sometimes rolled directly in as the denominator of K).