0% found this document useful (0 votes)
212 views100 pages

Kalman Filter Explained - MOST SIMPLISTICALLY

The document discusses how a Kalman filter works by estimating the state of a dynamic system over time using a series of measurements observed over time that contain uncertainty. It uses the concept of a state that contains variables like position and velocity and predicts the next state using the previous state while accounting for uncertainty. It represents the state and its uncertainty using matrices like the mean and covariance matrix and can model correlations between state variables. The Kalman filter provides an optimal estimate of the true state of the system by combining predictions with new measurements in a way that minimizes uncertainty.

Uploaded by

user2127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views100 pages

Kalman Filter Explained - MOST SIMPLISTICALLY

The document discusses how a Kalman filter works by estimating the state of a dynamic system over time using a series of measurements observed over time that contain uncertainty. It uses the concept of a state that contains variables like position and velocity and predicts the next state using the previous state while accounting for uncertainty. It represents the state and its uncertainty using matrices like the mean and covariance matrix and can model correlations between state variables. The Kalman filter provides an optimal estimate of the true state of the system by combining predictions with new measurements in a way that minimizes uncertainty.

Uploaded by

user2127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Bzarg
On the future, science, & tech

How a Kalman �lter works, in pictures


I have to tell you about the Kalman �lter, because what it does is pretty damn amazing.

Surprisingly few software engineers and scientists seem to know about it, and that makes me sad
because it is such a general and powerful tool for combining information in the presence of un-
certainty. At times its ability to extract accurate information seems almost magical— and if it
sounds like I’m talking this up too much, then take a look at this previously posted video where I
demonstrate a Kalman �lter �guring out the orientation of a free-�oating body by looking at its ve-
locity. Totally neat!

What is it?

You can use a Kalman �lter in any place where you have uncertain information about some dy-
namic system, and you can make an educated guess about what the system is going to do next.
Even if messy reality comes along and interferes with the clean motion you guessed about, the
Kalman �lter will often do a very good job of �guring out what actually happened. And it can take
advantage of correlations between crazy phenomena that you maybe wouldn’t have thought to
exploit!

Kalman �lters are ideal for systems which are continuously changing. They have the advantage
that they are light on memory (they don’t need to keep any history other than the previous state),
and they are very fast, making them well suited for real time problems and embedded systems.

The math for implementing the Kalman �lter appears pretty scary and opaque in most places
you �nd on Google. That’s a bad state of a�airs, because the Kalman �lter is actually super sim-
ple and easy to understand if you look at it in the right way. Thus it makes a great article topic,
and I will attempt to illuminate it with lots of clear, pretty pictures and colors. The prerequisites
are simple; all you need is a basic understanding of probability and matrices.

I’ll start with a loose example of the kind of thing a Kalman �lter can solve, but if you want to get
right to the shiny pictures and math, feel free to jump ahead.

1 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

What can we do with a Kalman �lter?

Let’s make a toy example: You’ve built a little robot that can wander around in the woods, and
the robot needs to know exactly where it is so that it can navigate.


We’ll say our robot has a state xk , which is just a position and a velocity:


xk = (p ,⃗  v)⃗ 

Note that the state is just a list of numbers about the underlying con�guration of your system; it
could be anything. In our example it’s position and velocity, but it could be data about the
amount of �uid in a tank, the temperature of a car engine, the position of a user’s �nger on a
touchpad, or any number of things you need to keep track of.

Our robot also has a GPS sensor, which is accurate to about 10 meters, which is good, but it
needs to know its location more precisely than 10 meters. There are lots of gullies and cli�s in
these woods, and if the robot is wrong by more than a few feet, it could fall o� a cli�. So GPS by
itself is not good enough.

2 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

We might also know something about how the robot moves: It knows the commands sent to the
wheel motors, and its knows that if it’s headed in one direction and nothing interferes, at the next
instant it will likely be further along that same direction. But of course it doesn’t know everything
about its motion: It might be bu�eted by the wind, the wheels might slip a little bit, or roll over
bumpy terrain; so the amount the wheels have turned might not exactly represent how far the
robot has actually traveled, and the prediction won’t be perfect.

The GPS sensor tells us something about the state, but only indirectly, and with some uncertainty
or inaccuracy. Our prediction tells us something about how the robot is moving, but only indi-
rectly, and with some uncertainty or inaccuracy.

But if we use all the information available to us, can we get a better answer than either estimate
would give us by itself? Of course the answer is yes, and that’s what a Kalman �lter is for.

How a Kalman �lter sees your problem

Let’s look at the landscape we’re trying to interpret. We’ll continue with a simple state having only
position and velocity.

x⃗  = [ ]
p
v

We don’t know what the actual position and velocity are; there are a whole range of possible
combinations of position and velocity that might be true, but some of them are more likely than
others:

3 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

The Kalman �lter assumes that both variables (postion and velocity, in our case) are random and
Gaussian distributed. Each variable has a mean value μ, which is the center of the random distri-
bution (and its most likely state), and a variance σ 2 , which is the uncertainty:

In the above picture, position and velocity are uncorrelated, which means that the state of one
variable tells you nothing about what the other might be.

The example below shows something more interesting: Position and velocity are correlated. The
likelihood of observing a particular position depends on what velocity you have:

This kind of situation might arise if, for example, we are estimating a new position based on an
old one. If our velocity was high, we probably moved farther, so our position will be more distant.
If we’re moving slowly, we didn’t get as far.

This kind of relationship is really important to keep track of, because it gives us more informa-

4 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

tion: One measurement tells us something about what the others could be. And that’s the goal of
the Kalman �lter, we want to squeeze as much information from our uncertain measurements as
we possibly can!

This correlation is captured by something called a covariance matrix. In short, each element of
the matrix Σij is the degree of correlation between the ith state variable and the jth state vari-
able. (You might be able to guess that the covariance matrix is symmetric, which means that it
doesn’t matter if you swap i and j). Covariance matrices are often labelled “Σ”, so we call their el-
ements “Σij ”.

Describing the problem with matrices

We’re modeling our knowledge about the state as a Gaussian blob, so we need two pieces of in-
^k (the mean, elsewhere named μ ), and its co-
formation at time k : We’ll call our best estimate x
variance matrix Pk .

position
^k = [
x ]
velocity
(1)
Σpp Σpv
Pk = [ ]
Σvp Σvv

(Of course we are using only position and velocity here, but it’s useful to remember that the state
can contain any number of variables, and represent anything you want).

Next, we need some way to look at the current state (at time k-1) and predict the next state at
time k. Remember, we don’t know which state is the “real” one, but our prediction function
doesn’t care. It just works on all of them, and gives us a new distribution:

5 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

We can represent this prediction step with a matrix, Fk :

It takes every point in our original estimate and moves it to a new predicted location, which is
where the system would move if that original estimate was the right one.

Let’s apply this. How would we use a matrix to predict the position and velocity at the next mo-
ment in the future? We’ll use a really basic kinematic formula:

pk = pk−1 + Δtvk−1
vk = vk−1
In other words:

1 Δt
^k = [
x ]x
^k−1 (2)
0 1
^k−1
= Fk x (3)

6 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

We now have a prediction matrix which gives us our next state, but we still don’t know how to
update the covariance matrix.

This is where we need another formula. If we multiply every point in a distribution by a matrix A,
then what happens to its covariance matrix Σ?

Well, it’s easy. I’ll just give you the identity:

Cov(x) = Σ
(4)
Cov(Ax) = AΣAT

So combining (4) with equation (3) :

^ k = Fk x
x ^k−1
(5)
Pk = Fk Pk−1 FTk

External in�uence

We haven’t captured everything, though. There might be some changes that aren’t related to
the state itself— the outside world could be a�ecting the system.

For example, if the state models the motion of a train, the train operator might push on the
throttle, causing the train to accelerate. Similarly, in our robot example, the navigation software
might issue a command to turn the wheels or stop. If we know this additional information about

what’s going on in the world, we could stu� it into a vector called uk , do something with it, and
add it to our prediction as a correction.

Let’s say we know the expected acceleration a due to the throttle setting or control commands.
From basic kinematics we get:

1
pk = pk−1 + Δtvk−1 + aΔt2
2
vk = vk−1 +aΔt
In matrix form:

Δt2
^k−1 + [
^ k = Fk x
x 2 ]a
Δt (6)

^k−1 + Bk uk
= Fk x


Bk is called the control matrix and uk the control vector. (For very simple systems with no ex-
ternal in�uence, you could omit these).

7 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Let’s add one more detail. What happens if our prediction is not a 100% accurate model of what’s
actually going on?

External uncertainty

Everything is �ne if the state evolves based on its own properties. Everything is still �ne if the
state evolves based on external forces, so long as we know what those external forces are.

But what about forces that we don’t know about? If we’re tracking a quadcopter, for example, it
could be bu�eted around by wind. If we’re tracking a wheeled robot, the wheels could slip, or
bumps on the ground could slow it down. We can’t keep track of these things, and if any of this
happens, our prediction could be o� because we didn’t account for those extra forces.

We can model the uncertainty associated with the “world” (i.e. things we aren’t keeping track of)
by adding some new uncertainty after every prediction step:

Every state in our original estimate could have moved to a range of states. Because we like
^k−1 is moved to somewhere inside a
Gaussian blobs so much, we’ll say that each point in x
Gaussian blob with covariance Qk . Another way to say this is that we are treating the untracked
in�uences as noise with covariance Qk .

8 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

This produces a new Gaussian blob, with a di�erent covariance (but the same mean):

We get the expanded covariance by simply adding Qk , giving our complete expression for the
prediction step:


^ k = Fk x
x ^k−1 + Bk uk
(7)
Pk = Fk Pk−1 FTk + Qk

In other words, the new best estimate is a prediction made from previous best estimate, plus
a correction for known external in�uences.

And the new uncertainty is predicted from the old uncertainty, with some additional uncer-
tainty from the environment.

All right, so that’s easy enough. We have a fuzzy estimate of where our system might be, given by
^k and Pk . What happens when we get some data from our sensors?
x

Re�ning the estimate with measurements

We might have several sensors which give us information about the state of our system. For the

9 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

time being it doesn’t matter what they measure; perhaps one reads position and the other reads
velocity. Each sensor tells us something indirect about the state— in other words, the sensors
operate on a state and produce a set of readings.

Notice that the units and scale of the reading might not be the same as the units and scale of the
state we’re keeping track of. You might be able to guess where this is going: We’ll model the sen-
sors with a matrix, Hk .

We can �gure out the distribution of sensor readings we’d expect to see in the usual way:

^k
μ⃗ expected = Hk x
(8)
Σexpected = Hk Pk HTk

One thing that Kalman �lters are great for is dealing with sensor noise. In other words, our sen-
sors are at least somewhat unreliable, and every state in our original estimate might result in a

10 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

range of sensor readings.

From each reading we observe, we might guess that our system was in a particular state. But be-
cause there is uncertainty, some states are more likely than others to have have produced the
reading we saw:

We’ll call the covariance of this uncertainty (i.e. of the sensor noise) Rk . The distribution has a

mean equal to the reading we observed, which we’ll call zk .

So now we have two Gaussian blobs: One surrounding the mean of our transformed prediction,
and one surrounding the actual sensor reading we got.

