**Kalman Filter**

*Smriti Gupta, Ophir Gal*

* Kalman filtering* is an algorithm for estimating the true value of some variable of interest and is more accurate then the value produced by a series of measurements alone. It tends to converge onto the true value more quickly than simply taking the mean of the measurements. It is an iterative process relying on a series of noisy measurements over time, where the estimate at each time step relies solely on that of the previous time step and the current measurement/observation. It is called a filter since it essentially filters out the noise. The filter is named after Rudolf Kalman, one of its prominent developers.

Kalman filtering is basically a two-step process: **prediction** and** update. **The algorithm gets initialized with the first estimate (usually some educated guess) and predicts the next estimate by comparing **some predicted value** with the **sensor's (noisy) measurement/observation**. These two values are weighted and combined to yield an updated estimate where the weights are determined by the percentage of uncertainty.

*Animation of the Kalman Filter in action: the dotted red line represents the noisy measurements and the green curve is the filtered estimates (the horizontal axis represents time). *

**Formal Definition**

**Formal Definition**

**X**, the**Mean State Vector**, contains the information about the quantities the measurement depends on, e.g. position and velocity in the case of autonomous vehicles. The physical quantities are described by gaussian distribution with mean**x**.**P**, the**State Covariance Matrix**, contains information about the uncertainty in the quantities on which measurement depends.**k**is the**number of time steps.****X k+1|k**is the**Prediction Step**- you receive sensor measurements to update your belief and the algorithm predicts the next measurement at time k+1.**X k+1|k**is the**Update Step**- After prediction by the algorithm, sensor measurements are used to update the physical quantities.

*A block diagram describing two iterations of the Kalman Filter process.*

**The Dynamic Model:**

**X**_{k }**= F**_{k}**X**_{k-1 }**+ B**_{k}**U**_{k }**+ ****V**_{k}_{ }where **X**_{k} is the estimate of our true state at time step k.

**X**_{k-1}is the estimate of the state at time step k-1.**F**_{k}is the state-transition model.**H**_{k}is the observation model.**Q**_{k}is the covariance of the process noise.**R**_{k}is the covariance of the observation noise.**B**_{k}is the control input matrix.**U**_{k}_{ }is the control variable.**V**_{k}is the noise/error/uncertainty in the predicted state.

**Prediction :**

**Predicted state estimate: **

X' = FX+V ,

when you know X (initial measurements) you can predict X' using this equation.

**Increase in uncertainty (process noise):**

P’ = FPF^{T }+ Q,

the process noise, refers to uncertainty in the prediction, which can be represented by a gaussian distribution with a mean of zero.

**Update: **

After getting sensor data,

**Measurement Update:**

Y = Z - H X' ,

where H is the measurement function that maps the predicted state to the measurement space.

For example, LIDAR only measures position but Kalman Filter models both position and velocity, so H is used to map the values from the measurement domain to the prediction domain.

S = H P’ H^{T }+ R

where S is called the innovation covariance.

**Kalman Filter Gain:**

K = P’H^{T}S^{-1}, ^{ }

it combines uncertainty of where we think the correct measurement is, P' with an uncertainty of our measurement R.

If R>>p', sensor measurements are uncertain, and the Kalman filter will give more weight to prediction.

If R<<P', more weight is given to the sensor's measurement.

Measurement noise represents the uncertainty of the measurements.

**New updated state:**

X = X’+ K Y

**Update covariance estimate:**

P = ( I - K H) P’

**State transition Function - **

**B**is the control input matrix.**U**is the control Vector.**B*U**represents and updates the state of our object (e.g. the position of a car) due to some internal force (e.g. of the motor of the car) when we know how much acceleration and deceleration is going to happen over time.**V**is the random noise.**B*U = 0**when internal forces are not able to model.

**Q update (Process Covariance matrix):**

To model the stochastic part of the state transition matrix we have

P’ = FPF^{T }+ Q,

The state vector only tracks physical quantities like velocity and position in autonomous vehicle. The Q matrix includes the time, * dt*, to account for the fact that as more time passes we become more uncertain about the velocity and position. So as

*increases we need to add more uncertainty to the state covariance matrix P. We can also model acceleration as random noise.*

**dt**For illustration, let's look at a diagram describing the use of Kalman Filter with LIDAR and RADAR data to estimate position and velocity:

*As you can see in the diagram, covariance matrix and state matrices are generated after the first measurement and prediction are made. The state is updated as new measurements come in.*

## Disadvantages

Vanilla Kalman filters assume Gaussian distributions and linear functions underlie the data. Most real world problems have a non-linear relationship between the update and prediction phases as they involve angles and other factors. Vanilla Kalman filters cannot be used for non-linear functions. When you feed a gaussian distribution with a non-linear function the result is a non-gaussian distribution.

