# The Kalman Filter

These notes are based on

Meinhold R.J., Singpurwalla N.D., (1983):
Understanding the Kalman Filter.
*The American Statistician*, 37, 123–127.

## Model

The **Kalman Filter** provides an efficient recursive estimator for
the unobserved state of a linear discrete time dynamical system in the
presence of measurement error. Kalman (1960) first introduced the
method in the Engineering literature, but it can be understood in the
context of Bayesian inference.

Let ${y}_{t}$ denote a vector of observed variables at time $t$ and let ${s}_{t}$ denote the unobserved state variables of the system at time $t$. We wish to conduct inference about the state variables given only the observed data $\{{y}_{t}\}$ and the structure of a linear model consisting of a measurement equation and a transition equation.

The evolution of the observed variable depends on the state variables through a linear measurement equation

The variable ${y}_{t}$ is observed with measurement error which follows the Normal distribution with mean zero and covariance matrix ${\Omega}_{\epsilon}$.

The state vector ${s}_{t}$ obeys the transition equation

where $G$ and ${\Omega}_{\eta}$ are known matrices and ${\eta}_{t}$ captures the influence of effects that are outside the model on the state transition process. The noise terms ${\epsilon}_{t}$ and ${\eta}_{t}$ are independent. In general $G$ and $F$ can be time-dependent but for the sake of simplicity the time subscripts are omitted here.

The Kalman Filter is similar in nature to the standard linear regression model. The state of the process ${s}_{t}$ corresponds to the regression coefficients, however the state is not constant over time, requiring the introduction of the transition equation.

## Bayesian Interpretation

Let ${Y}_{t}=({y}_{t},{y}_{t-1},\dots ,{y}_{1})$ denote the complete history of observed data at time $t$. Our goal is to obtain the posterior distribution of ${s}_{t}$ given ${Y}_{t}$. We know from Bayes’ Theorem that

The left-hand side is the posterior distribution of ${s}_{t}$. On the second line, the first term is the likelihood of ${s}_{t}$ and the second term is the prior distribution of ${s}_{t}$. This equation defines a recursive Bayesian updating relationship.

At time $t-1$, our knowledge of the system is summarized by the the posterior distribution

where ${\hat{s}}_{t-1}$ is our previous estimate about the mean of ${s}_{t-1}$. This process is initialized at time $0$ by specifying ${\hat{s}}_{0}$ and ${\Sigma}_{0}$.

Before observing ${y}_{t}$, our best prediction of ${s}_{t}$ comes from (2), namely $G{s}_{t-1}+{\eta}_{t}$. However, combining this with (4), we have

where

This follows directly from the properties of the multivariate Normal distribution.

After observing ${y}_{t}$, we can update our knowledge about ${s}_{t}$ using the likelihood $\mathrm{Pr}({y}_{t}|{s}_{t},{Y}_{t-1})$. Let ${e}_{t}$ denote the error in predicting ${y}_{t}$,

Observing ${e}_{t}$ is equivalent to observing ${y}_{t}$ since $F$, $G$, and ${s}_{t-1}$ are all known. Thus, (3) becomes

Now, using the measurement equation (1), we can write ${e}_{t}=F({s}_{t}-G{\hat{s}}_{t-1})+{\epsilon}_{t}$, and therefore

Now, from Bayes’ Theorem the posterior distribution of ${s}_{t}$ satisfies

Once this probability is computed, we can perform another iteration of the recursion by going back to (3).

## Calculating the Posterior Distribution

We can calculate the posterior distribution (10) directly by appealing to the properties of the Normal Distribution. Note that

where ${R}_{t}$ is given by (6). Conditional on ${e}_{t}$, the distribution of ${s}_{t}$ is

To summarize, the posterior distribution of ${s}_{t}$ was be calculated recursively by first choosing initial values for ${s}_{0}$ and ${\Sigma}_{0}$. Then at each period $t$, given the posterior distribution of ${s}_{t-1}$, with mean ${\hat{s}}_{t-1}$ and covariance matrix ${\Sigma}_{t-1}$ as in (4), we form a prior for ${s}_{t}$ with mean $G{\hat{s}}_{t-1}$ and variance ${R}_{t}=G{\Sigma}_{t-1}{G}^{\top}+{\Omega}_{\eta}$ as in (5), evaluate the likelihood in (9) given ${e}_{t}={y}_{t}-FG{\hat{s}}_{t-1}$, and then arrive at the posterior in time $t$ given by (12).

## Algorithm

Using the theoretical derivation as a guide, we can implement the **Kalman Filter**
as a recursive algorithm. Given initialization values ${s}_{0}$ and ${\Sigma}_{0}$, at time $t$,

The posterior distribution at time $t-1$ is Normal with mean ${\hat{s}}_{t-1}$ and covariance matrix ${\Sigma}_{t-1}$.

Form the covariance matrix of the prior distribution, $${R}_{t}=G{\Sigma}_{t-1}{G}^{\top}+{\Omega}_{\eta};$$

Calculate the mean of the posterior, $${\hat{s}}_{t}=G{\hat{s}}_{t-1}+{R}_{t}{F}^{\top}({\Omega}_{\epsilon}+F{R}_{t}{F}^{\top}{)}^{-1}{e}_{t};$$

Calculate the variance of the posterior: $${\Sigma}_{t}={R}_{t}-{R}_{t}{F}^{\top}({\Omega}_{\epsilon}+F{R}_{t}{F}^{\top}{)}^{-1}F{R}_{t}.$$