The Kalman filter is an (optimal) estimator of linear systems with Gaussian (Normal) error statistics. It is useful for making educated guesses about:
- the value of something given a lot of noisy data (Smoothing noisy data)
- the value of something given missing data (Estimating missing data)
- the value of something is the future (Forecasting future states and observations)
Cool examples of the use of Kalman Filters include the Apollo navigation computer, vehicle tracking, estimating financial time series and satellite navigation1.
How it works
1. The model
The Kalman filter assumes that the state of a system evolves from a prior state at time according to the equation:
where is the prior state, () is optional control input and () is a noise term representing uncertainty about the prior state. The uncertainty () is assumed to be multivariate normal with a zero mean and has a covariance matrix (called the Process noise covariance matrix) indicating the extent that each state varies with another. The matrix is called the ‘System Equation’ represents how a system evolves through time.
For example if the state x is a vector representing the position and velocity of a person moving at a constant speed then the system matrix (F) would represent the equation and and the system equation would be
The Kalman filter also assumes that observations of the state of system are a linear function2 of the states plus a noise term:
where () is the observed state, () is the transformation matrix that translates states to the measurement domain, and () is measurement noise assumed to be zero mean with covariance().
2. Estimating true state of the system given some observations
The state of the system can not be observed directly due to noise and perhaps also due to a transformation from the state domain to the observation domain. For example, you might be estimating the position of a person based on observations of their speed. Therefore an algorithm is required to estimate the state () (position). Estimates of the parameters () are not discrete values but described by probability density functions (pdfs). These pdfs are assumed to be Gaussian and their covariances are described by a covariance matrix (). The Kalman filter algorithm estimates () using a two-step recursive algorithm: 1) state prediction; 2) measurement update. The state prediction estimates the state given the system matrix and knowledge of the state at the previous time step. The measurement update combines information provided by the observations with those of state prediction to generate an updated (improved) estimate of the states.
The Kalman state estimation equations are:
where () are the covariances associated with the predicted state vector.
The Kalman measurement update equations are:
where () is the optimal Kalman gain which is a function of the relative certainty of the measurements vs the current state. () represents the residual of the measurement. () represents the covariance of the residual.
Equation 5 is stating that the updated state is the estimated state () + some proportion of the difference between the measurement ()) and the estimate. This proportion is determined by the Kalman gain matrix ()).
Equation 6 is stating that the updated covariance for the estimate is the estimated covariance + some proportion of the covariance of the residuals. This proportion is determined by the Kalman gain ().
Equation 7 is stating that the optimal kalman gain is the current estimate of the state covariances mapped to the measurement domain ‘divided’ by the residual covariance . If the residual covariance is small then the Kalman gain is large. This means that the estimates produced by equation 5 will put more weight on the estimate residuals when they are close to the estimated residuals and less emphasis when they are far away from the expected value. E.g. If observations are noisy then pay little attention if they are close to expected then pay attention.
These equations can be applied to any problem that you can formulate in state space form.
3. Deriving the Kalman State Estimation Equations
The state estimation equation (3) is a straight-forward application of equation one to calculate an estimate of x given its prior state and any known control inputs. The covariance estimation equation (4) is simply the variance3 of the state estimation i.e. . Since we do not know the value $latex(x_t)$ we need to derive it by subtracting equations 1 from 3.
4. Deriving the Kalman Measurement Estimation Equations
The update of the state given an observation (Equation 5) can be thought of as the estimated state updated with some amount of the residual. If the weight of the residual is 1 then the state estimate is updated to the observation, conversely if the weight of the residual is 0 then the state estimate ignores the observation.
This equation is justified on the properties of Gaussian statistics – namely when you multiply two Gaussian pdfs their distribution is also a Gaussian pdf4. This can be thought of in terms of the multiplication of exponentials is equivalent to summing the exponents which means that () and () are linear functions of the previous ()and (). As it can be seen above the weighted sum is a linear function of means. It is also in a form similar to the following known result when multipling normal PDFs (). and the updated variance is ().
The update of the covariance matrix (Equation 6) may be similarly constructed to the state update equation.
It may be thought of as the estimated ()reduced in proportion to the observed variance. As it can be seen above the weighted sum is a linear function of the variance and therefore fits the form expected of a normal distribution.
- A linear function, or more strictly speaking an affine function, is the equation of a line (mx +c) i.e. a value multiplied by a constant plus a constant.↩
- See for example http://www.johndcook.com/blog/2012/10/29/product-of-normal-pdfs/↩