**Key Results**

**Key Results**

It has been shown that Kalman Filters are optimal linear filters (i.e. minimize the expected mean squared error between the real value and estimated value) under the following assumptions: (1) the true system generating the values is exactly described by the model used in the filter, and (2) the noise in the system is uncorrelated, and the noise covariances are known. *A**utocovariance least-squares* is one of several methods that have been developed to estimate covariances.

The performance of the filter can be evaluated once you obtain estimates of the covariance. The optimality or performance of the filter is indicated by the "whiteness" of the noise of the output prediction error, which can be assessed in a number of ways. There are also methods for measuring the performance when the noise terms are non-Gaussian distributed using probability inequalities or large-sample theory [6], [7].

**Connection to Decision-Making in Robotics**

**Connection to Decision-Making in Robotics**

Kalman filtering has many applications in technology. One of the main applications is in the guidance, navigation and control of vehicles, especially aircraft or space vehicles (where navigation systems have difficulty verifying the location using waypoints). In fact, It was used in the Ranger, Mariner, and Apollo missions of the 1960s. In particular, the on-board computer that guided the moon-landing of the Apollo 11 lunar module used a Kalman filter. It is also widely applied in signal processing and econometrics.

The filter is also used in robotics motion planning and sensor fusion in localization. For example, you may want to navigate your autonomous vehicle according to a series of noisy data from LIDAR and RADAR sensors which consists of errors or inaccurate measurements that may lead to collisions. Using Kalman filters, we can predict better estimates using a relatively small number of measurements over time instead of using the last measurement alone. It helps to solve MDP problems.

**Non-Linear Variants**

**Non-Linear Variants**

## Extended Kalman Filter

For non-linear functions, an extended version of Kalman filter is used. It linearizes non-linear functions by employing a multivariate Taylor series approximation.

**Linearizing the H function**

One can linearize the H function by taking a Taylor series approximation of the non-linear function.

This approximation is tangent to H at the mean location of the original gaussian.

*A non-linear function with its linearized approximation.*

*Source: **http://cognitoware.com/tutorials/ExtendedKalmanDifferentialDrive.htm*

**First Order Taylor Expansion**

**First Order Taylor Expansion**

**H****(x) ≈****H****(a) + D****H****(a)(x−a)****H(a)**, a non-linear function at 'a' - best prediction of predicted estimation.**D****H****(a)(x−a)**, extrapolation around 'a'.**H(x) = arc(tan(x))**, projects the predicted state x onto the measurement space.**DH(a)**- Jacobian matrix

**Algorithm**

**Algorithm**

For Extended Kalman Filter, the function does not need to be linear, but it should be differentiable.

x_{k= }= f_{k}x_{k-1}+W_{k}

y = Hx’ + v

The W_{k} and * v* are multivariate gaussian noises with mean 0 and covariance Q and R respectively. The Jacobian is used to combine measurements with observations as they cannot be directly combined. At each time step, Jacobian matrix is created to produce estimates.

**Prediction:**

Predicted state estimate** , **x' = f(x,u)** ,** when you know * x* you can predict

*using this equation.*

**x'**The increase in uncertainty P’ = FPF

^{T }+ Q represents the uncertainty in the prediction step which can be represented by gaussian distribution with mean zero.

**Update: **

After getting sensor data we preform the **measurement update:**

y = z - h(x),

where h is the measurement function that maps the predicted state into measurement space.

S = H P’ H^{T }+ R

**Kalman Filter Gain: **

K = P’H^{T}S^{-1}, ^{ }it combines the uncertainty of where we think the correct measurement is, P', with the uncertainty of our measurement R.

If R>>p', sensor measurements are uncertain then Kalman filter will give more weight to prediction.

If R<<P', more weight will be given to the sensor's measurement. Measurement noise refers to the uncertainty in the measurements.

**New updated state:**

x = x'+ K y

**Update covariance estimate: **

P = ( I - K H) P’

where the state transition matrix and observation matrix are Jacobians F = f'(x) and H = h'(x).

*As you can see in the figure, first Extended Kalman filter (EKF) matrices were generated for the input data. In the prediction step, new EKF matrices, covariance matrix, and state transition matrix were generated to make the first prediction. For the RADAR data, Jacobian matrices are first computed as they produce non-linear data while for LIDAR, vanilla Kalman filter works. The state is updated with new measurements.*

## Disadvantages

Extended Kalman filters may sometimes linearize very fast and hence fail to produce a good estimate. They may produce a highly deviated covariance matrix than the covariance matrix formed by true measurement. For further optimization, particle filters and Monte Carlo methods are commonly used.

## Unscented Kalman Filter

This is an alternative solution to the non-linear functions of Extended Kalman Filter (EKF). When the **f** and **h** functions are highly non-linear, EKF does not work as the covariance (or uncertainty) will propagate, leading to poor performance.