11 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

We must try to reconcile our guess about the readings we’d see based on the predicted state
(pink) with a di�erent guess based on our sensor readings (green) that we actually observed.

So what’s our new most likely state? For any possible reading (z1 , z2 ) , we have two associated

probabilities: (1) The probability that our sensor reading  zk is a (mis-)measurement of (z1 , z2 ) ,
and (2) the probability that our previous estimate thinks (z1 , z2 ) is the reading we should see.

If we have two probabilities and we want to know the chance that both are true, we just multiply
them together. So, we take the two Gaussian blobs and multiply them:

What we’re left with is the overlap, the region where both blobs are bright/likely. And it’s a lot
more precise than either of our previous estimates. The mean of this distribution is the con�gu-
ration for which both estimates are most likely, and is therefore the best guess of the true
con�guration given all the information we have.

Hmm. This looks like another Gaussian blob.

12 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

As it turns out, when you multiply two Gaussian blobs with separate means and covariance ma-
trices, you get a new Gaussian blob with its own mean and covariance matrix! Maybe you can see
where this is going: There’s got to be a formula to get those new parameters from the old ones!

Combining Gaussians

Let’s �nd that formula. It’s easiest to look at this �rst in one dimension. A 1D Gaussian bell curve
with variance σ 2 and mean μ is de�ned as:
2
1 −
(x–μ)

N (x, μ, σ) = −− e 2σ 2 (9)
σ√2π

We want to know what happens when you multiply two Gaussian curves together. The blue curve
below represents the (unnormalized) intersection of the two Gaussian populations:

13 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

?
N (x, μ0 , σ0 ) ⋅ N (x, μ1 , σ1 ) = N (x, μ′ , σ ′ ) (10)

You can substitute equation (9) into equation (10) and do some algebra (being careful to renor-
malize, so that the total probability is 1) to obtain:


σ02 (μ1 – μ0 )
μ = μ0 +
σ02 + σ12
(11)
′2
σ04
σ = σ02 –
σ02 + σ12

We can simplify by factoring out a little piece and calling it k:

σ02
k= (12)
σ02 + σ12
μ′ = μ0 +k(μ1 – μ0 )
2 (13)
σ ′ = σ02 – kσ02

Take note of how you can take your previous estimate and add something to make a new esti-
mate. And look at how simple that formula is!

But what about a matrix version? Well, let’s just re-write equations (12) and (13) in matrix form.
If Σ is the covariance matrix of a Gaussian blob, and μ⃗ its mean along each axis, then:

K = Σ0 (Σ0 + Σ1 )−1 (14)


′ → → →
μ⃗  = μ0 +K(μ1 – μ0 ) (15)
Σ′ = Σ0 – KΣ0

K is a matrix called the Kalman gain, and we’ll use it in just a moment.

Easy! We’re almost �nished!

Putting it all together

We have two distributions: The predicted measurement with (μ0 , Σ0 ) ^k , Hk Pk HTk ),


= (Hk x

and the observed measurement with (μ1 , Σ1 ) = (zk , Rk ). We can just plug these into equa-

14 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

tion (15) to �nd their overlap:


Hk x^′k = Hk x
^k ^k )
+K(zk – Hk x
(16)
Hk P′k HTk = Hk Pk HTk –KHk Pk HTk

And from (14) , the Kalman gain is:

K = Hk Pk HTk (Hk Pk HTk + Rk )−1 (17)

We can knock an Hk o� the front of every term in (16) and (17) (note that one is hiding inside

K ), and an HTk o� the end of all terms in the equation for Pk .


^′k = x
x ^k +K′ (zk – Hk x
^k )
′ ′
(18)
Pk = Pk – K Hk Pk

K′ = Pk HTk (Hk Pk HTk + Rk )−1 (19)

…giving us the complete equations for the update step.

′ ′
^k is our new best estimate, and we can go on and feed it (along with Pk ) back
And that’s it! x
into another round of predict or update as many times as we like.

15 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Wrapping up

Of all the math above, all you need to implement are equations (7), (18) , and (19) . (Or if you
forget those, you could re-derive everything from equations (4) and (15) .)

This will allow you to model any linear system accurately. For nonlinear systems, we use the ex-
tended Kalman �lter, which works by simply linearizing the predictions and measurements
about their mean. (I may do a second write-up on the EKF in the future).

If I’ve done my job well, hopefully someone else out there will realize how cool these things are
and come up with an unexpected new place to put them into action.

Some credit and referral should be given to this �ne document, which uses a similar approach in-
volving overlapping Gaussians. More in-depth derivations can be found there, for the curious.

This entry was posted in Mini-courses, Programming on August 11, 2015 [https://www.bzarg.com
/p/how-a-kalman-�lter-works-in-pictures/] .

315 thoughts on “How a Kalman �lter works, in pictures”

16 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Valen
August 11, 2015 at 5:51 pm

Great article! Loving your other posts as well.

AKM Sabbir
February 28, 2017 at 4:19 am

it seems its linear time dependent model. is it possible to introduce nonlinearity. what if the
transformation is not linear. then how do you approximate the non linearity. every state repre-
sents the parametric form of a distribution. that means the actual state need to be sampled. is
not it an expensive process?

AKM Sabbir
February 28, 2017 at 4:22 am

i am sorry u mentioned Extended Kalman Filter. i apologize, i missed the last part. great write up.
i really loved it.

r00bi
October 12, 2019 at 12:37 pm

Thanks, it was a nice article!


How can I plot the uncertainty surrounding each point (mean) in python?

James
January 15, 2020 at 12:59 pm

17 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

I �nd drawing ellipses helps me visualize it nicely.

For a quick-and-dirty plot, you can treat each row (or column) of the covariance matrix as a vector
and plot out linear combinations of the two using sine and cosine. So given covariance matrix
and mean
M = [m11, m12; m21, m22]
u = [u1; u2]
your x and y values would be
x = u1 + m11 * cos(theta) + m12 * sin(theta)
y = u2 + m21 * cos(theta) + m22 * sin(theta)
Just sweep theta from 0 to 2pi and you’ve got an ellipse!

For a more in-depth approach check out this link:


https://www.visiondummy.com/2014/04/draw-error-ellipse-representing-covariance-matrix/

wangjiangjiang
December 20, 2019 at 1:27 am

Have you written an introduction to extended Kalman �ltering?

Beiming
November 19, 2017 at 2:15 pm

now I understood,you are greate!

18 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Camilla
August 11, 2015 at 8:42 pm

Wow! This article is amazing. Thank you very much for putting in the time and e�ort to produce
this.

Davi
January 4, 2017 at 10:06 am

Thank you very much!

george
August 11, 2015 at 9:34 pm

This is a nice and straight forward explanation .


Thanks.

sobhan
January 5, 2016 at 3:04 pm

I do agree…that is so great and I �nd it interesting and I will do it in other places ……and mention
your name dude……….thanks a lot.

Justin
August 11, 2015 at 9:35 pm

Hey Tim what did you use to draw this illustration?

19 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

https://www.bzarg.com/wp-content/uploads/2015/08/kal�ow.png

tbabb Post author

August 13, 2015 at 12:07 am

All the illustrations are done primarily with Photoshop and a stylus.

Philip Tellis
August 11, 2015 at 10:30 pm

Nice explanation. Looks like someone wrote a Kalman �lter implementation in Julia:
https://github.com/wkearn/Kalman.jl

Paul Masurel
August 11, 2015 at 11:22 pm

Great post! Keep up the good work!

Ben Jackson
August 12, 2015 at 12:10 am

Nice work! I literally just drew half of those covariance diagrams on a whiteboard for someone.
Now I can just direct everyone to your page.

Maxime Caron
August 12, 2015 at 12:10 am

20 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Great post. Keep up the good work! I am hoping for the Extended Kalman �lter soon.

Sebastian
August 12, 2015 at 1:49 am

What happens if your sensors only measure one of the state variables. Do you just make the H
matrix to drop the rows you don’t have sensor data for and it all works out?

Raj Samant
December 12, 2015 at 5:22 pm

You reduce the rank of H matrix, omitting row will not make Hx multiplication possible. If in
above example only position is measured state u make H = [1 0; 0 0]. If both are measurable then
u make H = [1 0; 0 1];

Jim Hejl
August 12, 2015 at 2:09 am

great write up! Thx!!

John Shea
August 12, 2015 at 2:19 am

Very nice, but are you missing squares on those variances in (1)?

Santanu Dutt

21 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

December 28, 2016 at 11:55 am

Thanks a lot for this wonderfully illuminating article. Like many others who have replied, this too
was the �rst time I got to understand what the Kalman Filter does and how it does it. Thanks a lot

Ilya Kavalerov
August 12, 2015 at 2:34 am

Nice post!

Near ‘You can use a Kalman �lter in any place where you have uncertain information’ shouldn’t
there be a caveat that the ‘dynamic system’ obeys the markov property? I.e. a process where
given the present, the future is independent of the past (not true in �nancial data for example).

Also just curious, why no references to hidden markov models, the Kalman �lter’s discrete (and
simpler) cousin?

Jan Galkowski
August 12, 2015 at 2:10 pm

Don’t know if this question was answered, but, yes, there is a Markovian assumption in the
model, as well as an assumption of linearity. But, at least in my technical opinion, that sounds
much more restrictive than it actually is in practice. If the system (or “plant”) changes its internal
“state” smoothly, the linearization of the Kalman is nothing more than using a local Taylor expan-
sion of that state behavior, and, to some degree, a faster rate of change can be compensated for
by increasing sampling rate. As far as the Markovian assumption goes, I think most models which
are not Markovian can be transformed into alternate models which are Markovian, using a
change in variables and such.

tom
August 12, 2015 at 3:24 am

22 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Awesome post! I’m impressed.

Kalen
August 12, 2015 at 5:57 am

Aaaargh!
I wish I’d known about these �lters a couple years back – they would have helped me solve an
embedded control problem with lots of measurement uncertainty.

Thanks for the great post!

Mike McRoberts
August 12, 2015 at 7:33 am

Great article and very informative. Love the use of graphics. I would love to see another on the
‘extended Kalman �lter’.

Thanks,

Mike

Yola
February 26, 2018 at 10:23 am

The same here! And i agree the post is clear to read and understand. Thanks to the author!

Pedrow
August 12, 2015 at 10:54 am

23 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Great article, thanks!

It would be great if you could repeat all the de�nitions just after equations (18) and (19) – I found
myself constantly scrolling up & down because I couldn’t remember what z was, etc. etc.

Greg Yaks
August 12, 2015 at 12:20 pm

Just before equation (2), the kinematics part, shouldn’t the �rst equation be about p_k rather than
x_k, i.e., position and not the state?

santaraxita
August 12, 2015 at 9:10 pm

This is an excellent piece of pedagogy. Every step in the exposition seems natural and reason-
able. I just chanced upon this post having the vaguest idea about Kalman �lters but now I can
pretty much derive it. The only thing I have to ask is whether the control matrix/vector must
come from the second order terms of the taylor expansion or is that a pedagogical choice you
made as an instance of external in�uence? Also, I guess in general your prediction matrices can
come from a one-parameter group of di�eomorphisms.

tbabb Post author

August 13, 2015 at 12:09 am

Nope, using acceleration was just a pedagogical choice since the example was using kinematics.
The control matrix need not be a higher order Taylor term; just a way to mix “environment” state
into the system state.

Jai

24 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

August 12, 2015 at 9:30 pm

I wish there were more posts like this. That explain how amazing and simple ideas are repre-
sented by scary symbols. Loved the approach. Can you please do one on Gibbs
Sampling/Metropolis Hastings Algorithm as well?

Eric O. LEBIGOT
August 12, 2015 at 10:31 pm

Very nice write up! The use of colors in the equations and drawings is useful.

Small nitpick: an early graph that shows the uncertainties on x should say that sigma is the stan-
dard deviation, not the “variance”.

tbabb Post author

August 12, 2015 at 11:12 pm

@Eric Lebigot: Ah, yes, the diagram is missing a ‘squared’ on the sigma symbols. I’ll �x that when I
next have access to the source �le for that image.

Nico Galoppo
August 12, 2015 at 11:34 pm

Eye opening. The only part I didn’t follow in the derivation, is where the left hand side of (16)
came from… until I realized that you de�ned x’_k and P’_k in the true state space coordinate sys-
tem, not in the measurement coordinate system – hence the use of H_k!

Antti

25 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

August 13, 2015 at 6:19 am

Hmm, I didn’t think this through yet, but don’t you need to have a pretty good initial guess for
your orientation (in the video example) in order for the future estimates to be accurate? Please
show this is not so :)

