An attempt at demystifying the application of the Kalman filter, in order to stop making it look more complex than it is.
- The goal
- Not the goal
- How you can help
- Demystifying the Kalman filter
- Le Kalman filter
- Context
- Steps
- Terms definitions
- x : State vector
- P : Covariance matrix of the state vector x
- K : Kalman gain
- z : Measurement vector
- F : State transition model
- Q : Covariance matrix of the process noise
- H : Measurement matrix
- v : Measurement noise
- R : Covariance matrix of the sensor noise
- u : Control vector
- B : Control matrix
- w : External noise, sources of uncertainity
- Initialisation of the Kalman filter
- Diagram summary and meta-example
- How to cite
- Sources and recommended reads
- Legal disclaimer
The goal is to provide a thorough practical introduction to the application of the Kalman filter to the reader, so as he understand the filter algorithm and can to an extend apply it readily to his use case. The goal is also to provide a clear approach to the Kalman filter as to create a strong fondation on which the dedicated reader will be able to rely in order to dig deeper into more technical ressources on the subject of the Kalman filter.
In the grand scheme of thing, the goal is to help bring useful knowledge to the most people possible.
Even if we aim to provide an introduction as simple as possible, it will still require investment from the reader, and work on
This work does not have as a goal to provide the deep understanding of the Kalman filter, nor about the underlying principles, mainly probability, distribution, Bayesian statistics and so forth. At least, at present, see below.
We invite any reader to open an issue if there is anything unclear, mistakes (be it a typo, a wront equation, whatever), or if a topic related to the Kalman filter needs an explanation. Organically, we are not against trying to dumb down the underlying foundations of the Kalman filter and associated mathematical concepts if there is a demand for it (even just one person).
Now let's get to business.
In this work we will refer to the discrete version of the Klaman filter algorithm. As it is hard to explain all the Kalman filter parts in isolation, we strongly invite the reader to go through all the material presented here before coming back again to the part that could be unclear during their first read. For the reader that prefer to have a global view before digging in, we would recommend to read the Diagram summary and meta-example part before starting the material as it is written.
This work try to dumb the Klamn filter down to the maximun. It won't go into details, but aims to provide a good understanding of the different parts of the algorithm, and wherever possible, underlying principles. The goal is to allow the maximum of people to try to grasp the concept, even people with limited mathematical background. It will be made as so the reader have very limited need to look at other material while going through this one. In order to do so, steps and terms will explained in a manner that can seems repeating and a bit cumbersome.
The time will be refered to, through the notation
The following math notation is used in the present work:
| Symbol | Signification |
|---|---|
| Matrix multiplication | |
| Transpose of the matrix |
|
| Inverse of the matrix |
|
| Matrix at time |
|
| Standard deviation of the element |
|
| Variance of the element |
|
| Covariances of the elements |
|
| Distributed as | |
| Normal distribution |
The Kalman algorithm is an estimator, and not a filter per se. It will estimate the most likely state in which a system is, from measurements and model results, pondered by uncertainities. Thus, as it will aim to discard "errors" in the inputs, it should converge toward the true state of the system. That's why when looked at it from the point of view of signal processing, as it should discard noise and other artifacts presents in the recording and estimation errors from the models used, it looks like it is filtering the input fed to it.
To be consistent with our title, we will limit the use of "synonyms" and to be consistent with why most layman people look into the Kalman algorithm, we will keep calling it the Kalman filter, and not the Kalman estimator. We will aim for a consistent and strict mathematical notation, especially for vector and matrix, something that seem to be somewhat overlook into the physics textbooks.
The Kalman filter can be summarized into two steps: prediction and correction.
Some of the following variables are not measured or calculated from measurements and/or associated logic. Therefore, they have to be establish by the operator: you. This is where the difficulties in using and establishing a good, accurate and valuable Kalman filter lie. It requires theorethical knowledge about the system of interest, but also theoretical knowledge theoretical domains related to the field of the system of interest, as well as pratical, field knowledge of the system of interest, most of the time gained through field study.
The modelling choice will be dependent, to an extend, on the operator choice with the consequences they imply. Be sure to put the adequat level of care and research for your application.
The following domains can be of interest in the task of developping adequat values for the following variables:
- Point estimation theory
- Linear Modelling
- Non-linear modelling
- Time variant modelling
It is of the form:
With
-
$\vec{x}(t)$ : State vector at time$t$ , essentially the input of the Kalman filter iteration -
$\vec{x_p}$ : State vector as predicted using model$\mathbf{F}$ and the control vector$\vec{u}$ -
$\vec{x_c}$ : State vector predicted and corrected by the Kalman filter, the state vector$\vec{x}(t+1)$ . It is the output of the Kalman filter iteration and will be used as the state vector input$\vec{x}$ of the next Kalamn filter iteration
The state vector represent the assumption we are making about the state of the model. This is not the raw measurements. The state, and therefore the state vector, depends on the pre-established model
The state is an estimation of the system state. It is built through the estimation from the state from previous
It is simply the covariance matrix linked to the state vector
It is computed as such:
With
-
$\mathbf{P}(t)$ : the covariance matrix associated to the state vector$\vec{x}(t)$ -
$\mathbf{P_p}$ : the covariance matrix associated to the state vector$\vec{x_p}$ -
$\mathbf{P_c}$ : the covariance matrix associated to the state vector$\vec{x_c}$
The covariance matrix
For more imformation on covariance and covariance matrix:
It is computed through the equation:
It dictate the balance of how much measurement, from the measurement vector
A nice approach to understand that balance relationship between measurement (
So going from the equation given above we can write the Kalman gain as:
Which give us two important limits:
Basically meaning, if the state vector
At the same time, if the state vector is know accurately
It is the vector composed of the measurements from the sensor(s). It is o the form:
With
It is linked to the measurement noise
The measurement vector has the following relation to the state vector:
With
The measurement matrix
State that F is the transition to point in time t to t+1
The state transition model
This would be the case for example when you try to assess the attitude (the state of the system) of a moving system, that is: pitch, roll and yaw. Where you can use the gyroscope measurements, angular speeds, acquired for a specific
As any other applications specific terms, you will have to provide it yourself, through theoretical and/or empirical knowledge.
This is the covariance matrix associated to the state transition model
More broadly, it is considered link to the uncertainity in the update step. And therefore is link to the control (
One way to solve the problem in a brute force manner might be to establish this parameter through some sort of gradient descent.
To avoid accounting for any uncertainty in the state transition model
The measurement matrix
It is made of real values, and represent the relation between, the impact of, the measurements and the state vector. A value of
The relation it holds between the state vector
With
As the measurement noise
The measurement noise usually assumed to be a zero-mean Gaussian random variable. But will depend on the sensors you are using, as well as the variables measured and the system of interest in which they are evolving in. The measurement noise
The measurement noise
With
And is represented by a normal distribution:
The equation above is only valid if your measurement noise is distributed normally (in the mathematical sense) and mean
Or more generally by the normal distribution:
With
In the equation of the Kalman filter, the measurement noise would be of the form:
With
If you have to estimate the measurement noise and its characteristics, you will usually need to refer to the sensor documentation, which should provide you with information regarding the noise range of the sensor. Empirical experimentation might be needed to estimate the sensor noise characteristics in your application.
The covariance matrix
Which, if the measurements are uncorrelated between each others, is of the form:
The case could be made that the covariance matrix of the sensor noise
This represent the control applied to the system of interest, susceptible to change the state vector
For example, suppose our system is a free falling rocket. The state vector
The control matrix
It works a bit in the same way as the measurement matrix
It is sometimes called
for example, let say we are interested in the velocity and the position of a system. It will be expressed by the following state vector:
We know that the discrete velocity and position are computed using the following equation:
The predicted transition from
With
-
$\mathbf{F}$ , the state transition model is the the expression of the physic formula described above, and therefore add the distance travelled during$\Delta t$ at the velocity$vel(t)$ from the state vector$\vec{x}(t)$ , and keep the velocity the same. It is equat to
-
For sake of simplicity, we will assume the oexternak sources of uncertainity
$\vec{\omega}$ to be null -
For the sake of the argument, the control vector
$\vec{u}$ will be of the form of a scalar (a non composite value, a singular value):$\vec{u}(t) = a(t)$ ,$a(t)$ an arbitrary value of acceleration. The exact value doesn't matter in this case.
In this case the control matrix would be, according to the physic formula stated above:
Again, as with any application specific variables, you will have to design your control matrix
It represent the sources of uncertainity that may influence the dynamic of the state vector from one
This parameter is sometimes included, or even entierely represented by the control vector
The initialisation of the Kalman filter is going to be an important step but also very application specific.
The variables consituing the Kalman filter will have to be found, or one could say intitialised, via theoretical and empirical means, the state vector
Indeed, for example, let's say you have a robot needing to travel through a maze, just like a micro mouse robot. You choose to use a Kalman filter to estimate the position and velocity of the robot: your state vector
The initial value of the state vector
Learn your system, study it. And just try. Build a safe and adequat experimental setup to be able to try out hypothesis about your system, your application and their practical application. Fail there rather than when guiding that multi millions rocket. Taxpayer around your country will thank you.
Below is a little diagram followed by the variables associated to each components.
-
State vector:
$\vec{x}(t)$ ,$\mathbf{P}(t)$ -
Control:
$\vec{u}(t)$ ,$\mathbf{B}$ -
State transition model:
$\mathbf{F}(t)$ ,$\mathbf{Q}$ -
External source of of uncertainty:
$\vec{\omega}$
-
State vector predicted:
$\vec{x_p}$ ,$\mathbf{P_p}$ -
Measurements:
$\vec{z}$ ,$\mathbf{R}$ ,$\mathbf{H}$ ,$\vec{v}$ -
Kalman gain:
$\mathbf{K}$
The following is a metaphorical example which, hoepfully, should help the reader grasp the meaning of each parts of the Kalman filter.
Let say that your brain is the hardware, and the software the Kalman filter. Your goal is to estimate the state of the world. For that you have at your disposal:
- The official informations about the world
- Your model of the functionning world
- The actions you do to change the world
- Your observations about the world
Which gave you the following system:
To estimate the state of the world ($\vec{x}(t)$) in 10 years (
You listen to the TV, read some articles and build your model about how the world seems to be transforming (
In addition, because you are one of the wealthiest man on Earth, you account for the actions you are taking to change the world (
But sadly, you can't be 100% sure of the success of your endeavours or their consequences, and as we said earlier, you are rich but not omniscient: there is a lot you don't know, misunderstood or even been lied about (
Once your prediction made about the futur is done, you go enquire about a how the world is doing (
Once you got your predictions and you measurements made, you balance each others regarding the quality of the sources of information that allowed you to make those up, and give more importance to the trustier one (
You end up with the best estimate you can come up to, of what will be the world in 10 years: that was one iteration of your mental Kalman estimator, also called Kalman filter.
Robinault Lucien (2023). Demystifying the Kalman filter. V1.0.0 (https://github.com/TSS-22/demystifying-kalman-filter), GitHub. DOI: 10.5281/zenodo.10396368
The rumors say that Anna got them in her archive.
-
BARRETO, Armando, ADJOUADI, Malek, ORTEGA, Francisco, et al. Intuitive Understanding of Kalman Filtering with MATLAB®. ISBN-13: 978-0367191337. CRC Press, 2020.
A good book to grasp the foundation of the Kalman filter, as well as the filter in its basic mathematic form. The associated code examples are very valuable as they present the algorithm in a working manner (code is exempt of error). The drawback are that the book is relatively confuse and sometimes confusing, as denomination can seem inconsistent and information is scattered and disorganized. -
HASLWANTER, Thomas. 3D Kinematics. ISBN-13: 978-3319752761. Cham, Switzerland : Springer, 2018.
Good ressource for 3D kinematics, as the name implies, but can be frustrating as it overlook some "trivial" steps sometimes. Very useful if your application of the Kalman filter will reside in the use of Inertial Motor Unit in the case of sensor fusion, or anything 3D related. It is short (good thing) and does its job. Sadly this is one of the most exhaustive source of information about the topic of 3D kinematics and it will ask for a lot of investment and personal research to dig valuable, valid, serious and proper information on the topic. -
STROUD, Kenneth Arthur et BOOTH, Dexter J. Engineering mathematics. ISBN-13: 978-1352010275. Bloomsbury Publishing, 2020.
Extremely valuable ressource to learn the basic mathematics to enter confidently the realm of science and engineering level mathematics. This book could teach mathematics to a monkey. -
STROUD, Kenneth Arthur et BOOTH, Dexter J. Advanced engineering mathematics. ISBN-13: 978-1352010251. Bloomsbury Publishing, 2020.
For the nerdy monkey. -
How to understand Kalman gain intuitively?. Answers: Jav_Rock, Zichao Zhang, ssk08. June 2012.
A nice view at the Kalman gain behavior to understand its mathematical purpose.
The information and tools contained in this repository are provided in good faith and no warranty, representation, statement or undertaking is given regarding any information or tool connected with this repository and any warranty, representation, statement or undertaking whatsoever that may be expressed or implied by statute, custom or otherwise is hereby expressly excluded. The use of the tools in this repository and any information in this repository is entirely at the risk of the user. Under no other circumstances the author should be liable for any costs, losses, expenses or damages (whether direct or indirect, consequential, special, economic or financial including any loss of profits) whatsoever that may be incurred through the use of any information or tools contained in this repository. This repository may contain inaccurate information. Which the author is under no responsibility to update or correct any such information or to even maintain this repository. Which the author reserves its right to change any information or any part of this repository without notice.

