# How to understand Kalman gain intuitively?

The Kalman filter algorithm works as follows

Initialize $\hat{\textbf{x}}_{0|0}$ and $\textbf{P}_{0|0}$.

At each iteration $k=1,\dots,n$

Predict

Predicted (a priori) state estimate $$\hat{\textbf{x}}_{k|k-1} = \textbf{F}_{k}\hat{\textbf{x}}_{k-1|k-1} + \textbf{B}_{k} \textbf{u}_{k}$$ Predicted (a priori) estimate covariance $$\textbf{P}_{k|k-1} = \textbf{F}_{k} \textbf{P}_{k-1|k-1} \textbf{F}_{k}^{\text{T}} + \textbf{Q}_{k}$$ Update

Innovation or measurement residual $$\tilde{\textbf{y}}_k = \textbf{z}_k - \textbf{H}_k\hat{\textbf{x}}_{k|k-1}$$ Innovation (or residual) covariance $$\textbf{S}_k = \textbf{H}_k \textbf{P}_{k|k-1} \textbf{H}_k^\text{T} + \textbf{R}_k$$ Optimal Kalman gain $$\textbf{K}_k = \textbf{P}_{k|k-1}\textbf{H}_k^\text{T}\textbf{S}_k^{-1}$$ Updated (a posteriori) state estimate $$\hat{\textbf{x}}_{k|k} = \hat{\textbf{x}}_{k|k-1} + \textbf{K}_k\tilde{\textbf{y}}_k$$ Updated (a posteriori) estimate covariance $$\textbf{P}_{k|k} = (I - \textbf{K}_k \textbf{H}_k) \textbf{P}_{k|k-1}$$

The Kalman gain $K_k$ represents the relative importance of the error $\tilde{\textbf{y}}_k$ with respect to the prior estimate $\hat{\textbf{x}}_{k|k-1}$.

I wonder how to understand the formula for the Kalman gain $K_k$ intuitively? Consider the case when the states and outputs being scalar, why is the gain bigger, when

• $\textbf{P}_{k|k-1}$ is bigger

• $\textbf{H}_k$ is bigger

• $\textbf{S}_k$ is smaller?

Thanks and regards!

• This a hard question to answer properly. I tried, but not convinced with my own answer. Basically the gain controls how much you trust the measurements over the estimation, but I can't explain how this gain is conformed. – Jav_Rock Jun 5 '12 at 15:06

I found a good way of thinking intuitively of Kalman Gain $K$. If you write $K$ this way

$\displaystyle \quad\ \bf{K_k} = \bf{P_k^-\, H_k^{\rm T} (H_k P_k^-\, H_k^{\rm T} + R_k)^{-1}} = \bf{\frac {P_k^-\, H_k^{\rm T}}{H_k P_k^-\, H_k^{\rm T} + R_k}}$

you will realize that the relative magnitudes of matrices ($R_k$) and ($P_k$) control a relation between the filter's use of predicted state estimate ($x_{k}⁻$) and measurement ($ỹ_k$).

$\displaystyle \quad\ \lim\limits_{\bf{R_k \to 0}} \bf{{P_k^-\, H_k^{\rm T}} \over\ {H_k P_k^-\, H_k^{\rm T} + R_k}}\ = \bf{H_k^{-1}}$

$\displaystyle \quad\ \lim\limits_{\bf{P_k \to 0}} \bf{{P_k^-\, H_k^{\rm T}} \over\ {H_k P_k^-\, H_k^{\rm T} + R_k}}\ = \bf 0$

Substituting the first limit into the measurement update equation

$\displaystyle \quad\ \bf{\hat x_k} = \bf{x_k^-} + \bf{K_k}(\bf{\tilde y_k}-\bf{H_k}\bf{x_k^-})$

suggests that when the magnitude of $R$ is small, meaning that the measurements are accurate, the state estimate depends mostly on the measurements.

When the state is known accurately, then $H P^⁻ H^T$ is small compared to $R$, and the filter mostly ignores the measurements relying instead on the prediction derived from the previous state ($x_k⁻$).

• Thanks! If I am correct, $K_k$ is not monotonic with respect to $H_k$. – Tim Jun 6 '12 at 11:00

The Kalman gain tells you how much I want to change my estimate by given a measurement.

${\bf S}_k$ is the estimated covariance matrix of the measurements ${\bf z}_k$. This tells us the "variability" in our measurements. If it's large, it means that the measurements "change" a lot. So your confidence in these measurements is low. On the other hand, if ${\bf S}_k$ is small, variability is low, our confidence in the measurement increases. When we are confident about our measurements, were confident that the information we're obtaining is good enough for us to update/change our state estimates. So the Kalman gain is higher.

${\bf P}_k$ is the estimated state covariance matrix. This tells us the "variability" of the state, ${\bf x}_k$. If ${\bf P}_k$ is large, it means that the state is estimated to change a lot. So you need to be able to change your estimates with new measurements. As a result, the Kalman gain is higher.

Conversely, if ${\bf P}_k$ is small, then you know that your state doensn't change that much, so you don't want to alter your estimates too much at every time instant. @Jav_Rock's answer says that if ${\bf P}_k \rightarrow 0$, then the $K\rightarrow 0$. In other words, he implied that if you think that your state doesn't vary anymore, you don't try to change your estimate anymore.

Jav_Rock got the point. Actually if you write $\bf{K_k}$ like this

$\displaystyle \quad\ \bf{K_k} = \bf{P_k^-\, H_k^{\rm T} (H_k P_k^-\, H_k^{\rm T} + R_k)^{-1}} = \bf{H_k^-\frac {H_kP_k^-\, H_k^{\rm T}}{H_k P_k^-\, H_k^{\rm T} + R_k}}$

the numerator of the fraction stands for the uncertainty propagated from the model while $\bf{R_k}$ stands for the uncertainty from the measurement. So the value of the fraction stands for how much we should trust the measurement, as explained by Jav_Rock.

As for the $\bf{H_k^-}$, it just transform the observation back to the state, because it is the state that we want to update, not the observation.

To wrap up, the gain $\bf{K_k}$ computes how much correction we should take from observation and transform the correction of observation back to the correction of state, which leads to the update of state estimate:

$\displaystyle \quad\ \bf{\hat x_k} = \bf{x_k^-} + \bf{K_k}(\bf{\tilde y_k}-\bf{H_k}\bf{x_k^-})$

I am working on the Kalman Filter (KF) algorithm. I observed that the kalman gain deals with convergence of algorithm with time, that is, how fast the algorithm corrects and minimizes the residual.

Coming to the equation choose an initial kalman gain value and vary it from low to high, that can give you an approximated one.