I have recently been to a conference where there was a common tool for everyone, the Kalman filter. The point is that I was a bit shocked when I saw that many people there see some of its steps as black magic.

I decided to write a (yet another) detailed guide about the Kalman filter. In particular, I have tried to be rigorous enough with the math but trying at the same time to explain with plain words what is going on at every single step. Therefore, after reading it, it should be easy (hopefully) to others to understand and implement a Kalman filter in its simplest version, the Discrete Linear one.

An example about how to calibrate the accelerometers or gyroscopes of an IMU is considered as an illustration throughout the guide. In fact, I have written a small Python script and generated some animations in order to be more illustrative. The aim of the example, together with the guide, is to understand why in the following figure, the states of position, velocity and accelerometer's bias converge around the true values.

You can find the guide in the following link from my blog http://dobratech.com/courses/kalman-filtering-for-drones/

## Comments

@Hector,

Thanks. That math is pretty simple and I still remember stuff from Statistical Signal Analys courses.

In this specific example, how do you know that accelerometer readings are uncorrelated with drone velocity?

I see your explanation: "i.e. we do not care about the position or the velocity of the drone for applying a certain acceleration.", but I am still not sure :) Maybe I get confused because I think velocity and acceleration are usually not independent. I feel a bit embarrased. It seems like it should be straightforward...

Can you give me an example of a state variable that would be correlated with accelerometer? i.e. from another model. What if we had other sensor signals as state variables?

If you don't have time to answer, I can just wait for future articles.

Thanks!

@earthpatrol

thanks!

@Mikhail

thanks a lot for your feedback. I was not also very happy with that part, so I will upgrade it soon.

About "the third step", since you are from the electrical guys, you will find the following illustrative (I hope).

Keep this fact in mind: (a+b)² = a² + b² + 2ab (1).

Now consider the interference of two sinusoids and compute the resultant amplitude. It is not the addition or subtraction of the independent amplitudes but it is related with (1), we are squaring an addition, and the resultant amplitude depends on the off-set between the two signals.

Physically the interference means that you are

fusingtwo informations in a point in the space (in fact in quantum physics, a sinusoidal brings information about the position and momentum of a particle :P). In the Kalman filter, instead of sinusoidals, you have Gaussians, and instead of fusing them in a spacial point, you are fusing them in a time event. Mathematically is the same, but physically is different.You can think about the correlation as the "off-set" of the two sinusoidal functions in an interference. If the are not correlated, then the analogy is that the third term in (1) "would be zero", as it happens with the constructive interference.

We know how to measure off-set in sinusoidal signals, but, how to measure if two variables are correlated? well, we have statistical tools that based on a collection of measurements of the two variables, we can say if they are correlated or not. Or even your expertise when you are setting up the model can determine that, for example, the probability of me being hungry does not depends on the probability of the temperature in Antarctica in 5 min. The same happen with the IMU case, the probability of having a 5 as a reading in the accelerometer (in my model) does not depend on the position or velocity of my IMU.

Cheers!

@Hector

Thank you for the Kalman guide!

Just some comments on reading/understanding Kalman filter articles in general from my point of view. I am an engineer (firmware and electrical), but never had to use estimation for work. I remeber basics from probability theory since it is used in EE signal processing, etc, but I have not used Linear Algebra since college. It is hard to "visualize" results of matrix operations without writing them out. I can follow your explanation/derivation (or other guides), but still have a problem doing similar thing for a different system with different state vectors, etc.

Not sure how it is for other engineers, but for me the hardest part is linear algebra and understanding where simplifications can be used. For example, like this one "where the third step has been possible since the accelerometer (the input) is uncorrelated with the rest of the states".

And I am not even talking yet about choosing values for Q matrix in a real system. That is blac magic :)

Waiting for more chapters from you. Thanks!

Nice work @Hector. Enjoying your work and posts. Thanks.

Wow, Darius Jack really forgot to take his meds again..

haha David, and you have not seen the other posts from him that I had to delete (first time ever I remove posts from smb)

After reading it again I am very sure of it.

David

Ya. I think Global Innovator is Darius Jack. He's back on the fuzzy logic

David

@Andy

Sure, feel free to post at the course whatever question or doubt in order to improve the guide.

@OlliW

Yep, CF and KF can be compared in the sense that both are fusing different sources about the same information. Right now I am not sure whether CF and KF are equivalent for some special cases...

maybe this argument makes the "filter" in the KF a bit more transparent: When the various matrices are constant with time, then the KF reduces to a complementary filter. For instance with an accelerometer and gyro, the output becomes the weighted combination of the low-pass-filtered accelerometer data and the high-pass-filtered gyro data. So, some filtering is indeed going on.

:)

Next