This post was translated from Korean into English by AI.
A Kalman filter is a probabilistic method for estimating the state of a system from measurements. There are several ways to explain the Kalman filter. For example, it can be interpreted as a state observer or viewed as a combination of a low-pass filter and a high-pass filter. In this post, however, I will explain the Kalman filter as an approximation of the Bayesian filter, which I consider the most fundamental perspective.
Multivariate Normal Distribution
The Kalman filter assumes that both the vector-valued state and its observations follow multivariate normal distributions. Therefore, understanding the Kalman filter first requires an understanding of these distributions.
Normal Distribution
First, the probability density function of a one-dimensional normal distribution is defined as follows.
x∼N(μ,σ2)⟺p(x)=2πσ1exp(−21(σx−μ)2)
Here, μ is the mean and σ2 is the variance.
Properties of Normal Distribution
The normal distribution has many useful properties. One of the most important is that normal distributions are closed under linear combinations. In other words, if x1∼N(μ1,σ12) and x2∼N(μ2,σ22), then ax1+bx2 also follows a normal distribution for any constants a and b.
This can be proved easily by first showing that normal distributions are closed under scalar multiplication and then showing that they are closed under addition. Closure under scalar multiplication is straightforward, so I will omit it and prove closure under addition. There are several ways to do this, but the most intuitive is to calculate it directly as follows.
First, the probability density function of the sum x=x1+x2 of two independent random variables x1∼p1(x) and x2∼p2(x) is given by the convolution of their probability density functions:
p(x)=∫p1(t)p2(x−t)dt
Substituting the probability density functions of the normal distributions gives the following.
Substituting this back into the original expression gives the following.
2πσ12+σ221exp(−2(σ12+σ22)(x−(μ1+μ2))2)
By the definition of the normal distribution, this is a normal distribution with mean μ1+μ2 and variance σ12+σ22.
Definition of Multivariate Normal Distribution
There are several definitions of the multivariate normal distribution. The most common defines it as a probability distribution in which every linear combination of the components is normally distributed. In other words, a random variable x∈Rn follows a multivariate normal distribution if aTx follows a normal distribution for every vector a∈Rn.
An equivalent definition regards a multivariate normal distribution as a linear combination of n mutually independent one-dimensional standard normal distributions. That is, for a vector z∈Rk consisting of k independent one-dimensional standard normal random variables x1,x2,…,xk, there exist a matrix A and a vector μ such that x=Az+μ. Here, A is an n×k matrix, and μ is an n-dimensional vector.
This can be expressed mathematically as follows.
x∼N(μ,Σ)⟺∃A∈Rn×k,μ∈Rn s.t. x=Az+μ,z∼N(0,I)
Properties of Multivariate Normal Distribution
The second definition makes several proofs more convenient, so I will use it here. When using the second definition, the relationship between the covariance matrix Σ and A is important. First, if the mean of the random variable x is μ, the covariance is defined as follows.
Σ=E[(x−μ)(x−μ)T]
This means that the entry in row i, column j of the covariance matrix is the covariance between the i-th and j-th components.
Now, substituting x=Az+μ into this expression gives the following covariance matrix.
This covariance matrix is positive definite. Positive definiteness means that xTΣx>0 holds for every nonzero vector x∈Rn. This is easy to see as follows.
xTΣx=xTAATx=(ATx)T(ATx)=∥ATx∥2>0
One exception is when the variance of some component is zero. This case is called degenerate, and the covariance matrix then has no inverse. In such cases, that component must be removed through marginalization or a similar technique before performing the calculation. This is a special case, however, and will not be covered here.
From this, we can show that the covariance matrix must be invertible.
The statement that ATx=0 for every x is equivalent to the column vectors of A being linearly independent.
Therefore, a positive definite matrix has full rank and is invertible.
Therefore, the covariance matrix of any multivariate normal distribution must be invertible.
Probability Density Function of Multivariate Normal Distribution
Next, we can derive the probability density function of the multivariate normal distribution. Consider an n-dimensional random variable z whose components are mutually independent and each have the standard normal probability density function. Since the probability density function of z is simply the product of the probability density functions of its components, it is given by the following.
Next, for any multivariate probability distribution x and any invertible transformation f, the following holds.
y=f(x)⇒p(y)=p(x)∂y∂x=p(f−1(y))∣det(J)∣1
Here, J is the Jacobian of f. If f is a linear transformation, the Jacobian is the transformation matrix A, in which case the expression is given as follows.
Given a system model and an observation model, a Bayesian filter infers the state from observations and provides mathematically optimal inference for a system represented as a hidden Markov chain. However, a Bayesian filter contains two integrals, and there is no easy way to evaluate them for arbitrary probability distributions. Consequently, these equations cannot be solved and used directly; they must be approximated in another form. As discussed in the previous post, the particle filter is a nonparametric approximation of the Bayesian filter and therefore makes no assumptions about the probability distributions or models. The Kalman filter discussed in this post is a parametric approximation of the Bayesian filter that assumes the system model and measurement model are linear Gaussian models of the following form.
xtzt=Ftxt−1+Btut+ϵt=Htxt+δt
The variables have the following meanings.
xt: state vector
zt: measurement vector
ut: control input vector
ϵt: state noise
δt: measurement noise
Ft: state transition matrix
Bt: control input matrix
Ht: measurement matrix
The state noise and measurement noise also follow Gaussian distributions as follows.
ϵtδt∼N(0,Qt)∼N(0,Rt)
We can now use these assumptions to derive the Kalman filter from the Bayesian filter. Because the Kalman filter assumes that the probability distributions are multivariate normal, each distribution is completely determined by its mean and covariance matrix. The Kalman filter therefore estimates the state mean μ and covariance Σ as follows.
In the prediction step, the current state estimates μt−1∣t−1 and Σt−1∣t−1 are used to calculate the next state estimates μt∣t−1 and Σt∣t−1.
In the update step, the measurement zt is used to calculate the current state estimates μt∣t and Σt∣t.
Prediction Step
First, the state prediction step of the Bayesian filter is given as follows.
The covariance is also readily derived from its definition. Because the calculation is complicated, I will temporarily omit the time subscripts in the proof and use the following notation.
This expression is very difficult to evaluate. In fact, however, we can show that it is a Gaussian distribution as follows.
The denominator of this expression is constant with respect to xt.
When expanded, the numerator takes the form exp(−xtTAxt) with respect to xt. Therefore, as long as its integral is 1, this distribution is Gaussian.
The denominator of this expression is the numerator integrated with respect to xt. Therefore, integrating the entire expression with respect to xt must give 1.
Accordingly, there is no need to calculate the entire expression; we only need to examine its mean and variance.
First, the probability density functions of the prior distribution and the measurement model are as follows.
Here, some terms involving xt were rewritten as terms involving xtT. This is because those terms are scalars and therefore remain unchanged when transposed.
We can now obtain the mean and standard deviation from the probability density above by comparing it with the expanded probability density function of a Gaussian distribution. Expanding the probability density function of a Gaussian distribution with mean m and covariance matrix P gives the following.
From this, we can see that the inverse of the coefficient in xT(∙)x is the covariance, and that multiplying the coefficient in −2xT(∙) by the covariance from the left gives the mean. Thus, the covariance of the original expression is
Σt∣t=(Σt∣t−1−1+HtTRt−1Ht)−1
and its mean is
μt∣t=Σt∣t(Σt∣t−1−1μt∣t−1+HtTRt−1zt)
In other words, the posterior distribution is given as follows.
However, the equations derived in this post differ from the form in which the Kalman filter is commonly presented. The Kalman Gain does not even appear in these equations. In fact, the Wikipedia article on the Kalman filter presents the prediction and update steps as follows. Although the notation differs slightly, the prediction step is identical to the one derived in this post, while the update step not only contains more stages but also has a completely different form.
However, we can show that the update step is also simply another form of the same equations.
First, to show that the covariances are equal, expand the covariance matrix in the update step of the general form, including the Kalman Gain, as follows.
Next, we apply the Woodbury matrix identity to the covariance matrix in the update step derived in this post. The Woodbury matrix identity is the following identity.
which is equal to the covariance matrix in the update step above.
The same method can be used to show that the means are also equal. As above, expanding the mean in the update step of the general form gives the following.
This is equal to the mean in the update step of the general form obtained earlier. Therefore, the method derived in this post and the general method—that is, the method using the Kalman Gain—are exactly equivalent.
Conclusion
In this post, we derived the Kalman filter directly from the Bayesian filter and showed that it is equivalent to the commonly used form of the Kalman filter. This allowed us to understand the Kalman filter as a parametric approximation of the Bayesian filter.