Home

Awesome

An Intuitive Tutorial on Bayesian Filtering

Introduction

This short tutorial aims to make readers understand Bayesian filtering intuitively. Instead of derivation of Kalman filter, I introduce Kalman filter from weighted average and moving average. I expect that readers will have intuition on Kalman filter such as meaning of equations.

This tutorial contains example applications to 2-D localization (a.k.a. target tracking) with various conditions and situations. It is important for users to know how to define the following five items in their applications. I hope that readers can build their intuition from my series of examples. My codes are based on FilterPy, but their contents and your understanding may not be limited to the library.

  1. State variable
  2. State transition function
  3. State transition noise
  4. Observation function
  5. Observation noise

Code Examples

1) From Weighted and Moving Average to Simple 1-D Kalman Filter

2) Kalman Filter

3) Extended Kalman Filter (EKF)

\mathbf{x}_{k+1} = f(\mathbf{x}_k; \mathbf{u}_{k+1}) = \begin{bmatrix} x_k + v_k t \cos(\theta_k + w_k t / 2) \\ y_k + v_k t \sin(\theta_k + w_k t / 2) \\ \theta_k + w_k t \\ v_k \\ w_k \end{bmatrix}
\mathrm{Q} = \mathrm{W}^\top \mathrm{M} \mathrm{W} \quad \text{where} \quad \mathrm{W} = \begin{bmatrix} \frac{\partial f}{\partial v} & \frac{\partial f}{\partial w} \end{bmatrix} \quad \text{and} \quad \mathrm{M} = \begin{bmatrix} \sigma^2_v & 0 \\ 0 & \sigma^2_w \end{bmatrix}
\mathbf{x}_{k+1} = f(\mathbf{x}_k; \mathbf{u}_{k+1}) = \begin{bmatrix} x_k + v_k t \cos(\theta_k + w_k t / 2) \\ y_k + v_k t \sin(\theta_k + w_k t / 2) \\ \theta_k + w_k t \\ v_k \\ w_{max} \tanh{(w_k / w_{max})} \end{bmatrix}
\mathbf{x}_k = \left\{ \begin{array}{ll}
    [x_k, y_k, \theta_k+\pi, -v_k, w_k]^\top & \text{if} \;\; v_k < \epsilon_- \\
    \mathbf{x}_k & \text{otherwise}
\end{array} \right.
\mathbf{x}_{k+1} = f(\mathbf{x}_k; \mathbf{u}_{k+1}) = \begin{bmatrix} x_k + v_{k+1} t \cos(\theta_k + w_{k+1} t / 2) \\ y_k + v_{k+1} t \sin(\theta_k + w_{k+1} t / 2) \\ \theta_k + w_{k+1} t \end{bmatrix}
\mathbf{z} = \begin{bmatrix} x_{GPS} \\ y_{GPS} \end{bmatrix} = h(\mathbf{x}) = \begin{bmatrix} x + o_x \cos \theta - o_y \sin \theta \\ y + o_x \sin \theta + o_y \cos \theta \end{bmatrix}

4) Unscented Kalman Filter (UKF)

5) Particle Filter

References

How to Cite

If you want to cite this tutorial and codes, please cite one of the following papers.

@article{Cho24,
    author      = {Se-Hyoung Cho and Sunglok Choi},
    title       = {Accurate and Resilient {GPS}-only Localization with Velocity Constraints},
    journal     = {IEEE Access},
    volume      = {12},
    year        = {2024},
    doi         = {10.1109/ACCESS.2024.3432335}
}
@article{Choi20,
    author      = {Sunglok Choi and Jong-Hwan Kim},
    title       = {Leveraging Localization Accuracy with Off-centered {GPS}},
    journal     = {IEEE Transactions on Intelligent Transportation Systems},
    volume      = {21},
    number      = {6},
    year        = {2020},
    doi         = {10.1109/TITS.2019.2915108}
}

Authors

Acknowledgement

This tutorial was supported by the following R&D projects in Korea.