cswork / libraryOpen practice workspace

Articles

Kalman Filter Interview Questions: Predict-Update Steps, Q and R, and Inconsistent Measurements

Practice Kalman filter interviews with a numeric predict-update ledger, Q/R tuning, normalized innovations, missing readings, and recovery tests.

A tracker predicts a position of 10 with uncertainty variance 5. A sensor reads 14 with measurement-noise variance 4. Should the estimate jump to 14, ignore the sensor, or land between them? The next reading is 30: is it a real maneuver or a broken observation? These are better Kalman filter interview questions than a request to recite matrix notation from memory.

The mathematics below follows NASA's Kalman-filter technical memorandum and the FilterPy reference implementation. These are technical sources for the stated linear-Gaussian model. The numbered measurements are original interview practice, not a report from a named employer. For an adjacent uncertainty-and-state-estimation prompt, see Optimize Autonomy Mapping Components.

Start with the state and the two uncertainty contracts

In a linear state-space model, the state evolves as x_k = F x_(k-1) + B u_k + w_k, and a measurement follows z_k = H x_k + v_k. w represents process error with covariance Q; v represents measurement error with covariance R. The state estimate carries covariance P. The model assumes the noise properties needed for the usual Kalman optimality result; real sensors and dynamics must be checked against that model. NASA's memorandum writes the same idea with different matrix letters and makes the predict/measurement-update separation explicit.

The useful interview distinction is that Q and R attach to different mechanisms. Q says how uncertain the state transition is between observations. R says how uncertain a sensor observation is after applying its measurement model. P is the filter's current uncertainty about its state estimate, not a tunable substitute for either. A candidate who raises R to excuse every large residual may hide a changed physical process; one who raises Q for every noisy sensor may make the tracker needlessly reactive.

Before calculating, ask what is being tracked, its units, the sample interval, whether inputs are known, what each sensor measures, and how timestamps align. A one-dimensional position-only example is useful for arithmetic. A moving target with velocity often needs a position-and-velocity state, so a 1D example cannot validate a full tracking architecture. Establish the modeling boundary first, then run the numbers.

Question 1: can you complete one predict-update ledger?

Use a scalar constant-state example with F = H = 1, no control input, prior estimate x = 10, prior variance P = 4, process variance Q = 1, sensor variance R = 4, and new measurement z = 14. All numbers are in consistent position units or squared units. The NASA derivation gives the general covariance and innovation equations; the scalar simplification is:

StepCalculationResult
Predict meanx_minus = F x10
Predict varianceP_minus = F² P + Q5
Innovationy = z - H x_minus4
Innovation varianceS = H² P_minus + R9
GainK = P_minus H / S5/9 ≈ 0.556
Update meanx_plus = x_minus + K y12.222…
Update variance(1 - K H) P_minus20/9 ≈ 2.222

The answer lands between 10 and 14 because both the predicted state and the observation carry uncertainty. The measurement has variance 4 and the prior prediction variance 5, so the gain is slightly above one-half. In this simple model the posterior variance is lower than either independent input variance. Say that S includes both prediction and measurement uncertainty; dividing the residual by R alone would overstate how surprising it is.

An interview follow-up may use F ≠ 1 or a multivariate observation. Then the predict equations become x_minus = F x + B u and P_minus = F P Fᵀ + Q; update with y = z - H x_minus, S = H P_minus Hᵀ + R, and K = P_minus Hᵀ S⁻¹. Do not treat matrix multiplication as commutative. In implementation, solve a linear system for the gain rather than explicitly forming an inverse when numerical stability matters. The arithmetic ledger is the asset: if a later residual is extreme, you know which x_minus and S it must be compared with.

Question 2: what changes when Q or R changes?

Hold the first observation at 14 and rerun the scalar case. If Q grows, the predicted variance P_minus grows, so the filter gives a larger gain to the measurement. If R grows, the innovation variance S grows while its predicted-state contribution stays fixed, so the gain shrinks. This is a local directional statement for the same prior and measurement, not a promise that every real filter's long-run accuracy improves when a covariance is inflated.

For example, with the same P_minus = 5 but R = 25, gain is 5/30 = 1/6, and the estimate moves from 10 to roughly 10.667. With R = 1, gain is 5/6, and it moves to roughly 13.333. The two outputs show trust weighting, not two different physical truths. To choose R, examine calibrated sensor residuals under representative conditions, units, correlations, and operating regimes. To choose Q, inspect the error in the transition model over the actual time step, including unmodeled acceleration or drifting inputs. The covariance of a continuous noise model must be discretized consistently with the sample interval; copying a constant Q into a different frame rate can change behavior.

The signs of mis-tuning help in debugging but are not conclusive diagnoses. If R is too small, a filter can chase noise and report unrealistically tight uncertainty. If Q is too small, it may lag a genuine maneuver. If either is too large, uncertainty and gain can move in the opposite direction. Process and measurement error can be confounded from one short trace; compare against held-out trajectories or calibrated references, not just visually smooth output. NASA's estimation workshop covers the broader estimation context.

