The guide
A Kalman filter is only as honest as the two noise numbers you give it
What a Kalman filter trusts, why its gain settles, why q and r are the whole tuning, and why a smooth estimate can still be wrong.
- 0.2709 steady position gain for q = 0.1, r = 2, dt = 1
- 19 steps for every gain entry to settle within 1 percent
- 1.0835 steady position variance, against a reading variance of 4
- 0.0394 gain after 100 steps when the process noise is left out
Read the full guide Fold the guide
Estimation theory is the branch of statistics that estimates unknown quantities from measured data with a random part, and the Kalman filter is its best-known working tool. A Kalman filter is an argument between two witnesses. One is a model that says where the thing should be now, given where it was a moment ago. The other is a sensor that says where it appears to be, with some noise on top. The filter does not pick a winner; it weighs them, and the weights come from how much each witness has earned.
Seen as a recursive Bayesian estimator, it treats the true state as a hidden process in which each state depends only on the one before it, and it updates its belief with each new reading. When the noise is Gaussian and the model is linear, the best estimate in the minimum mean square error sense comes out as a simple formula. That is the whole idea, and everything else is bookkeeping.
The idea is older than the name. Wiener had already shown how to estimate a signal buried in noise, but his filter assumes stationary signal and noise spectra and a fixed linear filter. Rudolf Kalman recast the problem in state-space form, where the state evolves step by step, and the result could run one reading at a time. The page on Kalman himself records that a visit to NASA Ames in 1960 led to the filter being used in the Apollo programme.
What the filter trusts
Each step has two halves. In the predict half the filter pushes its state forward with the model and grows its covariance, which is its own written claim about how wrong it might be. In the update half it compares the prediction with the reading. The gap is the innovation. Its variance is the predicted spread plus the sensor spread, and the gain is the share of the gap that gets believed.
Position readings alone are enough to recover velocity, because the pair is observable: the state can be estimated from the outputs. The covariance matrix is worth a second look. It is symmetric, and its diagonal holds variances, so a covariance of 1.08 on position means the filter claims a standard deviation near 1.04. A filter that claims too little is overconfident, and an overconfident filter stops listening.
The gain has a property that surprises people. It never depends on a reading. It is fixed by the model matrix, the process noise, the measurement noise and the starting covariance, so you can compute the whole gain history before a single number arrives. With a constant-velocity model, a step of 1, an acceleration standard deviation q of 0.1, a reading standard deviation r of 2 and a starting covariance of 100, the gain on position is 0.9804 at the first step. The filter has no idea where the thing is, so it nearly copies the reading.
By step 10 the gain is 0.3564, and it keeps falling toward 0.2709 for position and 0.0427 for velocity. After 19 steps every entry is within 1 percent of its final value. The final value is a fixed point. If the covariance stops changing, it must satisfy the discrete algebraic Riccati equation, which says the prior covariance equals the one propagated from itself after one update.
The tool solves that equation with a doubling iteration that converges in eight rounds here, and the answer matches the solver in SciPy. The steady prior covariance is 1.4860 for position and 0.06844 for velocity. After the update the position variance is 1.0835, which is well under the reading variance of 4. Model and sensor together beat the sensor alone.
The same fixed gains appear in an older and simpler tool. A constant-velocity Kalman filter with constant noise settings converges to the structure of the alpha beta filter, whose two gains someone had to choose by hand. The Kalman filter is the version where the gains are derived from the noise instead of guessed.
For a scalar random walk the steady state has a closed form. With a step variance q of 0.04 and a reading variance r of 1, the prior variance is (q + sqrt(q squared + 4 q r)) divided by 2, which is 0.2210, and the gain is 0.1810. Raise q relative to r and the gain rises, because a model that drifts freely deserves less trust.
The noise settings are the tuning
Nothing else in the filter is free. The model matrices describe the physics and the covariance starts as a guess that washes out. The one place a person decides anything is q and r, and the filter is optimal only if they match the real noise, the noise is white, and the model is right.
For the constant-velocity model, q is the standard deviation of a random acceleration that holds for one step. That gives a process noise matrix with dt to the fourth over four in the corner, dt cubed over two off the diagonal and dt squared in the last place, all times q squared. Written this way it cannot be forgotten, because it falls out of the physics.
The classic mistake is to leave it out. With no process noise the covariance can only shrink, the gain falls every step, and the filter slowly stops listening. On the example track the position gain is 0.0394 after 100 steps instead of 0.2709, and the velocity gain is 0.0006. The velocity estimate is frozen near its start while the thing keeps moving, and the position error is 9.23 against 1.94 for the raw readings.
The second mistake is units. The filter wants a variance for the reading noise, and people hand it a standard deviation. With r equal to 2 the filter sees 2 where 4 belongs, trusts the sensor twice too much, and settles on a gain of 0.3131 instead of 0.2709. The error is small enough to hide, which is what makes it dangerous. A third is putting the process noise after the update instead of in the prediction. The gain at each step is then computed from a prior that has not yet grown, and the final gain comes out at 0.2737. Plausible, slightly wrong, and wrong at every step.
The covariance update has its own trap. The short form, identity minus K H times P, is correct only when the gain is the optimal one. The Joseph form is valid for any gain and is the one to use when you are not sure. Force a gain of 0.5 into every entry and the two forms disagree by about 1.0038 at the last step, while with the right gain they agree to rounding.
Smooth is not consistent
An optimal filter leaves a white noise sequence behind it: its innovations carry no pattern. That gives a test that needs no truth. Divide each squared innovation by its predicted variance. If the model and the noise settings are right, each of those numbers is the square of a standard normal one, and the sum of m of them follows a chi-squared distribution with m degrees of freedom, whose mean is m.
So the mean of the normalised innovation squared should sit near 1, inside a band set by the 2.5 and 97.5 percent points of chi-squared divided by m. For the 90 steps after a ten-step burn-in the band runs from 0.729 to 1.313. The correct filter on the example scores 0.973, inside it. The burn-in is skipped because the start state is a guess, not a measurement.
Now look at the filter with no process noise. Its output wiggles less than the correct one, 0.74 against 1.03 in root-mean-square second difference, and far less than the raw readings at 5.45. It looks tidy. Its mean normalised innovation squared is 27.7, far above the band, and that number is the honest report: the filter is certain of something that is not true.
This is why a smooth output is a poor reason to call a filter tuned. Smoothness comes cheaply from a small gain. Consistency has to be earned from the noise settings. The standard deviation mistake fails in a quieter way, with a mean of 1.84 that is also above the band. Mistakes that hide in a plot show up in the check. Passing proves less than failing. A mean inside the band means the data do not contradict the settings, and a short record has a wide band. The tool does not run the whiteness test on the innovations; that would be a further check on the same residuals.
What the filter cannot do
A filter built for constant velocity believes the velocity changes slowly. Give it a track whose speed jumps by 3 right after step 50 and it cannot follow at once. In the tool’s simulated track, with q at 0.1, the estimate trails the true position by up to 3.909 at step 54. With q at 1 the lag is 0.944. A larger q lets the filter follow the jump, but a high gain also makes the estimate jumpier.
That limit is the model’s, not a bug in the arithmetic. Fixing it means a bigger q, a model with an acceleration state, or several models running at once. The tool shows the limit instead of hiding it, because a user who never sees a lag will assume there is none.
The tool also stays inside a narrow lane. It runs a linear filter on one position with fixed noise settings. It does not do nonlinear or extended filters, smoothing backward in time, missing readings or several targets. It does not certify any filter for navigation, tracking or control, and it measures nothing about a real sensor.
The examples are simulated, and a seeded generator makes them repeatable. The generator uses the 32-bit integer multiply that JavaScript exposes as Math.imul, and the readings are rounded to three decimals before the filter sees them. Because the true positions are known, the tool can report the error against truth, something a real sensor never allows. On the main example the filter’s position error is 0.978 against 1.937 for the raw readings.
In the field you will not have that luxury. You will have the consistency check, the gain history and the honest question of whether q and r describe the world. Those are the controls worth learning to read. The estimate is the part everyone looks at, and it is the least informative part of the picture.
Sources
Every source consulted for this guide. Links checked November 22, 2026.
- Kalman filter Wikipedia (CC BY-SA)
- Algebraic Riccati equation Wikipedia (CC BY-SA)
- Recursive Bayesian estimation Wikipedia (CC BY-SA)
- Rudolf E. Kalman Wikipedia (CC BY-SA)
- State-space representation Wikipedia (CC BY-SA)
- Covariance matrix Wikipedia (CC BY-SA)
- Wiener filter Wikipedia (CC BY-SA)
- Alpha beta filter Wikipedia (CC BY-SA)
- Chi-squared distribution Wikipedia (CC BY-SA)
- Estimation theory Wikipedia (CC BY-SA)
- Observability Wikipedia (CC BY-SA)
- Minimum mean square error estimator Wikipedia (CC BY-SA)
- solve_discrete_are - SciPy v1.18.0 Manual SciPy documentation
- scipy.stats.chi2 - SciPy v1.18.0 Manual SciPy documentation
- Math.imul() - JavaScript MDN Web Docs