Unscented Kalman Filter

Intuition

β€œIt is easier to approximate a probability distribution than it is to approximate an arbitrary nonlinear function”

Idea

We perform a nonlinear transformation h(x)h(x) on the 1D gaussian distribution (left), the result is a more complicated 1D distribution (right). We already know the mean and the standard deviation of the input gaussian, and we want to figure out the mean and standard deviation of the output distribution using this information and the nonlinear function.

ζˆͺ屏2022-07-21 17.02.49

UKF gives us a way to do this ny three steps

  1. Choose sigma points from our input distribution

    ζˆͺ屏2022-07-21 17.08.42
  2. Transform sigma points

    ζˆͺ屏2022-07-21 17.10.05
  3. Compute weighted mean and covariance of transformed sigma points, which will give us a good approximation of the true output distribution.

    ζˆͺ屏2022-07-21 17.11.07

Unscented Transform

Choosing sigma points

For an NN-dimensional PDF N(ΞΌx,Ξ£xx)\mathcal{N}\left(\mu_{x}, \Sigma_{x x}\right) , we need 2N+12N+1 sigma points

  • One for the mean
  • and the rest symmetrically distributed about the mean

1D:

ζˆͺ屏2022-07-21 17.44.13

2D:

ζˆͺ屏2022-07-21 17.44.42

Steps

  1. Compute the Cholesky Decomposition of the covariance matrix

    LLT=Ξ£xx \mathbf{L} \mathbf{L}^{T}=\boldsymbol{\Sigma}_{x x}
  2. Calculate the sigma points

    x0=ΞΌxxi=ΞΌx+N+ΞΊcol⁑iLi=1,…,Nxi+N=ΞΌxβˆ’N+ΞΊcol⁑iLi=1,…,N \begin{aligned} \mathbf{x}_{0} &=\boldsymbol{\mu}_{x} & & \\ \mathbf{x}_{i} &=\boldsymbol{\mu}_{x}+\sqrt{N+\kappa} \operatorname{col}_{i} \mathbf{L} & & i=1, \ldots, N \\ \mathbf{x}_{i+N} &=\boldsymbol{\mu}_{x}-\sqrt{N+\kappa} \operatorname{col}_{i} \mathbf{L} & & i=1, \ldots, N \end{aligned}
    • ΞΊ\kappa: tuning parameter. for Gaussian PDFs, setting ΞΊ=3βˆ’N\kappa = 3 - N is a good choice.

Transforming

Pass each of the 2N+12N + 1 sigma points through the nonlinear function h(x)\mathbf{h}(x)

yi=h(xi)i=0,…,2N \mathbf{y}_{i}=\mathbf{h}\left(\mathbf{x}_{i}\right) \quad i=0, \ldots, 2 N

Recombining

Compute the mean and covariance of the output PDF

  • mean

    ΞΌy=βˆ‘i=02NΞ±iyi \boldsymbol{\mu}_{y}=\sum_{i=0}^{2 N} \alpha_{i} \mathbf{y}_{i}
  • covariance

    Ξ£yy=βˆ‘i=02NΞ±i(yiβˆ’ΞΌy)(yiβˆ’ΞΌy)T \boldsymbol{\Sigma}_{y y}=\sum_{i=0}^{2 N} \alpha_{i}\left(\mathbf{y}_{i}-\boldsymbol{\mu}_{y}\right)\left(\mathbf{y}_{i}-\boldsymbol{\mu}_{y}\right)^{T}

with weights