Great illustration and nice work! Thanks!

Antti
August 13, 2015 at 6:21 am

(Or is it all “hidden” in the “velocity constrains acceleration” information?)

tbabb Post author

August 13, 2015 at 6:56 am

The Kalman �lter is quite good at converging on an accurate state from a poor initial guess.
Representing the uncertainty accurately will help attain convergence more quickly– if your initial
guess overstates its con�dence, the �lter may take awhile before it begins to “trust” the sensor
readings instead.

In the linked video, the initial orientation is completely random, if I recall correctly. I think it actu-
ally converges quite a bit before the �rst frame even renders. :)

Dayne Batten
August 13, 2015 at 12:32 pm

“The math for implementing the Kalman �lter appears pretty scary and opaque in most places
you �nd on Google.” Indeed. I’ve tried to puzzle my way through the Wikipedia explanation of
Kalman �lters on more than one occasion, and always gave up.

26 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

I was able to walk through your explanation with no trouble. Thank you.

Ju
August 24, 2015 at 2:39 pm

I’m a PhD student in economics and decided a while back to never ask Wikipedia for anything re-
lated to economics, statistics or mathematics because you will only leave feeling inadequate and
confused. Seriously, concepts that I know and understand perfectly well look like egyptian hiero-
glyphs when I look at the wikipedia representation. I would ONLY look at the verbal description
and introduction, the formulas seem to all be written by a wizard savant.

Alex Polotsk
August 13, 2015 at 12:34 pm

The article has a perfect balance between intuition and math! This is the �rst time I actually un-
derstood Kalman �lter. =)

I have a couple of questions.

The way we got second equation in (4) wasn’t easy for me to see until I manually computed it
from the �rst equation in (4). Is it meant to be so, or did I missed a simple relation? When you say
“I’ll just give you the identity”, what “identity” are you referring to? Are you referring to given
equalities in (4)?

So, sensors produce:


– observed noisy mean and covariance (z and R) we want to correct, and
– an additional info ‘control vector’ (u) with known relation to our prediction.
Correct?

Does H in (8) maps physical measurements (e.g. km/h) into raw data readings from sensors (e.g.
uint32, as described in some accelerometer’s reference manual)?

Post author

27 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

tbabb
August 13, 2015 at 7:13 pm

(4) was not meant to be derived by the reader; just given.

Z and R are sensor mean and covariance, yes. The control vector ‘u’ is generally not treated as re-
lated to the sensors (which are a transformation of the system state, not the environment), and
are in some sense considered to be “certain”. For example, the commands issued to the motors
in a robot are known exactly (though any uncertainty in the execution of that motion could be
folded into the process covariance Q).

Yes, H maps the units of the state to any other scale, be they di�erent physical units or sensor
data units. I suppose you could transform the sensor measurements to a standard physical unit
before it’s input to the Kalman �lter and let H be the some permutation matrix, but you would
have to be careful to transform your sensor covariance into that same space as well, and that’s
basically what the Kalman �lter is already doing for you by including a term for H. (That would
also assume that all your sensors make orthogonal measurements, which not necessarily true in
practice).

Nico Galoppo
August 13, 2015 at 4:39 pm

So what happens if you don’t have measurements for all DOFs in your state vector? I’m assuming
that means that H_k isn’t square, in which case some of the derivation doesn’t hold, right? What
do you do in that case?

Robert
August 13, 2015 at 7:44 pm

Excellent explanation. Thanks!

28 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

John Dabbar
August 15, 2015 at 12:07 am

Kalman �lters are used in dynamic positioning systems for o�shore oil drilling.

Istvan Hajnal
August 15, 2015 at 3:13 pm

Great write up. Very helpful. Thanks.

Just one question. Shouldn’t it be p_k in stead of x_k (and p_k-1 instead of x_k-1) in the equation
right before equation (2)? Also, in (2), that’s the transpose of x_k-1, right?
I guess the same thing applies to equation right before (6)?

Regards,
Istvan Hajnal

tbabb Post author

August 17, 2015 at 8:21 pm

Yes, my thinking was to make those kinematic equations look “familiar” by using x (and it would
be understood where it came from), but perhaps the inconsistency is worse. :\

Sourjya Sarkar
August 17, 2015 at 2:30 pm

Great ! Really interesting and comprehensive to read.

29 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Li
August 18, 2015 at 5:28 pm

Thanks for the post, I have learnt a lot. My background is signal processing, pattern recognition.

One question:

If we have two probabilities and we want to know the chance that both are true, we just multiply
them together.

Why not use sum or become Chi-square distribution?

Because from http://math.stackexchange.com/questions/101062/is-the-product-of-two-gaussian-


random-variables-also-a-gaussian

The product of two Gaussian random variables is distributed, in general, as a linear combination
of two Chi-square random variables.

Thanks,
Regards,
Li

tbabb Post author

August 20, 2015 at 6:48 pm

Ah, not quite. Let X and Y both be Gaussian distributed. We are not doing pdf(X ⋅ Y ), we are
doing pdf(X) ⋅ pdf(Y )!

Peter
June 21, 2017 at 8:41 am

Hello, is there a reason why we multiply the two Gaussian pdfs together? I mean, why not add
them up or do convolution or a weighted sum…etc?

30 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

And thanks for the great explanations of kalman �lter in the post :)

Hairuo
March 27, 2018 at 10:22 pm

Here is a good explanation whey it is the product of two Gaussian PDF. Basically, it is due to
Bayesian principle
https://math.stackexchange.com/q/2630447

Raphael Michel
August 19, 2015 at 4:33 pm

Really interesting article. Clear and simple. Exactly what I needed.

Stephane
August 20, 2015 at 6:23 am

Thank you very much for this very clear article!

Qu
August 20, 2015 at 8:43 am

Great post ! I have a question about fomula (7), How to get Qk genenrally ?

Prof. Vadlamani Ravi


August 21, 2015 at 11:42 pm

31 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Great post. It demysti�es the Kalman �lter in simple graphics. A great teaching aid. Thx.

Chintan
August 25, 2015 at 4:32 pm

Hello Tim,

Very nice article. I had read the signal processing article that you cite and had given up half way.

This article clears many things. I will now have to implement it myself.

It would be nice if you could write another article with an example or maybe provide Matlab or
Python code.

Keep up the good work.

Best Regards

Chintan

Naseem Makiya
August 26, 2015 at 3:49 am

Awesome post!!! Great visuals and explanations.

32 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Paul
October 7, 2015 at 7:34 pm

Can you realy knock an Hk o� the front of every term in (16) and (17) ?
I think this operation is forbidden for this matrix.

Insik
October 13, 2015 at 8:48 am

Wow! This post is amazing. It really helps me to understand true meaning behind equations.

rosie
October 28, 2015 at 5:48 am

This is simplyy awesum!!!! this demonstration has given our team a con�dence to cope up with
the assigned project

Debo
November 5, 2015 at 12:52 pm

Great post! Thanks

33 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

hec
November 13, 2015 at 1:54 am

Amazing article, I struggled over the textbook explanations. This article summed up 4 months of
graduate lectures, and i �nally know whats going on. Thank you.

Nezih
November 13, 2015 at 10:01 am

Greta article, thank you!

Mel
November 18, 2015 at 5:52 pm

Great work. Thanks!

34 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Jose Kurian
November 19, 2015 at 1:26 pm

Hello,

This is indeed a great article. I have been trying to understand this �lter for some time now. This
article makes most of the steps involved in developing the �lter clear.

I how ever did not understand equation 8 where you model the sensor. What does the parame-
ter H do here. How do you obtain the components of H.

Thanks in advance,

Jose

carolinux
November 30, 2015 at 1:13 pm

Very good job explaining and illustrating these! Now I understand how the Kalman gain equation
is derived. It was hidden inside the properties of Gaussian probability distributions all along!

Sam
December 5, 2015 at 4:09 pm

This is the greatest explanation ever!

Vidhya Venugopal
December 10, 2015 at 1:37 am

Great explanation! I have a question though just to clarify my understanding of Kalman Filtering.

35 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

In the above example (position, velocity), we are providing a constant acceleration value ‘a’.
Assuming this is a car example, let’s say the driver decides to change the acceleration during the
trip. From what I understand of the �lter, I would have to provide this value to my Kalman �lter
for it to calculated the predicted state every time I change the acceleration. Kalman �lter would
be able to “predict” the state without the information that the acceleration was changed. Is this
correct? Also, would this be impractical in a real world situation, where I may not always be aware
how much the control (input) changed?
Can anyone help me with this?

javad
January 2, 2016 at 4:56 pm

you are the best Tim!


thank you very much

minh
January 8, 2016 at 12:05 am

hey, my kalman �lter output is lagging the original signal. However it does a great job smoothing.
How does lagging happen

Sujay
January 21, 2016 at 7:23 am

I must say the best link in the �rst page of google to understand Kalman �lters. I guess I read
around 5 documents and this is by far the best one. Well done and thanks!! cheers!! :D

Salman
February 4, 2016 at 5:47 am

36 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Excellent explanation.

After reading many times about Kalman �lter and giving up on numerous occasions because of
the complex probability mathematics, this article certainly keeps you interested till the end when
you realize that you just understood the entire concept.

Keep up the good work.

Ben
February 4, 2016 at 11:01 am

Thank you for your excelent work!


There is no doubt, this is the best tutorial about KF !
Many thanks!

William A
February 17, 2016 at 9:23 pm

Great article ! Clear and easy to understand.

Paul
February 24, 2016 at 12:40 pm

This is by far the best explanation of a Kalman �lter I have seen yet. Very well done.

Baljit Kaur
March 1, 2016 at 10:19 am

37 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

