skoro v0.0.0

The Kalman filter

The Kalman filter integrates the states of a linear-Gaussian chain out one at a time, so that what is left on each state is its prediction and, with its measurement, its update; its gain weighs the innovation, its evidence is the product of the innovations' densities, and in information or square-root form it is elimination along the chain, which carries a state its measurements do not yet determine.

Updated 2026-11-25 · 4 min read

A quantity that changes over time is a chain of states, each following the one before it, each measured. To know the latest state is to integrate every earlier one out, and when the chain is linear and Gaussian what that leaves is a normal on the latest state, which the next state’s integral starts from. That recursion is the Kalman filter [Kalm60]. This note states it in the form it is usually written, proves it from the integral, and then writes it as the elimination it is, which needs no covariance and so carries a state that the measurements do not yet determine.

The filter#

Proposition 1(The Kalman filter).

Let states x0,x1,…\randomPoint_0, \randomPoint_1, \dots in Rn\R^n and measurements z0,z1,…\bfz_0, \bfz_1, \dots follow the linear-Gaussian chain

x0∼N(μ0,P0),zk∣xk∼N(Hkxk,Rk),xk+1∣xk∼N(Fkxk,Qk), \randomPoint_0 \sim \mathcal N(\mu_0, P_0), \qquad \bfz_k \mid \randomPoint_k \sim \mathcal N(H_k \randomPoint_k, R_k), \qquad \randomPoint_{k+1} \mid \randomPoint_k \sim \mathcal N(F_k \randomPoint_k, Q_k),

with P0P_0, RkR_k and QkQ_k positive definite, and let the measurements be observed at z^0,z^1,…\hat z_0, \hat z_1, \dots. Set μ0−=μ0\mu_0^- = \mu_0 and P0−=P0P_0^- = P_0, and for each kk

νk=z^k−Hkμk−,Sk=HkPk−Hk⊤+Rk,Kk=Pk−Hk⊤Sk−1,μk+=μk−+Kkνk,Pk+=(I−KkHk)Pk−,μk+1−=Fkμk+,Pk+1−=FkPk+Fk⊤+Qk. \begin{gathered} \nu_k = \hat z_k - H_k \mu_k^- , \qquad S_k = H_k P_k^- H_k\transpose + R_k , \qquad K_k = P_k^- H_k\transpose S_k^{-1} , \\ \mu_k^+ = \mu_k^- + K_k \nu_k , \qquad P_k^+ = (I - K_k H_k) P_k^- , \\ \mu_{k+1}^- = F_k \mu_k^+ , \qquad P_{k+1}^- = F_k P_k^+ F_k\transpose + Q_k . \end{gathered}

Then integrating x0,…,xk−1\point_0, \dots, \point_{k-1}, in that order, out of the terms that read only them and xk\point_k, the prior, the motions up to xk\point_k and the measurements z0,…,zk−1\bfz_0, \dots, \bfz_{k-1} at their values, leaves on xk\point_k the factor

log⁡N(xk; μk−,Pk−)+∑j<klog⁡N(νj; 0,Sj), \log \mathcal N(\point_k;\, \mu_k^-, P_k^-) + \sum_{j < k} \log \mathcal N(\nu_j;\, 0, S_j) ,

and with zk\bfz_k also observed, the posterior of xk\randomPoint_k given z0,…,zk\bfz_0, \dots, \bfz_k is N(μk+,Pk+)\mathcal N(\mu_k^+, P_k^+).

Proof.

By induction on kk. For k=0k = 0 the factor is the prior, with no evidence. Suppose the factor on xk\point_k is as stated. With zk\bfz_k observed, the terms that read xk\point_k are that factor and the measurement’s log⁡N(z^k; Hkxk,Rk)\log \mathcal N(\hat z_k;\, H_k \point_k, R_k), and their sum, as a function of xk\point_k, is a factor of full rank, since Pk−P_k^- is positive definite. By Proposition 2 it is a normal with the precision and the information vector

(Pk+)−1=(Pk−)−1+Hk⊤Rk−1Hk,(Pk+)−1μk+=(Pk−)−1μk−+Hk⊤Rk−1z^k,(2) (P_k^+)^{-1} = (P_k^-)^{-1} + H_k\transpose R_k^{-1} H_k , \qquad (P_k^+)^{-1} \mu_k^+ = (P_k^-)^{-1} \mu_k^- + H_k\transpose R_k^{-1} \hat z_k , \tag{2}
(2)

and these agree with the statement’s covariance form. Dropping the index kk, (P−1+H⊤R−1H)PH⊤=H⊤R−1(R+HPH⊤)\bigl(P^{-1} + H\transpose R^{-1} H\bigr) P H\transpose = H\transpose R^{-1} (R + H P H\transpose), so P+H⊤R−1=PH⊤S−1=KP^+ H\transpose R^{-1} = P H\transpose S^{-1} = K. Then

μ+=P+((P+)−1μ−−H⊤R−1Hμ−+H⊤R−1z^)=μ−+K(z^−Hμ−),P+=P+((P+)−1−H⊤R−1H)P−=P−−KHP−. \begin{gathered} \mu^+ = P^+ \bigl( (P^+)^{-1} \mu^- - H\transpose R^{-1} H \mu^- + H\transpose R^{-1} \hat z \bigr) = \mu^- + K (\hat z - H \mu^-) , \\ P^+ = P^+ \bigl( (P^+)^{-1} - H\transpose R^{-1} H \bigr) P^- = P^- - K H P^- . \end{gathered}

