Control

What is a Kalman filter and how does it work on noisy sensor data?

Short answer

A Kalman filter estimates a hidden state, such as the true level or slope of a signal, from noisy measurements. It works recursively: each step predicts the state with a model, then corrects the prediction with the new measurement. The Kalman gain sets how much the correction trusts the measurement relative to the model.

The predict-update cycle

The filter runs in two steps. In the predict step, the previous state and a model of the system give a new estimate and its variance, which measures uncertainty. In the update step, a new measurement arrives and the estimate is pulled toward it. The size of that pull is the Kalman gain K. K depends on two noise levels: process noise Q, the model's allowance for unexpected change, and measurement noise R, the sensor's noise. A large Q relative to R makes the filter follow the data faster and more noisily. A large R relative to Q makes it smoother and slower. Under linear-model and Gaussian-noise assumptions, this is the optimal linear estimator. When those assumptions fail, the output can still be useful but loses that guarantee.

Scalar example (hypothetical)

Suppose the prediction is 10 with variance P = 4, and a measurement of 12 arrives with R = 4.

  • Gain: K = P / (P + R) = 4 / 8 = 0.5
  • Estimate: 10 + 0.5 × (12 − 10) = 11
  • New variance: (1 − K) × P = 0.5 × 4 = 2

Because the model and the sensor are equally trusted, the estimate lands halfway and the variance halves. If the sensor were much noisier, say R = 36, the gain would fall to 4 / 40 = 0.1, and the estimate would move only to 10.2.

Tuning and limits

Tuning Q and R is where most of the practical work sits. R can be estimated from the sensor's noise when the machine is at standstill. Q is a model assumption about how fast the true state can change, and it is usually adjusted by testing on data. Nonlinear degradation, abrupt jumps and irregular sampling all challenge the standard filter. Outliers can damage it, so monitor the innovation, which is the measurement minus the prediction, and gate out values far larger than the expected spread. Irregular sample intervals need a model that depends on the elapsed time between samples.

Follow-up questions

How is a Kalman filter different from a moving average?

A moving average uses a fixed window and reacts to changes with a lag. A Kalman filter uses a dynamic model, attaches an uncertainty to each estimate and updates its gain at every step. Its lag can be balanced against smoothness by choosing Q and R.

Why does a Kalman filter depend so much on Q and R?

The gain comes from the balance between trust in the model and trust in the sensor. If Q and R are wrong, the filter either passes too much noise or reacts late to real change. A practical start is to estimate R from a standstill measurement, then check Q against data and process knowledge.

Sources

Example numbers are hypothetical, not measured field results.

Related questions

All questions