v.nice explanation. Actually I have something di�erent problem if you can provide a solution to
me. In my system, I have starting and end position of a robot. I need to �nd angle if robot needs
to rotate and velocity of a robot. Can I get solution that what will be Transition matrix, x(k-1), b(k),
u(k).
Thanks Baljit

Maneesha K
March 20, 2016 at 11:40 am

Such an amazing explanation of the much scary kalman �lter. Kudos to the author. Thanks very
much Sir. Expecting such explanation for EKF, UKF and Particle �lter as well.

Ali
March 23, 2016 at 6:11 pm

Hello There!

Great article but I have a question. Why did you consider acceleration as external in�uance?
Could we add the acceleration inside the F matrix directly e.g. x=[position, velocity, acceleration]’
?

Thanks!

Clive Myrie
May 6, 2016 at 2:47 pm

I think that acceleration was considered an external in�uence because in real life applications
acceleration is what the controller has (for lack of a better word) control of. In other words, accel-
eration and acceleration commands are how a controller in�uences a dynamic system.

38 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Minh
March 28, 2016 at 1:54 am

Thank you so so much Tim. The math in most articles on Kalman Filtering looks pretty scary and
obscure, but you make it so intuitive and accessible (and fun also, in my opinion). Again excellent
job! Would you mind if I share part of the particles to my peers in the lab and maybe my students
in problem sessions? I’ll certainly mention the source

Jeroen
April 1, 2016 at 12:01 pm

Best explanation I’ve read so far on the Kalman �lter. Far better than many textbooks. Thank you.

Graeme
April 3, 2016 at 8:43 pm

Without doubt the best explanation of the Kalman �lter I have come across! Often in DSP, learn-
ing materials begin with the mathematics and don’t give you the intuitive understanding of the
problem you need to fully grasp the problem. This is a great resource. Thanks.

vishwanath
April 9, 2016 at 11:30 am

amazing…simply simpli�ed.you saved me a lot of time…thanks for the post.please update with
nonlinear �lters if possible that would be a great help.

Laurent Vosgien
April 23, 2016 at 4:31 pm

39 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Your original approach (is it ?) of combining Gaussian distributions to derive the Kalman �lter
gain is elegant and intuitive. All presentations of the Kalman �lter that I have read use matrix al-
gebra to derive the gain that minimizes the updated covariance matrix to come to the same re-
sult. That was satisfying enough to me up to a point but I felt i had to transform X and P to the
measurement domain (using H) to be able to convince myself that the gain was just the barycen-
ter between the a priori prediction distribution and the measurement distributions weighted by
their covariances. This is where other articles confuse the reader by introducing Y and S which
are the di�erence z-H*x called innovation and its covariance matrix. Then they have to call S a
“residual” of covariance which blurs understanding of what the gain actually represents when ex-
pressed from P and S. Good job on that part !

I will be less pleasant for the rest of my comment, your article is misleading in the bene�t versus
e�ort required in developing an augmented model to implement the Kalman �lter. By the time
you invested the research and developing integrated models equations for errors of your sensors
which is what the KF �lter is about, not the the recursive algorithm principle presented here
which is trivial by comparison.

There is nothing magic about the Kalman �lter, if you expect it to give you miraculous results out
of the box you are in for a big disappointment. By the time you have developed the level of un-
derstanding of your system errors propagation the Kalman �lter is only 1% of the real work asso-
ciated to get those models into motion. There is a continuous supply of serious failed Kalman
Filters papers where greedy people expect to get something from nothing implement a EKF or
UKF and the result are junk or poor. All because of article like yours give the false impression that
understanding a couple of stochastic process principles and matrix algebra will give miraculous
results. The work in not where you insinuate it is. Understanding the Kalman �lter predict and
update matrix equation is only opening a door but most people reading your article will think it’s
the main part when it is only a small chapter out of 16 chapters that you need to master and 2 to
5% of the work required.

Byambajav
April 27, 2016 at 11:27 am

Great article I’ve ever been reading on subject of Kalman �ltering. Thanks !!!

Edu
April 28, 2016 at 10:58 pm

40 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

fantastic | thanks for the outstanding post !

Wanjohi
May 5, 2016 at 9:54 am

First time am getting this stu�…..it doesn’t sound Greek and Chinese…..greekochinese…..
on point….and very good work…..

Mohamad
May 8, 2016 at 2:32 am

thank you Tim for your informative post, I did enjoy when I was reading it, very easy and logic…
good job

Kurt Ramsdale
May 11, 2016 at 5:08 am

Equation 18 (measurement variable) is wrong.


Equation 16 is right. Divide all by H.

tbabb Post author

May 11, 2016 at 5:43 am

What’s the issue? Note that K has a leading H_k inside of it, which is knocked o� to make K’.

Kurt Ramsdale

41 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

May 11, 2016 at 8:23 am

x has the units of the state variables.


z has the units of the measurement variables.
K is unitless 0-1.
The units don’t work unless the right term is K(z/H-x).

Mehdi
May 11, 2016 at 12:06 pm

Excellent Post! Kalman Filter has found applications in so diverse �elds. A great one to mention is
as a online learning algorithm for Arti�cial Neural Networks.

vishnu
May 12, 2016 at 10:21 am

Great Article. Nicely articulated. Do you recommened any C++ or python implementation of
kalman �lter? I know there are many in google but your recommendation is not the same which i
choose.

Assume that every car is connected to internet. I am trying to predict the movement of bunch of
cars, where they probably going in next ,say 15 min. you can assume like 4 regions A,B,C,D
(5-10km of radius) which are close to each other. How can I make use of kalman �lter to predict
and say, so many number cars have moved from A to B.

I am actullay having trouble with making the Covariance Matrix and Prediction Matrix. In my case
I know only position. Veloctiy of the car is not reported to the cloud. So First step could be guess-
ing the velocity from 2 consecutive position points, then forming velocity vector and position vec-
tor.Then applying your equations. Is my assumption is right? Thanks

P.S: sorry for the long comment.Need Help. Thanks

42 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Ebrahim Mirzaei
May 17, 2016 at 3:51 pm

Excellent Post! thanks alot.


I want to use kalman Filter to auto correct 2m temperature NWP forecasts.
Could you please help me to get a solution or code in R, FORTRAN or Linux Shell
Scripts(bash,perl,csh,…) to do this.

omid
May 20, 2016 at 8:24 pm

Hi
I’m kinda new to this �eld and this document helped me a lot
I just have one question and that is what is the value of the covariance matrix at the start of the
process?

Will
May 20, 2016 at 9:29 pm

This is the best article I’ve read on Kalman �lter so far by a long mile!

Will
May 20, 2016 at 9:32 pm

Btw, will there be an article on Extend Kalman Filter sometime in the future, soon hopefully?

Thanks! Great work

43 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

urwa
May 22, 2016 at 1:52 pm

Thanks a bunch. :) Very helpful indeed

Sagar
May 25, 2016 at 2:44 pm

Thanks a lot :D Great article!

Taz Walker
May 31, 2016 at 2:24 am

Awesome thanks! :)

martin
June 7, 2016 at 5:14 pm

My main interest in the �lter is its signi�cance to Dualities which you have not mentioned – pity

Matheus
June 7, 2016 at 6:23 pm

Thank you for the really good work!

44 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Colin
June 11, 2016 at 10:26 am

Excellent. Thank you.

Chong
June 22, 2016 at 2:41 am

Excellent explanation! best I can �nd online for newbies! Pls do a similar one for UKF pls!

Manne
June 22, 2016 at 8:51 pm

This article completely �lls every hole I had in my understanding of the kalman �lter. Thank you
so much!

Nick
June 26, 2016 at 5:39 pm

Pure Gold !

Thanks!

45 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Pallanti Srinivas Rao


July 3, 2016 at 12:35 pm

Great work. The explanation is really very neat and clear.

meow
July 7, 2016 at 3:40 am

RIP Rudolf E. Kálmán.

shikhil bhalla
July 8, 2016 at 12:27 pm

Awsm work. kalman �lter was not that easy before. Thanks a lot.

Zsolt Zseludek
July 9, 2016 at 10:08 am

Great article. I used this �lter a few years ago in my embedded system, using code segments
from net, but now I �nally understand what I programmed before blindly :). Thanks.

46 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

MaheshAttade
July 10, 2016 at 5:48 pm

PURE AWESOMENESS!
Thanks.

nancy wei
July 12, 2016 at 3:52 am

Amazing! Funny and clear! Thanks a lot! It de�nitely give me a lot of help!!!!

ammar
July 13, 2016 at 3:36 pm

very helpful thanks

Trustmeimanengineer
July 14, 2016 at 9:34 pm

This is great actually. Im studying electrial engineering (master). Ive read plenty of Kalman Filter
explanations and derivations but they all kinda skip steps or forget to introduce variables, which
is lethal.
I had to laugh when I saw the diagram though, after seeing so many straight academic/technical
�ow charts of this, this was refreshing :D

If anyone really wants to get into it, implement the formulas in octave or matlab then you will see
how easy it is. This �lter is extremely helpful, “simple” and has countless applications.

47 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

ulzha
July 17, 2016 at 4:09 pm

Awesome! Acquisition of techniques like this might end up really useful for my robot builder aspi-
rations… *sigh* *waiting for parts to arrive*

satish
July 18, 2016 at 4:05 pm

An excellent way of teaching in a simplest way.

Abdulrahman Darwish
July 26, 2016 at 7:50 pm

Thank you so much, that was really helpful . AMAZING

James Wu
August 2, 2016 at 4:09 am

Excellent tutorial on kalman �lter, I have been trying to teach myself kalman �lter for a long time
with no success. But I actually understand it now after reading this, thanks a lot!!

48 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Harry
August 5, 2016 at 1:08 pm

Thank you very much for your explanation. This is the best tutorial that I found online. I’m also
expect to see the EKF tutorial. Thank you!!!

zjulion
August 10, 2016 at 9:36 am

Hi, dude,
great article.
there is a typo in eq(13) which should be \sigam_1 instead of \sigma_0.

tbabb Post author

August 12, 2016 at 8:28 am

Nope, that would give the wrong answer. See the same math in the citation at the bottom of the
article.

Oki Matra
August 14, 2016 at 6:24 pm

Please write your explanation on the EKF topic as soon as possible…, or please tell me the recom-
mended article about EKF that’s already existed by sending the article through the email :) (or the
link)

anderstood
August 20, 2016 at 11:27 pm

49 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Thank you for this excellent post. Just one detail: the fact that Gaussians are “simply” multiplied is
a very subtle point and not as trivial as it is presented, see http://stats.stackexchange.com
/questions/230596/why-do-the-probability-distributions-multiply-here.

Student
April 8, 2018 at 1:23 am

Great question! It has confused me a long time

Manny Glover
August 24, 2016 at 3:06 am

Just another big fan of the article. Great job! I de�nitely understand it better than I did before.

Sandra
August 26, 2016 at 4:04 pm

Oh my god. Thank you so much for this. Until now, I was totally and completely confused by
Kalman �lters. The pictures and examples are SO helpful. THANK YOU!!!

Hao Yang
August 30, 2016 at 4:28 pm

Thank you so much for this explaination.

Gary K

50 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

August 30, 2016 at 7:00 pm

Love it – thank you M. Bzarg! I owe you a signi�cant debt of gratitude…