It uses a minimal set of sigma points which are randomly sampled points around the mean. They are further used to predict a new mean and covariance estimate. This is a deterministic process which removes the Jacobian calculation process and produces the true mean through an **unscented transformation**. Here, we need to find a normal distribution that is as close to the true distribution as possible that has a common mean and covariance matrix.

### Sigma Points

It is very easy to transform points of the state space with a non-linear transformation. Sigma points are chosen to be around the mean state and in a certain relation to the variance of every dimension of the state.

### Algorithm

The algorithm follows two steps as before: prediction and update.

**Process model:**

x_{k|k } = f(x_{k}_{,}ν_{κ})

** Prediction** - done in three steps: generating sigma points, predicting new sigma points and predicting new mean and covariance.

**Update **- done in two steps: measurement prediction and a state update.

ήx - **dimension of state vector**, number of physical quantities.

ήσ -** number of sigma points** = 2*ήx+1 with first point to be mean of the distribution.

*Diagram describing the Unscented Kalman Filter algorithm.*

(chi) χ_{κ|κ}= [x_{k|k } x_{k|k}+ sqrt((λ+η_{x})P_{k|k}) x_{k|k}- sqrt((λ+η_{x})P_{k|k})] - generation of sigma points

x_{k|k } - the mean state estimate

x_{k|k}+ sqrt((λ+η_{x})P_{k|k}) - 2 sigma points

x_{k|k}- sqrt((λ+η_{x})P_{k|k}) - 2 sigma points in opposite direction.

λ -** design parameter** - it determines the location of sigma points. A large value of **λ** moves sigma points **away from** the mean state and a smaller value moves them** towards **the mean state.

ν_{κ - }**process noise vector**, independent of change in time. To find its value we only need to know the stochastic properties of noise.

[ x_{k|k }|ν_{κ} ]- **Augmented state vector** - formed after combining the state vector and process noise vector, also called augmented covariance matrix. For this matrix as well - sigma points are calculated in the same way.

**Predicted mean:**

x_{k+1|k = } ε(i=0-n_{a}) (ω_{i}* χ_{k+1|k,i})

**Predicted Covariance:**

P_{k+1|k = } ε(i=0-2*n_{a}) [ω_{i}*( χ_{k+1|k,i}-x_{k+1|k })*( χ_{k+1|k,i}-x_{k+1|k })T]

ω_{i }=λ/(λ+na), for i=0

ω_{i }=1/2*(λ+na), for i=1,2,3....na)

**Update: **

**Measurement model:**

** **** **Z_{k+1}=h(x_{K+1}) + w_{k+1}

This is the same process as prediction. Instead of generating sigma points we use points from prediction. Here, measurement noise **w**_{k+1}_{ }have additive effect so we do not need to calculate the augmented matrix. We will transform sigma points into measurement step and calculate mean and covariance.

S_{k+1|k = } ε(i=0-2*n_{a}) [ω_{i}*( Z_{k+1|k,i}-z_{k+1|k })*( Z_{k+1|k,i}-z_{k+1|k })T]

**Update Step: **

For this we need actual measurement from sensor

**Kalman Gain:**

_{ }K_{k+1|k }=T_{k+1|k}S_{k+1|k}^{-1}

**State Update****: **

** **** **x_{k+1|k}_{ =}x_{k+1|k}_{+1}+K_{k+1|k }*( Z_{k+1}-z_{k+1|k })

**Covariance Matrix update : **

** **** **P_{k+1|k }_{ =}P_{k+1|k -}-K_{k+1|k}*P_{k+1|k }*.K^{T}_{k+1|k }

**Cross Correlation between sigma points in measurement space and state space:**

T_{k+1|k }=ε(i=0-2*n_{a}) [ω_{i}*( χ_{k+1|k,i}-x_{k+1|k })*( Z_{k+1|k,i}-z_{k+1|k })T]

( χ_{k+1|k,i}-x_{k+1|k }) = predicted sigma points in state space.

Z_{k+1|k,i}-z_{k+1|k }) = predicted sigma points in measurement space.

**Important Applications**

**Important Applications**

Object tracking problems in computer vision like Lucas-Kannade tracker, visual odometry, and lane detection for autonomous vehicles.

Sensor fusion: experiments and robots involving use of multiple sensors (like LIDAR, RADAR, IMU's etc.) use Kalman filtering to produce better estimates.

Satellite Navigation.

Weather forecasting.

Solving continuous state space or discrete state space MDPs.

**Open Research Questions**

**Open Research Questions**

Some open problems are: optimization of delay tolerance, adaptive Kalman filters, devising solutions for different type of MDPs, and more. To improve the performance for highly non-linear and more realistic models - some other methods like particle filter and Monte Carlo methods are used.