Linear Kalman Filter

Intuition Example

ζˆͺ屏2022-07-19 15.40.40

Estimation of the 1D position of the vehicle.

Starting from an initial probabilistic estimate at time kβˆ’1k-1

Note: The initial estimate, the predicted state, and the final corrected state are all random variabless that we will specify their means and covariances.

  1. Use a motion model to predict our new state
  2. Use observation model (e.g. derived from GPS) to correct that prediction of vehicle position at time kk

In this way, we can think of the Kalman filter as a technique to fuse information from different sensors to produce a final estimate of some unknown state, taking the uncertainty in motion and measurements into account.

The Linear Dynamical System

Motion model:

ζˆͺ屏2022-07-19 16.07.45 xk=Fkβˆ’1xkβˆ’1+Gkβˆ’1ukβˆ’1+wkβˆ’1 \mathbf{x}_{k}=\mathbf{F}_{k-1} \mathbf{x}_{k-1}+\mathbf{G}_{k-1} \mathbf{u}_{k-1}+\mathbf{w}_{k-1}

where

  • uk\mathbf{u}_k: control input
  • wk\mathbf{w}_k: process/motion noise. wk∼N(0,Qk)\mathbf{w}_{k} \sim \mathcal{N}\left(\mathbf{0}, \mathbf{Q}_{k}\right)

Measurement model

yk=Hkxk+vk \mathbf{y}_{k}=\mathbf{H}_{k} \mathbf{x}_{k}+\mathbf{v}_{k}

where

  • vk\mathbf{v}_{k}: measurement noise. vk∼N(0,Rk)\mathbf{v}_{k} \sim \mathcal{N}\left(\mathbf{0}, \mathbf{R}_{k}\right)

Kalman Filter Steps

Prediction

We use the process model to predict how our state evolves since the last time step, and will propagate our uncertainty.

xΛ‡k=Fkβˆ’1xkβˆ’1+Gkβˆ’1ukβˆ’1PΛ‡k=Fkβˆ’1P^kβˆ’1Fkβˆ’1T+Qkβˆ’1 \begin{array}{l} \check{\mathbf{x}}_{k}=\mathbf{F}_{k-1} \mathbf{x}_{k-1}+\mathbf{G}_{k-1} \mathbf{u}_{k-1} \\ \check{\mathbf{P}}_{k}=\mathbf{F}_{k-1} \hat{\mathbf{P}}_{k-1} \mathbf{F}_{k-1}^{T}+\mathbf{Q}_{k-1} \end{array}

Correction

We use measurement to correct that prediction

Notation:

  • xΛ‡k\check{x}_k: a prediction before the measurement is incorporated

  • x^k\hat{x}_k: corrected prediction at time step kk

  • Optimal Gain

    Kk=PΛ‡kHkT(HkPΛ‡kHkT+Rk)βˆ’1 \mathbf{K}_{k}=\check{\mathbf{P}}_{k} \mathbf{H}_{k}^{T}\left(\mathbf{H}_{k} \check{\mathbf{P}}_{k} \mathbf{H}_{k}^{T}+\mathbf{R}_{k}\right)^{-1}
  • Correction

    x^k=xΛ‡k+Kk(ykβˆ’HkxΛ‡k)⏟innovationP^k=(Iβˆ’KkHk)PΛ‡k \begin{aligned} \hat{\mathbf{x}}_{k} &=\check{\mathbf{x}}_{k}+\mathbf{K}_{k}\underbrace{\left(\mathbf{y}_{k}-\mathbf{H}_{k} \check{\mathbf{x}}_{k}\right)}_{\text{innovation}} \\ \hat{\mathbf{P}}_{k}&=\left(\mathbf{I}-\mathbf{K}_{k} \mathbf{H}_{k}\right) \check{\mathbf{P}}_{k} \end{aligned}

Summary

ζˆͺ屏2022-07-19 16.46.13

Example

Consider a self-driving vehicle estimating its own position.

The state vector includes the position and its first derivative, velocity.

x=[pdpdt=pΛ™] \mathbf{x}=\left[\begin{array}{c} p \\ \frac{d p}{d t}=\dot{p} \end{array}\right]

Input is the scalar acceleration

u=a=d2pdt2 \mathbf{u}=a=\frac{d^{2} p}{d t^{2}}

THe linear dynamical system is

  • Motion/Process model

    xk=[1Ξ”t01]xkβˆ’1+[0Ξ”t]ukβˆ’1+wkβˆ’1 \mathbf{x}_{k}=\left[\begin{array}{cc} 1 & \Delta t \\ 0 & 1 \end{array}\right] \mathbf{x}_{k-1}+\left[\begin{array}{c} 0 \\ \Delta t \end{array}\right] \mathbf{u}_{k-1}+\mathbf{w}_{k-1}
  • Position observation

    yk=[10]xk+vk y_{k}=\left[\begin{array}{ll} 1 & 0 \end{array}\right] \mathbf{x}_{k}+v_{k}
  • Nose densities

    vk∼N(0,0.05)wk∼N(0,(0.1)12Γ—2) v_{k} \sim \mathcal{N}(0,0.05) \quad \mathbf{w}_{k} \sim \mathcal{N}\left(\mathbf{0},(0.1) \mathbf{1}_{2 \times 2}\right)