Ξ±i={ΞΊN+ΞΊi=0121N+ΞΊ otherwise  \alpha_{i}=\left\{\begin{array}{lr} \frac{\kappa}{N+\kappa} & i=0 \\ \frac{1}{2} \frac{1}{N+\kappa} & \text { otherwise } \end{array}\right.

Example

ζˆͺ屏2022-07-22 10.51.19

Compared to linearization (red), we can see the unscented transform (orange) gives a much better approximation!

ζˆͺ屏2022-07-22 10.52.26

The Unscented Kalman Filter (UKF)

πŸ’‘Idea: Instead of approximating the system equations by linearizing, we will calculate sigma points and use the Unscented Transform to approxiamte the PDFs directly.

Prediction step

To propagate the state from time kβˆ’1k-1 to time kk, apply the Unscented Transform using the current best guess for the mean and covariance.

  1. Compute sigma points

    L^kβˆ’1L^kβˆ’1T=P^kβˆ’1(Cholesky Decomposition)x^kβˆ’1(0)=x^kβˆ’1x^kβˆ’1(i)=x^kβˆ’1+N+ΞΊcol⁑iL^kβˆ’1i=1…Nx^kβˆ’1(i+N)=x^kβˆ’1βˆ’N+ΞΊcol⁑iL^kβˆ’1i=1…N \begin{array}{rlrl} \hat{\mathbf{L}}_{k-1} \hat{\mathbf{L}}_{k-1}^{T} & =\hat{\mathbf{P}}_{k-1} & (\text{Cholesky Decomposition})& \\ \hat{\mathbf{x}}_{k-1}^{(0)} & =\hat{\mathbf{x}}_{k-1} & & \\ \hat{\mathbf{x}}_{k-1}^{(i)} & =\hat{\mathbf{x}}_{k-1}+\sqrt{N+\kappa} \operatorname{col}_{i} \hat{\mathbf{L}}_{k-1} & i=1 \ldots N \\ \hat{\mathbf{x}}_{k-1}^{(i+N)} & =\hat{\mathbf{x}}_{k-1}-\sqrt{N+\kappa} \operatorname{col}_{i} \hat{\mathbf{L}}_{k-1} & i=1 \ldots N \end{array}
  2. Propagate sigma points

    x˘k(i)=fkβˆ’1(x^kβˆ’1(i),ukβˆ’1,0)i=0…2N \breve{\mathbf{x}}_{k}^{(i)}=\mathbf{f}_{k-1}\left(\hat{\mathbf{x}}_{k-1}^{(i)}, \mathbf{u}_{k-1}, \mathbf{0}\right) \quad i=0 \ldots 2 N
  3. Compute predicted mean and covariance (under the assumption of additive noise)

    Ξ±(i)={ΞΊN+ΞΊi=0121N+ΞΊ otherwise xΛ‡k=βˆ‘i=02NΞ±(i)xΛ‡k(i)PΛ‡k=βˆ‘i=02NΞ±(i)(xΛ‡k(i)βˆ’xΛ‡k)(xΛ‡k(i)βˆ’xΛ‡k)T+Qkβˆ’1 \begin{aligned} \alpha^{(i)} &=\left\{\begin{array}{ll} \frac{\kappa}{N+\kappa} & i=0 \\ \frac{1}{2} \frac{1}{N+\kappa} & \text { otherwise } \end{array}\right.\\\\ \check{\mathbf{x}}_{k} &=\sum_{i=0}^{2 N} \alpha^{(i)} \check{\mathbf{x}}_{k}^{(i)} \\\\ \check{\mathbf{P}}_{k} &=\sum_{i=0}^{2 N} \alpha^{(i)}\left(\check{\mathbf{x}}_{k}^{(i)}-\check{\mathbf{x}}_{k}\right)\left(\check{\mathbf{x}}_{k}^{(i)}-\check{\mathbf{x}}_{k}\right)^{T}+\mathbf{Q}_{k-1} \end{aligned}

Correction step

To correct the state estimate using measurement at time kk, use the nonlinear measurement model and the sigma points from the prediction step to predict the measurements.

  1. Predict measurements from propagated sigma points

    y^k(i)=hk(xΛ‡k(i),0)i=0…2N \hat{\mathbf{y}}_{k}^{(i)}=\mathbf{h}_{k}\left(\check{\mathbf{x}}_{k}^{(i)}, \mathbf{0}\right) \quad i=0 \ldots 2 N
  2. Estimate mean and covariance of predicted measurements

    y^k=βˆ‘i=02NΞ±(i)y^k(i)Py=βˆ‘i=02NΞ±(i)(y^k(i)βˆ’y^k)(y^k(i)βˆ’y^k)T+Rk \begin{array}{l} \hat{\mathbf{y}}_{k}=\displaystyle \sum_{i=0}^{2 N} \alpha^{(i)} \hat{\mathbf{y}}_{k}^{(i)} \\ \mathbf{P}_{y}=\displaystyle\sum_{i=0}^{2 N} \alpha^{(i)}\left(\hat{\mathbf{y}}_{k}^{(i)}-\hat{\mathbf{y}}_{k}\right)\left(\hat{\mathbf{y}}_{k}^{(i)}-\hat{\mathbf{y}}_{k}\right)^{T}+\mathbf{R}_{k} \end{array}
  3. Compute cross-covariance and Kalman Gain

    Pxy=βˆ‘i=02NΞ±(i)(xΛ‡k(i)βˆ’xΛ‡k)(y^k(i)βˆ’y^k)TKk=PxyPyβˆ’1 \begin{aligned} \mathbf{P}_{x y} &=\sum_{i=0}^{2 N} \alpha^{(i)}\left(\check{\mathbf{x}}_{k}^{(i)}-\check{\mathbf{x}}_{k}\right)\left(\hat{\mathbf{y}}_{k}^{(i)}-\hat{\mathbf{y}}_{k}\right)^{T} \\\\ \mathbf{K}_{k} &=\mathbf{P}_{x y} \mathbf{P}_{y}^{-1} \end{aligned}
  4. Compute corrected mean and covariance

    x^k=xΛ‡k+Kk(ykβˆ’y^k)P^k=PΛ‡kβˆ’KkPyKkT \begin{array}{l} \hat{\mathbf{x}}_{k}=\check{\mathbf{x}}_{k}+\mathbf{K}_{k}\left(\mathbf{y}_{k}-\hat{\mathbf{y}}_{k}\right) \\ \hat{\mathbf{P}}_{k}=\check{\mathbf{P}}_{k}-\mathbf{K}_{k} \mathbf{P}_{y} \mathbf{K}_{k}^{T} \end{array}

UKF Example

ζˆͺ屏2022-07-22 11.09.51

ζˆͺ屏2022-07-22 11.10.52

Prediction step

2D state estimate β‡’N=2,ΞΊ=3βˆ’N=1\Rightarrow N=2, \quad \kappa=3-N=1

  1. Compute sigma points

    L^0L^0T=P^0[0.1001][0.1001]T=[0.01001] \begin{aligned} &\hat{\mathbf{L}}_{0} \hat{\mathbf{L}}_{0}^{T}=\hat{\mathbf{P}}_{0} \\ &{\left[\begin{array}{cc} 0.1 & 0 \\ 0 & 1 \end{array}\right]\left[\begin{array}{cc} 0.1 & 0 \\ 0 & 1 \end{array}\right]^{T}=\left[\begin{array}{cc} 0.01 & 0 \\ 0 & 1 \end{array}\right]} \end{aligned} x^0(0)=x^0x^0(i)=x^0+N+ΞΊcol⁑iL^0i=1…,Nx^0(i+N)=x^0βˆ’N+ΞΊcol⁑iL^0i=1,…,Nx^0(0)=[05]x^0(1)=[05]+3[0.10]=[0.25]x^0(2)=[05]+3[01]=[06.7]x^0(3)=[05]βˆ’3[0.10]=[βˆ’0.25]x^0(4)=[05]βˆ’3[01]=[03.3] \begin{aligned} \hat{\mathbf{x}}_{0}^{(0)} &=\hat{\mathbf{x}}_{0} \\ \hat{\mathbf{x}}_{0}^{(i)} &=\hat{\mathbf{x}}_{0}+\sqrt{N+\kappa} \operatorname{col}_{i} \hat{\mathbf{L}}_{0} \quad i=1 \ldots, N \\ \hat{\mathbf{x}}_{0}^{(i+N)} &=\hat{\mathbf{x}}_{0}-\sqrt{N+\kappa} \operatorname{col}_{i} \hat{\mathbf{L}}_{0} \quad i=1, \ldots, N \\ \hat{\mathbf{x}}_{0}^{(0)} &=\left[\begin{array}{l} 0 \\ 5 \end{array}\right] \\ \hat{\mathbf{x}}_{0}^{(1)} &=\left[\begin{array}{l} 0 \\ 5 \end{array}\right]+\sqrt{3}\left[\begin{array}{c} 0.1 \\ 0 \end{array}\right]=\left[\begin{array}{c} 0.2 \\ 5 \end{array}\right] \\ \hat{\mathbf{x}}_{0}^{(2)} &=\left[\begin{array}{l} 0 \\ 5 \end{array}\right]+\sqrt{3}\left[\begin{array}{c} 0 \\ 1 \end{array}\right]=\left[\begin{array}{c} 0 \\ 6.7 \end{array}\right] \\ \hat{\mathbf{x}}_{0}^{(3)} &=\left[\begin{array}{l} 0 \\ 5 \end{array}\right]-\sqrt{3}\left[\begin{array}{c} 0.1 \\ 0 \end{array}\right]=\left[\begin{array}{c} -0.2 \\ 5 \end{array}\right] \\ \hat{\mathbf{x}}_{0}^{(4)} &=\left[\begin{array}{l} 0 \\ 5 \end{array}\right]-\sqrt{3}\left[\begin{array}{l} 0 \\ 1 \end{array}\right]=\left[\begin{array}{c} 0 \\ 3.3 \end{array}\right] \end{aligned}
  2. Propagate sigma points

    xΛ‡1(i)=f0(x^0(i),u0,0)i=0,…,2NxΛ‡1(0)=[10.501][05]+[00.5](βˆ’2)=[2.54]xΛ‡1(1)=[10.501][0.25]+[00.5](βˆ’2)=[2.74]xΛ‡1(2)=[10.501][06.7]+[00.5](βˆ’2)=[3.45.7]xΛ‡1(3)=[10.501][βˆ’0.25]+[00.5](βˆ’2)=[2.34]xΛ‡1(4)=[10.501][03.3]+[00.5](βˆ’2)=[1.62.3] \begin{aligned} &\check{\mathbf{x}}_{1}^{(i)}=\mathbf{f}_{0}\left(\hat{\mathbf{x}}_{0}^{(i)}, \mathbf{u}_{0}, \mathbf{0}\right) \quad i=0, \ldots, 2 N \\ &\check{\mathbf{x}}_{1}^{(0)}=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{c} 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] \\ &\check{\mathbf{x}}_{1}^{(1)}=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{c} 0.2 \\ 5 \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.5 \end{array}\right](-2)=\left[\begin{array}{c} 2.7 \\ 4 \end{array}\right] \\ &\check{\mathbf{x}}_{1}^{(2)}=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{c} 0 \\ 6.7 \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.5 \end{array}\right](-2)=\left[\begin{array}{c} 3.4 \\ 5.7 \end{array}\right] \\ &\check{\mathbf{x}}_{1}^{(3)}=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{c} -0.2 \\ 5 \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.5 \end{array}\right](-2)=\left[\begin{array}{c} 2.3 \\ 4 \end{array}\right] \\ &\check{\mathbf{x}}_{1}^{(4)}=\left[\begin{array}{cc} 1 & 0.5 \\ 0 & 1 \end{array}\right]\left[\begin{array}{c} 0 \\ 3.3 \end{array}\right]+\left[\begin{array}{c} 0 \\ 0.5 \end{array}\right](-2)=\left[\begin{array}{c} 1.6 \\ 2.3 \end{array}\right] \end{aligned}
  3. Compute predicted mean and covariance (under the assumption of additive noise)

    Ξ±(i)={ΞΊN+ΞΊ=12+1=13i=0121N+ΞΊ=1212+1=16 otherwise xΛ‡k=βˆ‘i=02NΞ±(i)xΛ‡k(i)=13[2.54]+16[2.74]+16[3.45.7]+16[2.34]+16[1.62.3]=[2.54] \begin{aligned} \alpha^{(i)} &=\left\{\begin{array}{l} \frac{\kappa}{N+\kappa}=\frac{1}{2+1}=\frac{1}{3} \quad i=0 \\ \frac{1}{2} \frac{1}{N+\kappa}=\frac{1}{2} \frac{1}{2+1}=\frac{1}{6} \quad \text { otherwise } \end{array}\right.\\\\ \\ \check{\mathbf{x}}_{k}&=\sum_{i=0}^{2 N} \alpha^{(i)} \check{\mathbf{x}}_{k}^{(i)} \\ &=\frac{1}{3}\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]+\frac{1}{6}\left[\begin{array}{c} 2.7 \\ 4 \end{array}\right]+\frac{1}{6}\left[\begin{array}{l} 3.4 \\ 5.7 \end{array}\right]+\frac{1}{6}\left[\begin{array}{c} 2.3 \\ 4 \end{array}\right]+\frac{1}{6}\left[\begin{array}{l} 1.6 \\ 2.3 \end{array}\right]=\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right] \end{aligned} PΛ‡k=βˆ‘i=02NΞ±(i)(xΛ‡k(i)βˆ’xΛ‡k)(xΛ‡k(i)βˆ’xΛ‡k)T+Qkβˆ’1=13([2.54]βˆ’[2.54])([2.54]βˆ’[2.54])T+16([2.74]βˆ’[2.54])([2.74]βˆ’[2.54])T+16([3.45.7]βˆ’[2.54])([3.45.7]βˆ’[2.54])T+16([2.34]βˆ’[2.54])([2.34]βˆ’[2.54])T+16([1.62.3]βˆ’[2.54])([1.62.3]βˆ’[2.54])T+[0.1000.1]=[0.360.50.51.1] \begin{aligned} \check{\mathbf{P}}_{k}=& \sum_{i=0}^{2 N} \alpha^{(i)}\left(\check{\mathbf{x}}_{k}^{(i)}-\check{\mathbf{x}}_{k}\right)\left(\check{\mathbf{x}}_{k}^{(i)}-\check{\mathbf{x}}_{k}\right)^{T}+\mathbf{Q}_{k-1} \\ =& \frac{1}{3}\left(\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)\left(\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)^{T}+\\ & \frac{1}{6}\left(\left[\begin{array}{c} 2.7 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)\left(\left[\begin{array}{c} 2.7 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)^{T}+\frac{1}{6}\left(\left[\begin{array}{c} 3.4 \\ 5.7 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)\left(\left[\begin{array}{c} 3.4 \\ 5.7 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)^{T}+\\ & \frac{1}{6}\left(\left[\begin{array}{c} 2.3 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)\left(\left[\begin{array}{c} 2.3 \\ 4 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)^{T}+\frac{1}{6}\left(\left[\begin{array}{c} 1.6 \\ 2.3 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\right)\left(\left[\begin{array}{c} 1.6 \\ 2.3 \end{array}\right]-\left[\begin{array}{c} 2.5 \\ 4 \end{array}\right]\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

  1. Predict measurements from propagated sigma points

    ζˆͺ屏2022-07-22 11.47.22

  2. Estimate mean and covariance of predicted measurements

    ζˆͺ屏2022-07-22 11.47.33

  3. Compute cross-covariance and Kalman Gain

    ζˆͺ屏2022-07-22 11.49.43

  4. Compute corrected mean and covariance

    ζˆͺ屏2022-07-22 11.49.59

Summary

  • The UKF use the unscented transform to adpat the Kalman filter to nonlinear systems.
  • The unscented transform works by passing a small set of carefully chosen samples through a nonlinear system, and computing the mean and covariance of the outputs.
  • The unscented transform does a better job of approixmating the output distribution than analytical local linearization, for similar computational cost

Comparision of Nonlinear KF

ζˆͺ屏2022-07-22 11.57.02

Reference