Statistics & probability

Kalman filter calculator from noisy measurements

Estimate a continuously valued hidden state from noisy measurements using a known linear state-space model.

Your numbers

Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.
Rows separated by semicolons; values by commas.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Estimate a continuously valued hidden state from noisy measurements using a known linear state-space model. The page keeps predicted uncertainty, measurement uncertainty and filtered uncertainty separate. It returns every filtered state, covariance, gain and innovation under an explicit predict-before-measurement convention, so the first observation is handled just as transparently as later observations.

THE FORMULAx−=F x; P−=F P Fᵀ+Q; K=P−Hᵀ(HP−Hᵀ+R)⁻¹.

A worked example

With scalar F=H=R=P0=1, Q=0 and prior mean zero, measurements one and two give first estimate 1/2 with variance 1/2, then estimate one with variance 1/3. Prediction precedes each observation.

Good to know

Constant linear Gaussian model, ≤4 states and observation dimensions, ≤200 measurement rows. Joseph covariance updates. No missing rows, smoothing, estimated model matrices or nonlinear filter.

Decide what the hidden state represents

A state vector describes the quantities you cannot observe perfectly, such as position and velocity. F advances that state between measurement times. H maps state coordinates into measurement coordinates. A two-entry state does not require two independent observations at each time, provided the supplied model and available observations are meaningful for the intended estimation problem.

The filter assumes the model matrices are known and constant. It does not learn a motion law from the measurement list. Choose units and a time interval before constructing F; using a matrix for one-second transitions with measurements collected ten seconds apart changes the model rather than merely changing a display label.

Two scalar Kalman updates combine noisy measurements with prior precisionPrior: 0, P=1First: 1/2, P=1/2Next: 1, P=1/3Measurements: 1, then 2; R=1, Q=0Gains: 1/2, then 1/3
With scalar F=H=R=P0=1, Q=0 and prior mean zero, measurements one and two give first estimate 1/2 with variance 1/2, then estimate one with variance 1/3. Prediction precedes each observation. Diagram is schematic; labels specify the numerical values.

The Hidden Markov model forward backward and Viterbi calculator uses a finite set of hidden states. Kalman filtering instead propagates a continuous state mean and covariance under the supplied linear Gaussian model.

Separate process noise from measurement noise

Q describes uncertainty added by the state evolution, while R describes uncertainty in each observation. Increasing Q allows the state to depart more from its predicted trajectory. Increasing R makes a measurement less informative relative to the predicted state. They are covariance matrices, so their diagonal entries are variances and their off-diagonal entries encode cross-coordinate uncertainty.

A standard deviation of two therefore contributes variance four, not two. Q and the prior covariance may be positive semidefinite, while this version requires R positive definite. A zero process variance is allowed; a zero observation variance is rejected rather than treated as a perfectly known measurement with potentially singular update equations.

Follow prediction before the first measurement

The prior state and covariance describe the instant before the first transition. The calculator first computes xminus=F x and Pminus=F P Ftranspose+Q, then compares the first observation with H xminus. This convention is important when comparing software that treats its supplied initial state as already belonging to the first observation time.

For a model with F equal to identity the distinction is easy to miss because the mean prediction is unchanged. With nonidentity F or nonzero Q, the first covariance and gain can differ substantially. Record the initialization time along with the state values; an apparently discrepant first result may simply use another timing convention.

Work through the scalar example without matrix notation

The default prior mean is zero and prior variance is one. With F=H=1, Q=0 and measurement variance one, the first observation one has innovation one and gain one half. Its filtered state becomes one half and its variance becomes one half. The result balances the prior and observation because their variances initially match.

The second observation is two. Predicted variance remains one half, so its gain is (1/2)/(1/2+1)=1/3. The innovation is 3/2 and the updated state is 1/2+(1/3)(3/2)=1. The new variance is one third. The filter has accumulated information; it is not just averaging the last pair of measurements.

Read gain, innovation and covariance together

An innovation is the measurement minus its predicted value. A large innovation can reflect an unusual observation, a model misspecification or simply large modeled measurement noise. Its numerical size alone is not an outlier test. The gain converts that measurement-space discrepancy into a correction expressed in state coordinates.

The returned covariance describes uncertainty conditional on the assumed linear Gaussian model, not an empirical error bound against ground truth. Its off-diagonal entries can remain nonzero even when Q and R are diagonal. Shared dynamics and partially observed states couple uncertainty, so inspecting only one variance can conceal important dependence.

Understand why the covariance update uses Joseph form

The algebraically simplified covariance update can lose symmetry or positive semidefiniteness through floating-point cancellation. Joseph form computes (I−KH)Pminus(I−KH)transpose+K R Ktranspose. Both terms have covariance structure, making the numerical update more reliable when gains are large or uncertainty scales differ.

This is a numerical safeguard, not a substitute for valid input covariances. A nonsymmetric matrix or a matrix with a materially negative eigenvalue is rejected. Nearly singular positive matrices can still be poorly conditioned, so very different coordinate scales may require rescaling rather than interpreting every printed decimal as equally reliable.

Know when filtering is insufficient

This page uses only observations up to the current row. A smoother would use later observations to revise earlier state estimates, which answers a different question. Missing observations, time-dependent matrices, control inputs and nonlinear models are also outside this constant-matrix form; none is silently inferred from an empty row.

To assess practical quality, compare innovations over time and test the estimated states against independent reference measurements when available. A visually smooth trajectory can be badly biased if the dynamics are wrong. Do not choose noise variances solely to make the curve look attractive; justify them from measurement precision and plausible model variation.

A few questions, answered

Are Q and R standard deviations?

No. They are covariance matrices. A standard deviation must be squared before it becomes a diagonal covariance entry.

Does this revise earlier estimates when later data arrive?

No. It is a forward filter. Smoothing is a separate calculation that uses future measurements.

Is the first entered state before or after the first observation?

Before the first transition. Prediction is performed before every observation, including the first.

Does a large gain mean the measurement is more accurate in absolute terms?

Not by itself. Gain depends on the relative predicted and measurement uncertainties and on the observation matrix.

Find your calculator

Start typing to explore the library.