Miriam
September 1, 2016 at 3:48 pm

Many thanks for this article,


sometimes the easiest way to explain something is really the harthest!
You did it!

Simon Chen
September 5, 2016 at 1:04 pm

Good job,thank you so much!

Vic Vega
September 7, 2016 at 11:00 pm

This is a great explanation. The one thing that you present as trivial, but I am not sure what the
inuition is, is this statement:

“””
This is where we need another formula. If we multiply every point in a distribution by a matrix A,
then what happens to its covariance matrix Σ?

Well, it’s easy. I’ll just give you the identity:


Cov(x)=Σ
Cov(Ax)==AΣA^T
“””

51 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Why is that easy? Thanks so much for your e�ort!

tbabb Post author

September 10, 2016 at 12:49 am

It’s easy because I gave it to you. :)

Will C
April 27, 2017 at 4:12 am

I think of it in shorthand – and I could be wrong – as


— you spread state x out by multiplying by A
— sigma is the covariance of the vector x (1d), which spreads x out by multiplying x by itself into
2d
so
— you spread the covariance of x out by multiplying by A in each dimension ; in the �rst dimen-
sion by A, and in the other dimension by A_t

Esteban Zuluaga
September 10, 2016 at 12:07 pm

Thanks for making science and math available to everyone!

On mean reverting linear systems how can I use the Kalman �lter to measure the half life of
mean reversion?

Alejandro
September 15, 2016 at 8:46 am

52 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Hey!

Just wanted to give some feedback. I really enjoyed your explanation of Kalman �lters. Also,
thank you very much for the reference!

Lars Kallryd
September 16, 2016 at 7:52 am

Thanks for a good tutorial !! What does a accelerometer cost to the Arduino? :D

Ste�
September 16, 2016 at 9:45 am

I have never come across so beautifully and clearly elaborated explanation for Kalman Filter such
as your article!! Thanks a lot for giving a lucid idea about Kalman Filter! Do continue to post many
more useful mathematical principles

hadi
September 17, 2016 at 3:44 am

Hey!

Thanks for the great article. I have a couple of questions though:

1) Why do we multiply the state vector (x) by H to make it compatible with the measurements.
Why don’t we do it the other way around? Would there be any issues if we did it the other way
around?

2) If you only have a position sensor (say a GPS), would it be possible to work with a PV model as
the one you have used? I understand that we can calculate the velocity between two successive
measurements as (x2 – x1/dt). I just don’t understand where this calculation would be �t in.

53 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Thanks :)

Selina
October 4, 2016 at 1:26 pm

I am currently working on my undergraduate project where I am using a Kalman Filter to use the
GPS and IMU data to improve the location and movements of an autonomous vehicle. I would
like to know what was in Matrix A that you multiplied out in equations 4 and 5. Thank you for the
helpful article!

Burak Cetinkaya
October 16, 2016 at 10:48 pm

The matrix A is just an example in equation 4, it is F_k in the equation 5. ( A = F_k )

Panruo Wu
October 6, 2016 at 12:15 am

Great article Thank you!

Nicolas Bouliane
October 15, 2016 at 10:41 am

Thanks for making math accessible to us. I wish more math topics were presented this well.

Rocco

54 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

October 17, 2016 at 9:16 pm

Very cool article! Thank you!

Rodrigo Alves
October 21, 2016 at 9:31 am

Awesome post. Thanks a lot !

Hazem Helal
October 22, 2016 at 1:58 pm

Thank you for your amazing work!


but i have a question please !
why this ??
We can knock an Hk o� the front of every term in (16) and (17) (note that one is hiding inside K ),
and an HTk o� the end of all terms in the equation for P′k.

thomai
October 23, 2016 at 5:36 pm

very nice! thanks!

55 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Bonobo2000
November 14, 2016 at 1:12 pm

excellent job, thanks a lot for this article.

Jonathan B
November 17, 2016 at 6:24 am

I know I am very late to this post, and I am aware that this comment could very well go unseen by
any other human eyes, but I also �gure that there is no hurt in asking. This article was very help-
ful to me in my research of kalman �lters and understanding how they work. I would absolutely
love if you were to do a similar article about the Extended Kalman �lter and the Unscented
Kalman Filter (or Sigma Point �lter, as it is sometimes called). If you never see this, or never write
a follow up, I still leave my thank you here, for this is quite a fantastic article.

Sheetal Bisht
November 17, 2016 at 8:36 pm

I cannot express how thankful am I to you. I have an interview and i was having trouble in under-
standing the Kalman Filter due to the mathematical equations given everywhere but how beauti-
fully have you explained Sir!! I understood each and every part and now feeling so con�dent
about the Interview. Thanks to you

Shilpi M
November 19, 2016 at 3:14 pm

Thank you very much..This article is really amazing

56 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Biao Yang
November 21, 2016 at 3:56 pm

I have been working on Kalman Filter , Particle Filter and Ensemble Kalman Filter for my whole
PhD thesis, and this article is absolutely the best tutorial for KF I’ve ever seen. I’m looking forward
to read your article on EnKF.

Biao Yang
November 21, 2016 at 4:13 pm

One thing may cause confusion this the normal * normal part. The product of two independent
normals are not normal. It should be better to explained as: p(x | z) = p(z | x) * p(x) / p(z) = N(z| x)
* N(x) / normalizing constant.

empiricist
February 17, 2017 at 3:24 am

Awesome. I felt something was at odds there too. anderstood in the previous reply also shared
the same confusion. I was about to reconcile it on my own, but you explained it right! Thanks!

Yagmur
November 22, 2016 at 7:48 pm

Thanks a lot for the nice and detailed explanation!

Livio
November 25, 2016 at 5:22 pm

57 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

After years of struggling to catch the physical meaning of all those matrices, evereything is crystal
clear �nally!

THANK YOU MAN, I LOVE YOU

johnny
December 2, 2016 at 7:46 am

Nice article!
it seems a C++ implementation of a Kalman �lter is made here :
https://github.com/hmartiro/kalman-cpp

Maissam
December 4, 2016 at 7:33 pm

what amazing description………thank you very very very much

Edu
December 9, 2016 at 1:15 am

Very good and clear explanation ! Many kudos !

Donovan Baarda
December 11, 2016 at 11:53 pm

For me the revelation on what kalman is came when I went through the maths for a single di-
mensional state (a 1×1 state matrix, which strips away all the matrix maths). When you do that it’s
pretty clear it’s just the weighed average between the model and the sensor(s), weighted by their

58 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

error variance.

It also explains how kalman �lters can have less lag. You can’t have a �lter without lag unless you
can predict the future, since �lters work by taking into account multiple past inputs. However,
with kalman the model is a a kind of “future” prediction (provided your model is good enough).

Math Fan
December 22, 2016 at 3:47 pm

Thank you for this article. It is very nice and helpful. One of the best teaching tips I picked up
from this is coloring equations to match the colored description. Brilliant!

When you knock o� the Hk matrix, that makes sense when Hk has an inverse. Is the result the
same when Hk has no inverse? In this case, how does the derivation change?

John
December 22, 2016 at 7:28 pm

Excellent ! You explained it clearly and simple. Thanks a lot!

Ramesh
December 23, 2016 at 10:44 pm

Awesome work !! . can you explain particle �lter also?

Neil
December 26, 2016 at 7:30 am

59 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

You explained it clearly and simplely. I had not seen it. Tks very much!

airyym
January 7, 2017 at 12:15 pm

It’s great post. But I have one question.


In equation (16), Where did the left part come from? Updated state is already multiplied by mea-
surement matrix and knocked o�? I couldn’t understand this step.

Mansoor Ghazi
January 11, 2017 at 4:58 pm

Thanks a lot! This is probably the best explanation of KF anywhere in the literature/internet.

Richard Manning
January 12, 2017 at 4:24 am

Really fantastic explanation of something that ba�es a lot of people (me included). Well done!

H.D.N.
January 13, 2017 at 12:32 am

So damn good! This is the �rst time that I �nally understand what Kalman �lter is doing.

miguel arrunategui
January 14, 2017 at 5:37 pm

60 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

I am a University software engineering professor, and this explanation is one of the best I have
seen, thanks for your outstanding work.

xchip
January 21, 2017 at 10:43 am

Where have you been all my life!!!! Finally got it!!!

W
January 21, 2017 at 1:49 pm

This is al kinds of awesome.

David
January 22, 2017 at 9:16 am

Great write-up! Thanks!

Vlad
January 24, 2017 at 3:14 pm

Loving the explanation.


A great refresher…

Divya
January 26, 2017 at 3:24 pm

61 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

This is an amazing explanation; took me an hour to understand what I had been trying to �gure
out for a week.
One question:
what exactly does H do? Can you give me an example of H? I was assuming that the observation x
IS the mean of where the real x could be, and it would have a certain variance. But instead, the
mean is Hx. Why is that? why is the mean not just x?
Thanks!

trecon
February 5, 2017 at 8:23 am

Thanks for the KF article. Very interesting!

juanattack
February 5, 2017 at 6:04 pm

Impressive and clear explanation of such a tough subject! Really loved the graphical way you
used, which appeals to many of us in a much more signi�cant way. Bravo!

Yao
February 6, 2017 at 11:15 pm

Great work! Thank you so much!

But I have a simple problem. In pratice, we never know the ground truth, so we should assign an
initial value for Pk. And my problem is Pk and kalman gain k are only determined by A,B,H,Q,R,
these parameters are constant. Therefore, as long as we are using the same sensor(the same R),
and we are measuring the same process(A,B,H,Q are the same), then everybody could use the
same Pk, and k before collecting the data. Am I right?

62 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Raul
February 10, 2017 at 10:59 am

Veeeery nice article! One of the best, if not the best, I’ve found about kalman �ltering! Makes it
much easier to understand! Thanks a lot for your great work!

Selin
February 11, 2017 at 5:13 pm

Thank you for this clear explanation!!

feng liu
February 15, 2017 at 9:45 pm

This is an amazing introduction! I read it through and want to and need to read it against. But
cannot suppress the inner urge to thumb up!

Revathi
February 16, 2017 at 11:43 am

Hello!
I have acceleration measurements only.How do I estimate position and velocity?
What will be my measurement matrix?
Is it possible to construct such a �lter?

Yunfei
February 16, 2017 at 12:19 pm

63 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Your tutorial of KF is truely amazing. Every material related to KF now lead and redirect to this ar-
ticle (orginal popular one was Kalman Filter for dummies). Hope to see your EKF tutorial soon.
Thank you.

Jones
February 17, 2017 at 5:00 pm

Amazing post! Thank you! I guess you did not write the EKF tutorial, eventually?

Small question, if I may:


What if the sensors don’t update at the same rate? You want to update your state at the speed of
the fastest sensor, right? Do you “simply” reduce the rank of the H matrix for the sensors that
haven’t been updated since the last prediction?

�orian
February 23, 2017 at 6:57 am

Hey, nice article. I enjoyed reading it. One small correction though: the �gure which shows multi-
plication of two Gaussians should have the posterior be more “peaky” i.e. less variance than both
the likelihood and the prior. The blue curve should be more certain than the other two.

Müller
February 24, 2017 at 10:14 pm