Given the data at time step k=0k=0

x^0∼N([05],[0.01001])Ξ”t=0.5 su0=βˆ’2[ m/s2]y1=2.2[ m] \begin{array}{l} \hat{\mathbf{x}}_{0} \sim \mathcal{N}\left(\left[\begin{array}{l} 0 \\ 5 \end{array}\right],\left[\begin{array}{cc} 0.01 & 0 \\ 0 & 1 \end{array}\right]\right) \\ \Delta t=0.5 \mathrm{~s} \\ u_{0}=-2\left[\mathrm{~m} / \mathrm{s}^{2}\right] \quad y_{1}=2.2[\mathrm{~m}] \end{array}

We want to estimate the state at time step k=1k=1.

Prediction step

xΛ‡k=Fkβˆ’1xkβˆ’1+Gkβˆ’1ukβˆ’1[pΛ‡1pΛ‡1]=[10.501][05]+[00.5](βˆ’2)=[2.54] \begin{aligned} \check{\mathbf{x}}_{k} &=\mathbf{F}_{k-1} \mathbf{x}_{k-1}+\mathbf{G}_{k-1} \mathbf{u}_{k-1} \\\\ {\left[\begin{array}{c} \check{p}_{1} \\ \check{p}_{1} \end{array}\right] } &=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{l} 0 \\ 5 \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.5 \end{array}\right](-2)=\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right] \end{aligned} PΛ‡k=Fkβˆ’1P^kβˆ’1Fkβˆ’1T+Qkβˆ’1PΛ‡1=[10.501][0.01001][10.501]T+[0.1000.1]=[0.360.50.51.1] \begin{aligned} \check{\mathbf{P}}_{k} &=\mathbf{F}_{k-1} \hat{\mathbf{P}}_{k-1} \mathbf{F}_{k-1}^{T}+\mathbf{Q}_{k-1} \\\\ \check{\mathbf{P}}_{1} &=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{cc} 0.01 & 0 \\ 0 & 1 \end{array}\right]\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]^{T}+\left[\begin{array}{cc} 0.1 & 0 \\ 0 & 0.1 \end{array}\right]=\left[\begin{array}{cc} 0.36 & 0.5 \\ 0.5 & 1.1 \end{array}\right] \end{aligned}

Correction step

  • Kalman Gain

    K1=PΛ‡1H1T(H1PΛ‡1H1T+R1)βˆ’1=[0.360.50.51.1][10](10][0.360.50.51.1][10]+0.05)βˆ’1=[0.881.22] \begin{aligned} \mathbf{K}_{1} &=\check{\mathbf{P}}_{1} \mathbf{H}_{1}^{T}\left(\mathbf{H}_{1} \check{\mathbf{P}}_{1} \mathbf{H}_{1}^{T}+\mathbf{R}_{1}\right)^{-1} \\ &\left.=\left[\begin{array}{cc} 0.36 & 0.5 \\ 0.5 & 1.1 \end{array}\right]\left[\begin{array}{l} 1 \\ 0 \end{array}\right]\left(\begin{array}{ll} 1 & 0 \end{array}\right]\left[\begin{array}{cc} 0.36 & 0.5 \\ 0.5 & 1.1 \end{array}\right]\left[\begin{array}{l} 1 \\ 0 \end{array}\right]+0.05\right)^{-1} \\ &=\left[\begin{array}{l} 0.88 \\ 1.22 \end{array}\right] \end{aligned}
  • Correction of the state prediction

    x^1=xΛ‡1+K1(y1βˆ’H1xΛ‡1)[p^1pΛ™^1]=[2.54]+[0.881.22](2.2βˆ’[10][2.54])=[2.243.63] \begin{aligned} \hat{\mathbf{x}}_{1} &=\check{\mathbf{x}}_{1}+\mathbf{K}_{1}\left(\mathbf{y}_{1}-\mathbf{H}_{1} \check{\mathbf{x}}_{1}\right) \\\\ {\left[\begin{array}{c} \hat{p}_{1} \\ \hat{\dot{p}}_{1} \end{array}\right] } &=\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]+\left[\begin{array}{c} 0.88 \\ 1.22 \end{array}\right]\left(2.2-\left[\begin{array}{ll} 1 & 0 \end{array}\right]\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)=\left[\begin{array}{l} 2.24 \\ 3.63 \end{array}\right] \end{aligned}
  • Correction of covariance

    P^1=(1βˆ’K1H1)PΛ‡1=[0.040.060.060.49] \begin{aligned} \hat{\mathbf{P}}_{1} &=\left(\mathbf{1}-\mathbf{K}_{1} \mathbf{H}_{1}\right) \check{\mathbf{P}}_{1} \\\\ &=\left[\begin{array}{ll} 0.04 & 0.06 \\ 0.06 & 0.49 \end{array}\right] \end{aligned}

    Note that the final covariance (i.e. the covariance after correction) is smaller. That is, we are more certain about the car position after we incoporate the position measurement. This uncertainty reduction occurs because our measurement model is fairly accurate (the measurement noise variance is quite small).

