CSE276A - Kalman Filter

Basis

What is Kalman Filter

An 1 dimensional example: We have two measurements x1x_1 and x2x_2 measuring a value. Each measurement has an uncertainty (standard deviation), σ1\sigma_1 and σ2\sigma_2. How to find the optimal estimate, x^\hat{x}, that best combines x1x_1 and x2x_2.

The idea is to use a weighted least squares, We want to find an x^\hat{x} that minimizes the “cost” function S=i=1nwi(x^xi)2S = \sum_{i=1}^{n}w_i(\hat{x} - x_i)^2. We want to give more weight to the measurement we trust more (the one with lower uncertainty), so we set wi=1σi2w_i = \frac{1}{\sigma_i^2}. We solve x^\hat{x}:

x^=wixiwi\hat{x} = \frac{\sum w_i x_i}{\sum w_i}

x^=(σ22σ12+σ22)x1+(σ12σ12+σ22)x2\hat{x} = \left( \frac{\sigma_2^2}{\sigma_1^2 + \sigma_2^2} \right) x_1 + \left( \frac{\sigma_1^2}{\sigma_1^2 + \sigma_2^2} \right) x_2

The new uncertainty of x^\hat{x}: Since Var(aX+bY)=a2Var(X)+b2Var(Y)\text{Var}(a \cdot X + b \cdot Y) = a^2 \cdot \text{Var}(X) + b^2 \cdot \text{Var}(Y), we get:

σx^2=(σ22σ12+σ22)2σ12+(σ12σ12+σ22)2σ22\sigma_{\hat{x}}^2 = \left( \frac{\sigma_2^2}{\sigma_1^2 + \sigma_2^2} \right)^2 \sigma_1^2 + \left( \frac{\sigma_1^2}{\sigma_1^2 + \sigma_2^2} \right)^2 \sigma_2^2

σx^2=σ12σ22σ12+σ22\sigma_{\hat{x}}^2 = \frac{\sigma_1^2 \sigma_2^2}{\sigma_1^2 + \sigma_2^2}

Rewrite the above formula as an update step:

x^=x1+σ12σ12+σ22(x2x1)\hat{x} = x_1 + \frac{\sigma_1^2}{\sigma_1^2 + \sigma_2^2} (x_2 - x_1)

Discrete Kalman Filter

In robotics case, the x1x_1 is the prediction of the robot’s state given previous state, and x2x_2 is the actual measurement of robot’s state from sensor.

The Process Model

st=Fst1+Gut+wts_t = Fs_{t-1} + Gu_t + w_t

  • sts_t: The true state of the system at time tt.
  • FF: It defines how the state would change if there were no control inputs. For example, s=[pv]s = \begin{bmatrix} p \\ v \end{bmatrix} (where pp is position, vv is velocity), then pt=pt1+vt1Δtp_t = p_{t-1} + v_{t-1} \cdot \Delta t and vt=vt1v_t = v_{t-1}, then

[ptvt]=[1Δt01][pt1vt1]\begin{bmatrix} p_t \\ v_t \end{bmatrix} = \begin{bmatrix} 1 & \Delta t \\ 0 & 1 \end{bmatrix} \begin{bmatrix} p_{t-1} \\ v_{t-1} \end{bmatrix}

  • GutGu_t: utu_t is control input. GG maps that command to a change in the state. For example, ut=[a]u_t = [a] which is acceleration, then Δv=aΔt\Delta v = a \cdot \Delta t, Δp=12a(Δt)2\Delta p = \frac{1}{2} a (\Delta t)^2. As a result,

Gut=[ΔpΔv]=[12(Δt)2Δt][a]Gu_t = \begin{bmatrix} \Delta p \\ \Delta v \end{bmatrix} = \begin{bmatrix} \frac{1}{2} (\Delta t)^2 \\ \Delta t \end{bmatrix} \begin{bmatrix} a \end{bmatrix}

  • wtw_t: Process noise, for example, a bump in the road or wheel slippage. p(w)N(0,Q)p(w) \sim N(0, Q), QQ represents “How much do I distrust my system model?”.

zt=Hst+vtz_t = Hs_t + v_t

  • ztz_t: The observation that sensor gives.
  • HH: For example, your state sts_t might be a 6D vector (position x, y, z; velocity vx, vy, vz), but measurement ztz_t is only a 3D vector (position x, y, z). The HH matrix would be a 3x6 matrix that just “selects” the first three components of the state.
  • vtv_t: Measurement Noise by the sensor itself. p(v)N(0,R)p(v) \sim N(0, R). RR represents “How much do I distrust my sensor?”.

Kalman Prediction

stt1=Fst1t1+Guts_{t|t-1} = Fs_{t-1|t-1} + Gu_t

  • st1t1s_{t-1|t-1}: The corrected state after the last update.
  • stt1s_{t|t-1}: The new predicted state for the current time tt, based only on information from t1t-1.

