The Extended Kalman Filter: An Interactive Tutorial

3689628578?profile=originalIn working with autopilot systems like OpenPilot and Pixhawk I have frequently come across references to something called an Extended Kalman Filter (EKF). Googling this term led me to several different web pages and reference papers, most of which I found too difficult to follow. So I decided to create my own tutorial for teaching and learning about the EKF from first principles. This tutorial assumes only high-school-level math and introduces concepts from more advanced areas like linear algebra as needed, rather than assuming you already know them.

The tutorial is currently about 2/3 complete.  I still need to introduce linear algebra concepts for sensor fusion, and then nonlinearity for the EKF.  But in the open-source spirit of "release early, release often", I'm posting this now, in the hope that people will try it out and provide comments.  

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • Thank you for your great effort.... many thanks indeed

  • I disagree with Nikola - the proper notation is far easier to understand than arcane variable names written in a stream of pseudocode.  Matlab is perfectly valid and well suited for demonstration code. 


    If you want to see a C-coded Klaman Filter, then look at the APM code!!

  • Cool.  If I may offer a few recommendations, please try to avoid using Greek letters, accented terms (i.e. prime or hat), subscripted notation, and other mathematical notation that can't easily be translated into code.  In fact, I'd ask that the tutorial be written as C code (IMHO, Matlab is cheating).  I've read dozens of papers and they all stem from a purely theoretical/mathematical basis which is lost on a lot of folks.  I've often chuckled at every SIGGraph paper presentation on fluid dynamics when the speaker says, "We implemented the Navier-Stokes equations..."  Yeah, sure you did.  Show me well-documented code.

    Francis X Grovers has a video presentation from the DPRG that started off awesome but sadly he got distracted by too many questions so the tutorial is incomplete.

    And then, of course, I'm sure we'd all like to know how kalman filters can be used to fuse different sensor types together and how you can add additional sensor types.

  • Very cool. And the interactive parts really drive home how the different variables fit together in an intuitive way. In the few minutes it took me to read your clear tutorial I went from "read something about that on the 'drones discuss' forum, check that box in the parameters, 'cause it sounds cool" to comprehension. Keep up the fabulous work! 

  • Part4:

    there is:  x ^ k   =   x ^ k   +   0 * (z k - x ^ k-1 ) =  x ^ k-1
    must be:   x ^ k   =   x ^ k-1   +   0 * (z k - x ^ k-1 ) =  x ^ k-1

  • This is great! One of the best ways to learn/master a subject is to teach it. I'm sure you'll learn even more by creating this tutorial. I look forward to going through it! I too had a hard time trying to learn the EKF, still do. ;-)

  • I had a hard enough time understanding DCM and then Quaternions, but I did eventually understand enough to work with it and diagnose and correct problems in code.  If your tutorial can teach me, then it will be a success so keep it coming..

This reply was deleted.