Best Linear Unbiased Estimator (BLUE)

If we have white, uncorrelated zero-mean noise, the Kalman Fitler is the best (i.e., lowest variance) unbiased estimator that uses only a linear combination of measurements.

Bias

We repeat the above Kalman filter for KK times.

ζˆͺ屏2022-07-19 22.29.32

The bias is defined as the difference between true position and the mean of estimated position values.

ζˆͺ屏2022-07-19 22.32.03

An estimator of filter is unbiased if it produces an β€œaverage” error of zero at a particular time step kk, over many trials.

E[e^k]=E[p^kβˆ’pk]=E[p^k]βˆ’pk=0βˆ€k∈N E\left[\hat{e}_{k}\right]=E\left[\hat{p}_{k}-p_{k}\right]=E\left[\hat{p}_{k}\right]-p_{k}=0 \qquad \forall k \in \mathbb{N}

Bias in Kalman filter state estimation

Consider the error dynamics

  • Predicted state error

    eΛ‡k=xΛ‡kβˆ’xk \check{\mathbf{e}}_{k}=\check{\mathbf{x}}_{k}-\mathbf{x}_{k}
  • Corrected state error

    e^k=x^kβˆ’xk \hat{\mathbf{e}}_{k}=\hat{\mathbf{x}}_{k}-\mathbf{x}_{k}

Using the Kalman Fitler equations, we can derive

eΛ‡k=Fkβˆ’1eΛ‡kβˆ’1βˆ’wke^k=(1βˆ’KkHk)eΛ‡k+Kkvk \begin{array}{l} \check{\mathbf{e}}_{k}=\mathbf{F}_{k-1} \check{\mathbf{e}}_{k-1}-\mathbf{w}_{k} \\ \hat{\mathbf{e}}_{k}=\left(\mathbf{1}-\mathbf{K}_{k} \mathbf{H}_{k}\right) \check{\mathbf{e}}_{k}+\mathbf{K}_{k} \mathbf{v}_{k} \end{array}

So long as

  • The initial state estimate is unbiased (E[e^0]=0E\left[\hat{\mathbf{e}}_{0}\right]=\mathbf{0} )
  • The noise is white, uncorrelated and zero mean (E[v]=0,E[w]=0E[\mathbf{v}]=\mathbf{0}, E[\mathbf{w}]=\mathbf{0} )

Then the state estiamte is unbiased

E[eΛ‡k]=E[Fkβˆ’1eΛ‡kβˆ’1βˆ’wk]=Fkβˆ’1E[eΛ‡kβˆ’1]βˆ’E[wk]=0 \begin{aligned} E\left[\check{\mathbf{e}}_{k}\right] &=E\left[\mathbf{F}_{k-1} \check{\mathbf{e}}_{k-1}-\mathbf{w}_{k}\right] \\ &=\mathbf{F}_{k-1} E\left[\check{\mathbf{e}}_{k-1}\right]-E\left[\mathbf{w}_{k}\right] \\ &=\mathbf{0} \end{aligned} E[e^k]=E[(1βˆ’KkHk)eΛ‡k+Kkvk]=(1βˆ’KkHk)E[eΛ‡k]+KkE[vk]=0 \begin{aligned} E\left[\hat{\mathbf{e}}_{k}\right] &=E\left[\left(\mathbf{1}-\mathbf{K}_{k} \mathbf{H}_{k}\right) \check{\mathbf{e}}_{k}+\mathbf{K}_{k} \mathbf{v}_{k}\right] \\ &=\left(\mathbf{1}-\mathbf{K}_{k} \mathbf{H}_{k}\right) E\left[\check{\mathbf{e}}_{k}\right]+\mathbf{K}_{k} E\left[\mathbf{v}_{k}\right] \\ &=\mathbf{0} \end{aligned}

Consistency

A filter is consistent if for all kk

E[e^k2]=E[(p^kβˆ’pk)2]=P^k E\left[\hat{e}_{k}^{2}\right]=E\left[\left(\hat{p}_{k}-p_{k}\right)^{2}\right]=\hat{P}_{k} ζˆͺ屏2022-07-19 23.22.43

This means that the filter is neither overconfident nor underconfident in the estimate it has produced.

The Kalman Fitler is consistent in state estimate.

E[eˇkeˇkT]=PˇkE[e^ke^kT]=P^k E\left[\check{\mathbf{e}}_{k} \check{\mathbf{e}}_{k}^{T}\right]=\check{\mathbf{P}}_{k} \qquad E\left[\hat{\mathbf{e}}_{k} \hat{\mathbf{e}}_{k}^{T}\right]=\hat{\mathbf{P}}_{k}

so long as

  • the initial state estimate is consistent (E[e^0e^0T]=PΛ‡0E\left[\hat{\mathbf{e}}_{0} \hat{\mathbf{e}}_{0}^{T}\right]=\check{\mathbf{P}}_{0} )
  • the noise is white and zero-mean (E[v]=0,E[w]=0E[\mathbf{v}]=\mathbf{0}, E[\mathbf{w}]=\mathbf{0} )

Reference