Question 3: is the second measurement inconsistent?

Continue the original scalar ledger after the first update. With F=H=1 and Q=1, the next predicted mean is about 12.222 and predicted variance about 3.222. If the next sensor value is z=30, the innovation is about 17.778. S = 3.222 + 4 ≈ 7.222, so normalized innovation squared, NIS = y²/S, is about 43.8. That is a very large discrepancy relative to this model's stated uncertainty. It does not, by itself, prove a sensor fault: the transition model, timestamp, association to a target, coordinate frame, or actual process could be wrong.

The NASA equations define innovation and its covariance. Under the modeled Gaussian conditions, a normalized innovation statistic can be compared with a preselected reference distribution or empirical calibration window. If a team uses a gate, state the probability level and dimension before inspecting this particular residual. Retrospectively choosing a threshold that excludes 30 is not a defensible test. For a vector observation use yᵀ S⁻¹ y, and check that S is well-conditioned and dimensions/units agree.

Then inspect raw evidence. Was the sample from the same target? Is z=30 expressed in the same coordinate frame as H x_minus? Did a stale measurement arrive after the state advanced? Did the target accelerate while a constant-state model assumed no motion? Are residuals biased over many samples or is this an isolated spike? If the sensor was clipped or obstructed, a skip-update policy may be justified. If a verified maneuver occurred, rejecting every large innovation can freeze the tracker on the wrong trajectory. A robust pipeline records the decision and its reason, and tests recovery after both a true outlier and a real state change.

Question 4: what happens when measurements are missing or delayed?

When no usable measurement arrives, the filter can perform a predict step and skip the update. In the scalar example, the mean remains at its transition prediction and variance grows by Q each gap. That is not a fabricated measurement of zero, nor should the state covariance remain fixed while the world advances. After a long gap, a genuine new observation will usually receive more weight because the predicted state is less certain—assuming the model and time step were updated correctly.

A delayed observation is harder. Feeding a reading captured at time t1 into a state predicted to t3 as though it were a t3 measurement corrupts innovation and can create a false outlier. Track sensor capture time separately from arrival time. Depending on latency and product constraints, buffer and reorder events, maintain past states for a retrospective update and repropagation, or discard samples older than an explicit horizon. State which choice preserves causal ordering and what user-visible delay it introduces. A filter library's update() method does not solve event-time ordering on its own.

With several sensors, each sensor has its own H and R, and measurement errors may be correlated. Sequentially applying two correlated measurements as independent can make P too small and the tracker overconfident. Check calibration, common upstream processing, and shared clocks before declaring independence. If a sensor drops out, log availability and continue from the remaining valid observations. If its variance changes with operating conditions, use an evidence-based R schedule rather than pretending the nominal lab value holds in rain, glare, or heat.

Question 5: why can an implementation be numerically fragile?

The compact posterior covariance expression (I - K H) P_minus is algebraically correct under the ideal Kalman gain, but finite-precision calculations can make a computed covariance nonsymmetric or slightly negative. FilterPy's source documentation uses the Joseph-form update, (I-KH) P_minus (I-KH)ᵀ + K R Kᵀ, to preserve covariance structure more robustly. This is a numerical engineering choice, not a change in the assumed physical noise model.

Tests should assert that state and observation dimensions match, matrices have compatible units, Q and R are symmetric positive semidefinite as intended, and the innovation covariance can be solved reliably. On a small scalar fixture, compare the code to the hand ledger. On a longer simulation, check empirical error and residual coverage over many trials, not only the final filtered line. Record package versions and floating-point tolerances. A filter can produce a smooth-looking plot while its reported uncertainty is badly calibrated.

If an interviewer asks whether Kalman filtering needs Gaussian data, answer with scope. The linear Kalman update is a best linear estimator under common second-moment assumptions, while the familiar full probabilistic optimality statements rely on stronger linear-Gaussian conditions. Nonlinear dynamics call for another model or approximation, such as an extended or unscented filter, but naming those methods does not repair a bad timestamp or a wrong coordinate transform. Diagnose the simple model first.

Question 6: how would you explain a failing tracker in one minute?

Start with a reproducible incident: “Our estimate lagged a sharp turn and then jumped toward one suspicious reading.” Ask for capture and arrival timestamps, predicted state, P_minus, raw z, H, Q, R, innovation, S, gain, and the update decision for each frame. Recompute one frame by hand. If the large residual is genuine motion, revisit the state transition and process covariance. If it is a misassociated or corrupt measurement, verify the sensor/association gate and the fallback path. Compare residual distributions before and after a proposed change on the same held-out sequence.

Separate three outcomes: accuracy against truth when available, uncertainty calibration, and operational behavior when the sensor is absent or inconsistent. Changing Q and R until the line looks attractive addresses none of those on its own. A strong interview response states a hypothesis, a discriminating trace, and a test that would disprove the hypothesis. It also says what the system does while uncertainty is high—slow down, abstain, request another sensor, or degrade a feature—rather than promising a confident position at every timestamp.

Sources and further reading