Very well explained!! Thank you.


Could you pleaseeeee extend this to the Extended, Unscented and Square Root Kalman Filters as
well.

Alberto Bussini

64 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

February 26, 2017 at 12:07 pm

I’m currently studying mechatronics and robotics in my university and we just faced the Kalman
Filter. It was really di�cult for me to give a practical meaning to it, but after I read your article,
now everything is clear!
Really a great one, I loved it!

xibo zhang
February 28, 2017 at 6:22 am

perfect work, simple and elegant!

Bharti Kaushal
March 3, 2017 at 6:09 am

Thanks Tim, nice explanation on KF ..really very helpful..looking forward for EKF & UKF

eric
March 3, 2017 at 12:00 pm

Best Guide on KF ever !

65 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Omer korech
March 3, 2017 at 12:45 pm

That was fascinating


Thanks

d
March 7, 2017 at 10:32 pm

For the extended Kalman Filter:


‘The Extended Kalman Filter: An Interactive Tutorial for Non-Experts’
https://home.wlu.edu/~levys/kalman_tutorial/
(written to be understood by high-schoolers)

Niel
March 13, 2017 at 9:21 am

I had read an article about simultaneously using 2 same sensors in kalman �lter, do you think it
will work well if I just wanna measure only the direction using E-compass?? What are those inputs
then and the matrix H?

nhorro
March 26, 2017 at 2:22 pm

Thanks, great article!

Budwar
March 26, 2017 at 7:52 pm

66 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

This is great. Such a wonderful description. Can you point me towards somewhere that shows
the steps behind �nding the expected value and SD of P(x)P(y), with normalisation. I’m getting
stuck somewhere

tbabb Post author

March 26, 2017 at 7:58 pm

I don’t have a link on hand, but as mentioned above some have gotten confused by the distinc-
tion of taking pdf(X*Y) and pdf(X) * pdf(Y), with X and Y two independent random variables. It is
the latter in this context, as we are asking for the probability that X=x and Y=y, not the probability
of some third random variable taking on the value x*y.

Faruk Musta�c
March 31, 2017 at 4:04 pm

Really clear article. Wish there were more explanations like this one.

georgeri��
April 3, 2017 at 2:48 pm

great job! best explanation so far

Mandrake
April 3, 2017 at 10:28 pm

Absolutely brilliant exposition!!! Thank you for the fantastic job of presenting the KF in such a sim-
ple and intuitive way.

67 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

I could be totally wrong, but for the �gure under the section ‘Combining Gaussians’, shouldn’t the
blue curve be taller than the other two curves? The location of the resulting ‘mean’ will be be-
tween the earlier two ‘means’ but the variance would be lesser than the earlier two variances
causing the curve to get leaner and taller.

tbabb Post author

April 3, 2017 at 10:42 pm

Yes, the variance is smaller. The blue curve is drawn unnormalized to show that it is the
intersection of two statistical sets. I’ve added a note to clarify that, as I’ve had a few questions
about it. Thanks for your comment!

Mandrake
April 3, 2017 at 10:47 pm

That totally makes sense. Thanks for clarifying that bit.


And did I mention you are brilliant!!!? :-)

Anirudh
April 6, 2017 at 10:41 am

Great article, I read several other articles on Kalman �lter but could not understand it clearly.

However, one question still remains unanswered is how to estimate covariance matrix. It would
be great if you could share some simple practical methods for estimation of covariance matrix.

Haseena
April 9, 2017 at 12:25 pm

68 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Very Nice Explanation..


Thanks for your e�ort

abdulrahim ghzal
April 14, 2017 at 2:43 pm

thank you … it is a very helpful article


hope the best for you ^_^

Luca
April 19, 2017 at 4:50 pm

Very nice explanation and overall good job ! Thanks !

Sai Krishna Allani


April 21, 2017 at 6:54 pm

Nice explanation. I understood everything expect I didn’t get why you introduced matrix ‘H’. Can
you please explain it?

Thanks,
Krishna

Bharath Ballamudi
April 27, 2017 at 1:34 am

Perhaps, the sensor reading dimensions (possibly both scale and units) are not consistent with
what you are keeping track of and predict……….as the author had previously alluded to that these

69 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

sensor readings are might only ‘indirectly’ measure these variables of interest. Say, the sensors
are measuring acceleration and then you are leveraging these acceleration measurements to
compute the velocity (you are keeping track of) ; and same holds true with the other sensor.
Since, there is a possibility of non-linear relationship between the corresponding parameters it
warrants a di�erent co-variance matrix and the result is you see a totally di�erent distribution
with both mean and co-variance di�erent from the original distribution. So, essentially, you are
transforming one distribution to another consistent with your setting.

Hope this makes sense.

tbabb Post author

April 27, 2017 at 7:07 am

H puts sensor readings and the state vector into the same coordinate system, so that they can be
sensibly compared.

In the simplest case, H can be biases and gains that map the units of the state vector to the units
of the sensors. In a more complex case, some element of the state vector might a�ect multiple
sensor readings, or some sensor reading might be in�uenced by multiple state vector elements.
For example, a craft’s body axes will likely not be aligned with inertial coordinates, so each coordi-
nate of a craft’s interial-space acceleration vector could a�ect all three axes of a body-aligned ac-
celerometer.

70 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

imane
April 23, 2017 at 6:29 pm

Bonjour,
i need to implémet a banc of 4 observers (kalman �lter) with DOS( Dedicated observer), in order
to detect and isolate sensors faults
each observer is designed to estimate the 4 system outputs qu’une seule sortie par laquelle il est
piloté, les 3 autres sorties restantes ne sont pas bien estimées, alors que par dé�nition de la
structure DOS, chaque observateur piloté par une seule sortie et toutes les entrées du système
doit estimer les 4 sorties.
SVP veuillez m’indiquer comment faire pour résoudre ce problème et merci d’avance

Alexei Guriev
April 24, 2017 at 10:03 pm

How I can get Q and R? Can somebody show me exemple.

Nathaniel Groendyk
February 9, 2018 at 1:13 am

I can’t �gure this out either. Are Q and R vectors? Matrices? Great article! I can almost implement
one, but I just cant �gure out R & Q.

tbabb Post author

February 9, 2018 at 1:58 am

Q and R are covariances of noise, so they are matrices. Their values will depend on the process
and uncertainty that you are modeling.

In many cases the best you can do is measure them, by performing a repeatable process many

71 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

times, and recording a population of states and sensor readings. You can then compute the co-
variance of those datasets using the standard algorithm.

jay
April 27, 2017 at 4:40 pm

I’d like a cookbook demonstration.

ie say: simple sensor with arduino and reduced testcase or absolute minimal C code

tx ~:”

dunanshan
April 28, 2017 at 5:37 am

Excellent article on Kalman Filter.


Thank you very much.

But I still have a question, why use multiply to combine Gaussians?


Maybe it is too simple to verify.

Yw
May 4, 2017 at 10:17 am

Really COOL. I understand Kalman Filter now. Thanks very much!

Mihir D
May 5, 2017 at 11:20 am

72 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Amazing article! Explained very well in simple words!

Tom Riis
May 6, 2017 at 4:26 am

Thanks so much!

Oguzhan
May 17, 2017 at 11:55 am

I wanted to clarify something about equations 3 and 4. You give the following equation to �nd the
next state;

Xk=FkXk-1 (equation 3)

You then use the co-variance identity to get equation 4.

Cov(AX) = AEA^t

For Cov(X)= E, are you saying that Cov(X-1) = Pk-1?

Is this the reason why you get Pk=Fk*Pk-1*Fk^T? because Fk*Xk-1 is just Xk therefore you get Pk
rather than Pk-1? in equation 5 as F is the prediction matrix?

tbabb Post author

May 17, 2017 at 6:29 pm

F is the prediction matrix, and Pk−1 is the covariance of xk−1 .

73 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Rafa
May 18, 2017 at 10:01 am

I have not �nish to read the whole post yet, but I couldn’t resist saying I’m enjoying by �rst time
reading an explanation about the Kalman �lter. I felt I need to express you my most sincere con-
gratulations. I’ll add more comments about the post when I �nish reading this interesting piece of
art.

Pd. I’m sorry for my pretty horrible English :(

Rafa
May 19, 2017 at 2:02 pm

Ok. I have read the full article and, �nally, I have understood this �lter perfectly and I have ap-
plied it to my researches successfully. Thank you so much Tim!

Craig
May 20, 2017 at 6:54 pm

Super excellent demultiplexing of the Kalman Filter through color coding and diagrams!

74 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Eyal
May 22, 2017 at 7:55 am

Thank you very much for this lovely explanation.


Can you please explain:
1. How do we initialize the estimator ?
2. How does the assumption of noise correlation a�ects the equations ?
3. How can we see this system is linear (a simple explanation with an example like you did above
would be great!) ?

Brenton
May 25, 2017 at 12:27 pm

Fantastic article, really enjoyed the way you went through the process.

One question, will the Kalman �lter get more accurate as more variables are input into it? ie. if
you have 1 unknown variable and 3 known variables can you use the �lter with all 3 known vari-
ables to give a better prediction of the unknown variable and can you keep increasing the known
inputs as long as you have accurate measurements of the data.

Mostly thinking of applying this to IMUs, where I know they already use magnetometer readings
in the Kalman �lter to remove error/drift, but could you also use temperature/gyroscope/other
readings as well? Or do IMUs already do the this?

Zaid
June 14, 2017 at 6:57 pm

You are awesome

Richard C
June 20, 2017 at 9:05 am

75 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Thanks for this article, it was very useful. Here’s an observation / question:

The prediction matrix F is obviously dependent on the time step (delta t). It also appears the
external noise Q should depend on the time step in some way. e.g. if Q is constant, but you take
more steps by reducing delta t, the P matrix accumulates noise more quickly. It appears Q should
be made smaller to compensate for the smaller time step.

Do you know of a way to make Q something like the amount of noise per second, rather than per
step?

ajebulon
June 21, 2017 at 4:21 pm

Very well explained. I found many links about Kalman which contains terrifying equations and I
ended up closing every one of them. This article really explains well the basic of Kalman �lter.

Lycos
June 24, 2017 at 1:19 am

Great article!! Even though I already used Kalman �lter, I just used it. By this article, I can �nally
get knowledges of Kalman �lter.

Romain
June 28, 2017 at 7:10 pm

Hi, Great article and great images !

you should mention how to initialize the covariance matrices.

I implemented my own and I initialized Pk as P0=[1 0; 0 1]. Pk will then converge by itself.

76 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

I initialized Qk as Q0=[0 0; 0 varA], where varA is the variance of the accelerometer. varA is esti-
mated form the accelerometer measurement of the noise at rest.

Same for Rk, I set it as Rk=varSensor. The estimated variance of the sensor at rest.

ps. to get the variance of few measure points at rest, let’s call them xi={x1, x2, … xn}
�rst get the mean as: mean(x)=sum(xi)/n
then the variance is given as: var(x)=sum((xi-mean(x))^2)/n
see here (scroll down for discrete equally likely values): https://en.wikipedia.org/wiki/Variance

Cheers,
Romain

Nathaniel Groendyk
February 9, 2018 at 1:16 am

THANK YOU KIND SIR! :)