Σtt1=FΣt1t1FT+Qt\Sigma_{t|t-1} = F\Sigma_{t-1|t-1}F^T + Q_t

  • Σt1t1\Sigma_{t-1|t-1}: Uncertainty covariance matrix of last best estimate st1t1s_{t-1|t-1}.
  • Σtt1\Sigma_{t|t-1}: New, larger predicted uncertainty for the current time tt.

Kalman Updating

State Update:

stt=stt1+Kt(ztHstt1)s_{t|t} = s_{t|t-1} + K_t(z_t - H s_{t|t-1})

  • The above formula is equivalent to x^=x1+K(x2x1)\hat{x} = x_1 + K(x_2 - x_1).
  • stts_{t|t}: The corrected state for time tt.
  • (ztHstt1)(z_t - H s_{t|t-1}): ztz_t is new measurement, Hstt1H s_{t|t-1} is expected measurement. The difference is called “surprise”.

Kt=Σtt1HTSt1K_t = \Sigma_{t|t-1} H^T S_t^{-1}

St=HΣtt1HT+RtS_t = H \Sigma_{t|t-1} H^T + R_t

  • StS_t: Equivalent to σ12+σ22\sigma_1^2 + \sigma_2^2 in the 1D example. Σtt1\Sigma_{t|t-1} is predicted uncertainty (like σ12\sigma_1^2), and HΣtt1HTH \Sigma_{t|t-1} H^T is the predicted uncertainty projected into the measurement space. RtR_t is measurement sensor’s uncertainty (like σ22\sigma_2^2).
  • KtK_t: This is the matrix version of K=σ12σ12+σ22K = \frac{\sigma_1^2}{\sigma_1^2 + \sigma_2^2}.

Covariance Update:

Σtt=(IKtH)Σtt1\Sigma_{t|t} = (I - K_t H) \Sigma_{t|t-1}

  • Σtt\Sigma_{t|t}: Corrected, smaller uncertainty (like σx^2\sigma_{\hat{x}}^2).

Extended Kalman Filter

The previous formula all assumed a linear world. However, in many cases, the state change is non-linear. For example, a robot’s state [x,y,θ][x, y, \theta]:

  • xt=xt1+vtcos(θt1)Δtx_t = x_{t-1} + v_t \cdot \cos(\theta_{t-1}) \cdot \Delta t
  • yt=yt1+vtsin(θt1)Δty_t = y_{t-1} + v_t \cdot \sin(\theta_{t-1}) \cdot \Delta t
  • θt=θt1+ωtΔt\theta_t = \theta_{t-1} + \omega_t \cdot \Delta t

As a result, there is no way to write the relationship with st=Fst1+Guts_t = F s_{t-1} + G u_t. In this section, we will use a non-linear expression:

st=f(st1,ut1)+wt1s_t = f(s_{t-1}, u_{t-1}) + w_{t-1}

zt=h(st)+vkz_t = h(s_t) + v_k

If the system is non-linear, we can’t use the Kalman filter. So, at every single time step, we will approximate the non-linear function with a linear one. The best linear approximation of a function at a specific point is its tangent line (or tangent plane in multi-dimensions) found by first-order Taylor series expansion.

stf(st1t1,ut1,0)+F(st1st1t1)+wt1s_t \approx f(s_{t-1|t-1}, u_{t-1}, 0) + F(s_{t-1} - s_{t-1|t-1}) + w_{t-1}

zth(stt,0)+H(ststt)+vkz_t \approx h(s_{t|t}, 0) + H(s_t - s_{t|t}) + v_k

where Fij=fisj(st1t1,ut1,0)F_{ij} = \frac{\partial f_i}{\partial s_j}(s_{t-1|t-1}, u_{t-1}, 0) and Hij=hisj(stt,0)H_{ij} = \frac{\partial h_i}{\partial s_j}(s_{t|t}, 0).

EKF Prediction

stt1=f(st1t1,ut1,0)s_{t|t-1} = f(s_{t-1|t-1}, u_{t-1}, 0)

Σtt1=FtΣt1t1FtT+Qt1\Sigma_{t|t-1} = F_t \Sigma_{t-1|t-1} F_t^T + Q_{t-1}

EKF Updating

Kt=Σtt1HtT(HtΣtt1HtT+Rt)1K_t = \Sigma_{t|t-1} H_t^T (H_t \Sigma_{t|t-1} H_t^T + R_t)^{-1}

stt=stt1+Kt(zth(stt1,0))s_{t|t} = s_{t|t-1} + K_t (z_t - h(s_{t|t-1}, 0))

Σtt=(IKtHt)Σtt1\Sigma_{t|t} = (I - K_t H_t) \Sigma_{t|t-1}


CSE276A - Kalman Filter
http://example.com/2025/11/08/CSE276A/CSE276A-kalman-filter/
Author
Songlin Zhao
Posted on
November 8, 2025
Licensed under