The integral of the sum over xk\point_k is the density of z^k\hat z_k when xk∼N(μk−,Pk−)\randomPoint_k \sim \mathcal N(\mu_k^-, P_k^-) and zk=Hkxk+ε\bfz_k = H_k \randomPoint_k + \varepsilon with ε∼N(0,Rk)\varepsilon \sim \mathcal N(0, R_k) independent: a normal with mean Hkμk−H_k \mu_k^- and covariance SkS_k, at z^k\hat z_k, which is N(νk; 0,Sk)\mathcal N(\nu_k;\, 0, S_k). So the sum is log⁡N(xk; μk+,Pk+)\log \mathcal N(\point_k;\, \mu_k^+, P_k^+) plus that evidence, which is also the posterior of the statement. Adding the motion log⁡N(xk+1; Fkxk,Qk)\log \mathcal N(\point_{k+1};\, F_k \point_k, Q_k) and integrating xk\point_k out leaves the density of Fkxk+wF_k \randomPoint_k + w with xk∼N(μk+,Pk+)\randomPoint_k \sim \mathcal N(\mu_k^+, P_k^+) and w∼N(0,Qk)w \sim \mathcal N(0, Q_k) independent, the normal N(μk+1−,Pk+1−)\mathcal N(\mu_{k+1}^-, P_{k+1}^-), and the evidence is carried along unchanged.

∎

The names are the filter’s own. N(μk−,Pk−)\mathcal N(\mu_k^-, P_k^-) is the prediction of the state from the measurements before it, and N(μk+,Pk+)\mathcal N(\mu_k^+, P_k^+) its update by its own measurement. The innovation νk\nu_k is the measurement’s residual at the prediction, the part of it that the past did not foresee, SkS_k its covariance, and the gain KkK_k the weight the update gives it: near zero when the measurement is noisy against the prediction, and near the weight that makes the update reproduce the measurement, Hkμk+=z^kH_k \mu_k^+ = \hat z_k, when it is precise. The constant left over is the evidence, the density of all the measurements so far, a product of the innovations’ densities.

The scalar case. Take x0∼N(a,s2)\randomPoint_0 \sim \mathcal N(a, s^2), z0∣x0∼N(x0,r2)\bfz_0 \mid \randomPoint_0 \sim \mathcal N(\randomPoint_0, r^2) and x1∣x0∼N(x0,q2)\randomPoint_1 \mid \randomPoint_0 \sim \mathcal N(\randomPoint_0, q^2), and integrate x0\randomPoint_0 out with z0\bfz_0 observed at z^0\hat z_0. Writing N(m,v)(x)\mathcal N(m, v)(\point) for the normal density of mean mm and variance vv at x\point,

ℓB(x1)=log⁡N(a,s2+r2)(z^0)+log⁡N(μ,P+q2)(x1),K=s2s2+r2,μ=a+K(z^0−a),P=(1−K) s2.(3) \logterm_B(\point_1) = \log \mathcal N(a, s^2 + r^2)(\hat z_0) + \log \mathcal N(\mu, P + q^2)(\point_1), \qquad K = \frac{s^2}{s^2 + r^2}, \quad \mu = a + K(\hat z_0 - a), \quad P = (1 - K)\, s^2 . \tag{3}
(3)

The update moves the prior’s mean toward the measurement by the fraction KK of the innovation, and shrinks its variance by the same fraction; the prediction keeps the mean and adds the motion’s variance.

The filter as elimination#

The covariance form needs a covariance, and a state that its measurements do not yet determine has none. The information form (2) needs only a precision and an information vector, which is what the normal equations are, and it adds measurements by adding to them. Its prediction, integrating the state out of the update and the motion, is the integral of Proposition 1, which leaves a factor of any rank. So the information form starts from no prior at all, carries a state that is determined along some directions only, and becomes a normal at the first step whose factor has full rank.

The square-root form goes one step further and keeps the factors as rows. At each step it stacks the rows of the factor left on xk\point_k, of the measurement, whitened by RkR_k, and of the motion, whitened by QkQ_k, and eliminates the block of xk\point_k by an orthogonal factorization, which leaves the rows of a factor on xk+1\point_{k+1}. That is elimination of the chain in its own order, the order of a path, in which no block’s elimination creates fill: each step is a dense factorization of a few blocks, and its cost does not grow with the chain. It works at the condition number of the rows, and not, as the covariance form’s subtraction (I−KH)P(I - K H) P does, at that of the matrices built from them.

What the filter is not. The filter’s update is the posterior of the state given the measurements so far. Elimination along the chain, followed by back substitution from the last state to the first, gives instead the mode of every state given every measurement, the minimizer of the whole chain’s objective; on a linear-Gaussian chain that is the mean of each state’s posterior given all the data, the smoothed mean, which a filter, looking only backward, does not compute. And on a chain whose means are not linear, the filter that linearizes each step at its prediction takes one Gauss–Newton step per state, from that prediction, and is not the mode of anything: it is exact where the linearization is.

References

  1. [Kalm60] R. E. Kalman. A New Approach to Linear Filtering and Prediction Problems. Journal of Basic Engineering 82(1), 35–45. 1960.

Built on by