Aditya
July 5, 2017 at 8:15 pm

This is de�nitely one of the best explanations of KF I have seen! I am trying to explain KF/EKF in
my master thesis and I was wondering if I could use some of the images! They’re really awesome!

Cheers,
Aditya

Kenny
July 10, 2017 at 8:14 am

Hello! Equation 12 results in a scalar value….just one value as the result. But equation 14 involves

77 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

covariance matrices, and equation 14 also has a ‘reciprocal’ symbol. Could you please explain
whether equation 14 is feasible (correct)? That is, if we have covariance matrices, then it it even
feasible to have a reciprocal term such as (sigma0 + sigma1)^-1 ?

Kenny
July 10, 2017 at 10:59 pm

Hello. I’d like to add…… when I meant reciprocal term in equation 14, I’m talking about (sigma0 +
sigma1)^-1…. which appears to be 1/[sigma0 + sigma1]. But if sigma0 and sigma1 are matrices,
then does that fractional reciprocal expression even make sense? Just interested to �nd out how
that expression actually works, or how it is meant to be interpreted – in equation 14. Thanks.

John Doe
July 14, 2017 at 9:23 pm

Simply, Great Work!!


Thank you so much :)

yota
July 16, 2017 at 12:29 pm

Nice article, it is the �rst time I go this far with kalman �ltering (^_^;)

Would you mind to detail the content (and shape) of the Hk matrix, if the predict step have very
detailed examples, with real Bk and Fk matrices, I’m a bit lost on the update step.
What is Hk exactly, what if my mobile have two sensors for speed for example and one very noisy
for position…

Jay

78 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

July 17, 2017 at 1:41 pm

Wow..
FINALLY found THE article that clear things up!
Thanks for the awesome article!

Mohamed Belal
July 18, 2017 at 8:34 am

Very well explained, one of the best tutorials about KF so far, very easy to follow, you’ve perfectly
clari�ed everything, thank you so much :)

Kenny
July 28, 2017 at 6:32 am

Finally found out the answer to my question, where I asked about how equations (12) and (13)
convert to a matrix form of equation (14). The answer is …… it’s not a simple matter of taking (12)
and (13) to get (14). The theory for obtaining a “kalman gain MATRIX” K is much more involved
than just saying that (14) is the ‘matrix form’ of (12) and (13). So, if anybody here is confused
about how (12) and (13) converts to (14) and (14), I don’t blame you, because the theory for that is
not covered here.

This particular article, however….. is one of the best I’ve seen though. It is one that attempts to
explain most of the theory in a way that people can understand and relate to.

Kenny
July 28, 2017 at 6:34 am

Finally found out the answer to my question, where I asked about how equations (12) and (13)
convert to a matrix form of equation (14). The answer is …… it’s not a simple matter of taking (12)

79 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

and (13) to get (14). The theory for obtaining a “kalman gain MATRIX” K is much more involved
than just saying that (14) is the ‘matrix form’ of (12) and (13). So, if anybody here is confused
about how (12) and (13) converts to (14) and (15), I don’t blame you, because the theory for that is
not covered here.

This particular article, however….. is one of the best I’ve seen though. It is one that attempts to
explain most of the theory in a way that people can understand and relate to.

Yang Ding
July 30, 2017 at 3:32 pm

Thank you. :) Love your illustrations and explanations. Made things much more clear. Please
draw more robots. XD

Timo
August 5, 2017 at 7:45 am

I only understand basic math and a lot of this went way over my head. I’m making a simple two
wheel drive microcontroller based robot and it will have one of those dirt cheap 6-axis gyro/ac-
celerometers. Was looking for a way to extract some sense and a way to combine this sensor
data into meaningful data that can be used to steer the robot. There’re a lot of uncertainties and
noise in such system and I knew someone somewhere had cracked the nut. Now I know at least
some theory behind it and I’ll feel more con�dent using existing programming libraries that
Implement these principles.

Even though I don’t understand all in this beautiful detailed explanation, I can see that it’s one of
the most comprehensive. I appreciate your time and huge e�ort put into the subject.
Bookmarked and looking forward to return to reread as many times as it takes to understand it
piece by piece.

Pu Huang
August 15, 2017 at 8:26 am

80 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Great blog!! Thanks to your nice work!


By the way, can I translate this blog into Chinese? Of course, I will put this original URL in my
translated post. :)

Arthur
August 20, 2017 at 8:08 pm

Thank you! this clari�ed my question abou the state transition matrix. Most people may be satis-
�ed with this explanation but I am not.
I am still curious about examples of control matrices and control vectors – the explanation of
which you were kind enough to gloss over in this introductory exposition.
I have a lot of other questions and any help would be appreciated!
I have a strong background in stats and engineering math and I have implemented K Filters and
Ext K Filters and others as calculators and algorithms without a deep understanding of how they
work. I would like to get a better understanding please with any help you can provide. Thank you!

Akhil Tiwari
August 22, 2017 at 10:49 am

what if we don’t have the initial velocity.


yes i can use the coordinates ( from sensor/LiDAR ) of �rst two frame to �nd the velocity but that
is again NOT completely reliable source

what should i do???

apeksha vr
August 23, 2017 at 10:43 am

I did not understand what exactly is H matrix. Can you explain the di�erence between H,R,Z?

81 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

adeeb
September 7, 2017 at 8:59 pm

i am doing my �nal year project on designing this estimator, and for starters, this is a good note
and report ideal for seminar and self evaluating,. thanks admin for posting this gold knowledge.
made easy for testing and understanding in a simple analogy. with great graphs and picture con-
tent. couldnt thank less. peace.

Jiang
September 13, 2017 at 12:33 am

This is so helpful!!!

Kenny
September 27, 2017 at 7:43 pm

A big question here is …. in equation (6), why is the projection (ie. xk) calculated from the state
matrix Fk (instead of F_k-1 ? Similarly? Why Bk and uk?
If we’re trying to get xk, then shouldn’t xk be computed with F_k-1, B_k-1 and u_k-1? It is because,
when we’re beginning at an initial time of k-1, and if we have x_k-1, then we should be using in-
formation available to use for projecting ahead…. which means F_k-1, B_k-1 and u_k-1, right? Not
F_k, B_k and u_k.

tbabb Post author

September 28, 2017 at 10:47 pm

Fk is de�ned to be the matrix that transitions the state from xk−1 to xk . We could label it Fk−1
and it would make no di�erence, so long as it carried the same meaning.

Similarly Bk is the matrix that adjusts the �nal system state at time k based on the control in-

82 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

puts that happened over the time interval between k − 1 and k . We could label it however we
please; the important point is that our new state vector contains the correctly-predicted state for
time k .

We also don’t make any requirements about the “order” of the approximation; we could assume
constant forces or linear forces, or something more advanced. The only requirement is that the
adjustment be represented as a matrix function of the control vector.

Kenny
September 29, 2017 at 3:45 am

Hi tbabb! Thanks for your kind reply. And thanks very much for explaining. I was only coming
from the discrete time state space pattern:
x[k+1] = Ax[k] + Bu[k]. I assumed that A is Ak, and B is Bk.
Then, when re-arranging the above, we get:
x[k] = Ax[k-1] + Bu[k-1]. I assumed here that A is A_k-1 and B is B_k-1. This suggests order is im-
portant. But, on the other hand, as long as everything is de�ned …. then that’s ok. Thanks again!
Nice site, and nice work.

Bhaskar
October 8, 2017 at 4:39 pm

The article was really great. It helped me understand KF much better. But I still have a doubt
about how you visualize senor reading after eq 8. There are two visualizations, one in pink color
and next one in green color. Can you explain the relation/di�erence between the two ?
Thanks in advance.

83 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Gore Shilpa
October 11, 2017 at 5:56 am

Needless to say, concept has been articulated well and serves it purpose really well!

om
October 13, 2017 at 10:24 pm

I could get how matrix Rk got introduced suudenly

(μ1,Σ1)=(zk→,Rk) .
I think I need read it again,
Explanation of Kalman Gain is superb.
Thanks a lot

PG
October 25, 2017 at 4:23 pm

The explanation is great but I would like to point out one source of confusion which threw me o�.
P_k should be the co-variance of the actual state and the truth and not co-variance of the actual
state x_k. This will make more sense when you try deriving (5) with a forcing function.

Mohan
October 27, 2017 at 1:17 am

Superb ! Very simply and nicely put. Thanks a lot !!

Paige

84 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

October 31, 2017 at 11:18 pm

This is, by far, the best tutorial on Kalman �lters I’ve found. You provided the perfect balance be-
tween intuition and rigorous math. Thank you :)

Scott
November 2, 2017 at 4:24 pm

Hello, thank you for this great article. I followed it and would like to code something up but I am
stopped at the computation of the Covariance matrix. I understand that each summation is inte-
gration of one of these: (x*x)* Gaussian, (x*v)*Gaussian, or (v*v)*Gaussian . I can use integration
by parts to get down to integration of the Gaussian but then I run into the fact that it seems to be
an integral that wants to result in the Error function, but the bounds don’t match. It only works if
bounds are 0 to inf, not –inf to inf. So I am unable to integrate to form the Covariance matrix.
Could you please point me in the right direction. Thanks!

Beiming
November 19, 2017 at 2:16 pm

Now i understood, you are great!

Yadviga
November 27, 2017 at 10:16 am

Great Job!!! Really the best explonation of Kalman Filter ever! Now my world is clear xD Is really
not so scary as it’s shown on Wiki or other sources! Thank You very much!

Angelia

85 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

November 30, 2017 at 3:02 am

hi, i would like to ask if it possible to add the uncertainty in term of magnetometer, gyroscope
and accelerometer into the kalman �lter?

Rob Snell
December 4, 2017 at 4:32 pm

Wow, fantastic article.

Srinivas
December 12, 2017 at 11:07 am

Very neat! Thanks for this article.

Michael Breuker
December 19, 2017 at 7:29 am

Excellent article and very clear explanations. I love your graphics. Thank you very much.
I really would like to read a follow-up about Unscented KF or Extended KF from you.

Alex
December 21, 2017 at 12:43 pm

Thanks for this article. Super! Simple and clear!

86 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

odyxanthi
December 27, 2017 at 11:22 pm

Thanks for your article, you ‘ve done a great job mixing the intuitive explanation with the mathe-
matical formality. Now I can �nally understand what each element in the equation represents.

xuesen
December 31, 2017 at 4:36 am

In “Combining Gaussians” section, why is the multiplication of two normal distributions also a
normal distribution. This doesn’t seems right if the two normal distributions are not independent.

giatorta
January 18, 2018 at 1:57 pm

really great post: easy to understand but mathematically precise and correct. Thank you!

Ananthapadmanabha
January 26, 2018 at 6:52 am

Very great explaination and really very intuitive. excited to see your other posts from now on.

87 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Josephine
January 27, 2018 at 3:39 pm

Informative Article.. It will be great if you provide the exact size it occupies on RAM,e�ciency in
percentage, execution of algorithm

El Barcho
January 29, 2018 at 1:52 am

so great article, I have question about equation (11) and (12). could you explain it or another
source that i can read?

Xinrui Wang
January 30, 2018 at 11:49 pm

Fantastic! Thanks for your explanation!

robert
February 2, 2018 at 2:32 pm

” (being careful to renormalize, so that the total probability is 1) ”


Can someone be kind enough to explain that part to me ? How do you normalize a Gaussian dis-
tribution ? Sorry for the newby question, trying to undertand the math a bit.

Thanks in advance

Joseph Cluever
February 14, 2018 at 6:17 pm

88 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

The integral of a distribution over it’s domain has to be 1 by de�nition. Also, I don’t know if that
comment in the blog is really necessary because if you have the covariance matrix of a multivari-
ate normal, the normalizing constant is known: det(2*pi*(Covariance Matrix))^(-1/2). There’s
nothing to really be careful about. See https://en.wikipedia.org/wiki/Multivariate_normal_distribu-
tion

Nathaniel Groendyk
February 9, 2018 at 1:50 am

Amazing article! Very impressed! You must have spent some time on it, thank you for this!

I had one quick question about Matrix H. Can it be extended to have more sensors and states?
For example say we had 3 sensors, and the same 2 states, would the H matrix look like this:
H = [ [Sensor1-to-State 1(vel) conversion Eq , Sensor1-to-State 2(pos) conversion Eq ] ;
[Sensor2-to-State 1(vel) conversion Eq , Sensor2-to-State 2(pos) conversion Eq ] ;
[Sensor3-to-State 1(vel) conversion Eq , Sensor3-to-State 2(pos) conversion Eq ] ]

Thank you!

Sasanka Kuruppuarachchi
February 21, 2018 at 5:44 am

Simply love it.

89 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

hamza
February 23, 2018 at 9:54 am

Hey Author,
Good work. Can you elaborate how equation 4 and equation 3 are combined to give updated co-
variance matrix?

tbabb Post author

February 23, 2018 at 7:51 pm

Fk is a matrix applied to a random vector xk−1 with covariance Pk−1 . Equation (4) says what we
do to the covariance of a random vector when we multiply it by a matrix.

Ankit Swarnkar
February 27, 2018 at 9:22 pm

Simply Awesome!

Sangyun Han
March 6, 2018 at 1:35 am

This article is the best one about Kalman �lter ever. Thanks for your help.

But I have a question about how to do knock o� Hk in equation (16), (17).


Because usual case Hk is not invertible matrix, so i think knocking o� Hk is not possible.
Can you explain?

Dasarath S

90 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

March 7, 2018 at 1:19 pm

Mind Blown !! The fact that you perfectly described the reationship between math and real world
is really good. Thnaks a lot!!

P P BANERJEE
March 10, 2018 at 7:42 pm

Can this method be used accurately to predict the future position if the movement is random like
Brownian motion.

tbabb Post author

March 12, 2018 at 6:02 pm

If you have sensors or measurements providing some current information about the position of
your system, then sure.

In the case of Brownian motion, your prediction step would leave the position estimate alone,
and simply widen the covariance estimate with time by adding a constant Qk representing the
rate of di�usion. Your measurement update step would then tell you to where the system had
advanced.

Lorenzo
March 13, 2018 at 10:24 am

It is an amazing article, thank you so much for that!!!!!

salma rv

91 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

March 17, 2018 at 6:28 am

Is the method useful for biological samples variations from region to region

João Escusa
March 21, 2018 at 12:05 pm

Hello.

I’m trying to implement a Kalman �lter for my thesis ut I’ve never heard of it and have some
questions.
I save the GPS data of latitude, longitude, altitude and speed. So my position is not a variable, so
to speak, it’s a state made of 4 variables if one includes the speed. Data is acquired every second,
so whenever I do a test I end up with a large vector with all the information.

How does one calculate the covariance and the mean in this case? Probabilities have never been
my strong suit.

Thanks.

tbabb Post author

March 22, 2018 at 2:17 am

Take many measurements with your GPS in circumstances where you know the “true” answer.
This will produce a bunch of state vectors, as you describe. Find the di�erence of these vectors
from the “true” answer to get a bunch of vectors which represent the typical noise of your GPS
system. Then calculate the sample covariance on that set of vectors. That will give you Rk , the
sensor noise covariance.

You can estimate Qk , the process covariance, using an analogous process.

Note that to meaningfully improve your GPS estimate, you need some “external” information, like
control inputs, knowledge of the process which is moving your vehicle, or data from other, sepa-

92 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

rate inertial sensors. Running Kalman on only data from a single GPS sensor probably won’t do
much, as the GPS chip likely uses Kalman internally anyway, and you wouldn’t be adding any-
thing!

Yar Zar
April 28, 2018 at 7:50 am

Well explanation! Thank you so much!

Vladimir
May 7, 2018 at 8:19 pm

Many thanks!
I’ve never seen such a clear and passionate explanation.

Di
May 17, 2018 at 3:38 am

Excellent explanation. Thank you!

P
February 23, 2019 at 3:43 pm

Great tutorial! Thanks! :D

Grant

93 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

March 14, 2019 at 11:16 pm

FANTASTIC explanation! Just EPIC:-)

Steve
March 20, 2019 at 9:50 am

Agree with Grant, this is a fantastic explanation, please do your piece on extended KF’s – non lin-
ear systems is what I’m looking at!!

modar
March 25, 2019 at 4:35 pm

Perfect ,easy and insightful explanation; thanks a lot.

Eranga De Silva
April 3, 2019 at 3:35 am

Thank you VERY much for this nice and clear explanation

Will
April 27, 2019 at 2:28 am

That was an amazing post! Thank you so much for the wonderful explanation!

As a side note, the link in the �nal reference is no longer up-to-date. Now it seems this is the cor-
rect link: https://drive.google.com/�le/d/1nVtDUrfcBN9zwKlGuAclK-F8Gnf2M_to/view

94 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Once again, congratz on the amazing post!

cle323
May 16, 2019 at 4:41 am

THANK YOU !!

After spending 3 days on internet, I was lost and confused. Your explanation is very clear ! Nice
job

Richard
May 26, 2019 at 4:59 pm

This was very clear until I got to equation 5 where you introduce P without saying what is it and
how its prediction equation relates to multiplying everything in a covariance matrix by A.

Richard
May 26, 2019 at 5:06 pm

Sorry, ignore previous comment. I’ve traced back and found it.

孙凯道
May 30, 2019 at 10:22 am

THANK YOU
Such a meticulous post gave me a lot of help.

95 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Monty
June 15, 2019 at 2:44 am

So it seems it’s interpolating state from prediction and state from measurement. H x_meas = z.
Doesn’t seem like x_meas is unique.

Maxim
July 16, 2019 at 12:34 pm

Thanks for the post.


I still have few questions.

1. At eq. (5) you put evolution as a motion without acceleration. At eq. 5 you add acceleration and
put it as some external force. But it is not clear why you separate acceleration, as it is also a part
of kinematic equation. So, the question is what is F and what is B. Can/should I put acceleration in
F?

2. At eq. 7 you update P with F, but not with B, despite the x is updated with both F & B. Why?

96 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

tbabb Post author

July 16, 2019 at 5:32 pm

1. The state of the system (in this example) contains only position and velocity, which tells us
nothing about acceleration. F is a matrix that acts on the state, so everything it tells us must be a
function of the state alone. If our system state had something that a�ected acceleration (for ex-
ample, maybe we are tracking a model rocket, and we want to include the thrust of the engine in
our state estimate), then F could both account for and change the acceleration in the update
step. Otherwise, things that do not depend on the state x go in B.

2. P represents the covariance of our state— how the possibilities are balanced around the
mean. B a�ects the mean, but it does not a�ect the balance of states around the mean, so it does
not matter in the calculation of P. This is because B does not depend on the state, so adding B is
like adding a constant, which does not distort the shape of the distribution of states we are track-
ing.

Abdul Basit
July 17, 2019 at 12:25 am

Great intuition, I am bit confuse how Kalman �lter works. But this blog clear my mind and I am
able to understand Computer Vision Tracking algorithms.

Monty
August 22, 2019 at 8:16 am

My issue is with you plucking H’s o� of this:


H x’ = H x + H K (z – H x)
x’ = x + K (z – H x) <- we know this is true from a more rigorous derivation

H isn't generally invertible. For sure you can go the other way by adding H back in. However, I do
like this explaination.

97 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

Abdelrhman
September 20, 2019 at 4:17 pm

Thanks alot for this, it’s really the best explanation i’ve seen for the Kalman �lter. visualization
with the idea of merging gaussians for the correction/update step and to �nd out where the
kalman gain “K” came from is very informative.

Kimon
September 23, 2019 at 9:45 pm

Is there a way to combine sensor measurements where each of the sensors has a di�erent la-
tency? How does one handle that type of situation?

David Sorcman
October 16, 2019 at 7:56 am

This is the best explanation of KF that I have ever seen, even after graduate school.

Just a warning though – in Equation 10, the “==?” should be “not equals” – the product of two
Gaussians is not a Gaussian. See http://mathworld.wolfram.com/NormalProductDistribution.html
for the actual distribution, which involves the Ksub0 Bessel function. The expressions for the vari-
ance are correct, but not the implication about the pdf.

Also, since position has 3 components (one each along the x, y, and z axes), and ditto for velocity,
the actual pdf becomes even more complicated. See the above link for the pdf for details in the 3
variable case.

tbabb Post author

November 1, 2019 at 12:00 am

98 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

See my other replies above: The product of two Gaussian PDFs is indeed a Gaussian. The PDF of
the product of two Gaussian-distributed variables is the distribution you linked. For this applica-
tion we need the former; the probability that two random independent events are simultane-
ously true.

Arye
November 12, 2019 at 8:23 am

Great Article!
I have some questions: Where do I get the Qk and Rk from? Do I model them? How do I update
them?
Thanks!

Mariana Jimenez
November 18, 2019 at 6:15 pm

Thank you very much ! Great article


I’ve been struggling a lot to understand the KF and this has given me a much better idea of how it
works.

Ryder
November 21, 2019 at 6:15 pm

There’s a few things that are contradiction to what this paper https://arxiv.org/abs/1710.04055
says about Kalman �ltering:

“The Kalman �lter assumes that both variables (postion and velocity, in our case) are random and
Gaussian distributed”
– Kalman �lter only assumes that both variables are uncorrelated (which is a weaker assumption
that independent). Kalman �lters can be used with variables that have other distributions besides
the normal distribution

99 of 100 28/03/20, 3:49 pm


How a Kalman filter works, in pictures | Bzarg https://www.bzarg.com/p/how-a-kalman-filter-w...

“In the above picture, position and velocity are uncorrelated, which means that the state of one
variable tells you nothing about what the other might be.”
– I think this a better description of what independence means that uncorrelated. Again, check
out p. 13 of the Appendix of the reference paper by Y Pei et Al.

Dmitry
November 22, 2019 at 2:05 am

Great article, �nally I got understanding of the Kalman �lter and how it works.

Vlad
February 14, 2020 at 12:49 am

This was such a great article. Really good job!

Nishant Jain
February 21, 2020 at 8:30 pm

How do we get Qk and Hk matrices?

Yiding Yang
March 4, 2020 at 9:06 am

This is an amazing tutorial. Thanks!

100 of 100 28/03/20, 3:49 pm

You might also like