I recently updated the homepage of my Kalman Filter tutorial with a new example based on a simple radar tracking problem. The goal was to make the Kalman Filter understandable to anyone with basic knowledge of statistics and linear algebra, without requiring advanced mathematics.
The example starts with a radar measuring the distance to a moving object and gradually builds intuition around noisy measurements, prediction using a motion model, and how the Kalman Filter combines both. I also tried to keep the math minimal while still showing where the equations come from.
I would really appreciate feedback on clarity. Which parts are intuitive? Which parts are confusing? Is the math level appropriate?
If you have used Kalman Filters in practice, I would also be interested to hear whether this explanation aligns with your intuition.
I think that this was a great intro into Kalman filtering.
The one important point that I think warrants a small paragraph near the end is that the example you gave is a way of doing forecasting (estimating the future state) and nowcasting (estimating the current state), but Kalman filters can also be used retrospectively to do retrocasting (using the present data to get a better estimate of the past).
Nowcasting and retrocasting are concepts that a lot of people have trouble with. That trouble is the crux of the Kalman filter ... combining (noisy) measurements with (noisy) dead reckoning gives us (better) knowledge. For complete symmetry, it is important to point out that we can't just use old measurements to describe the past any more than we should only use current and past measurements to define our estimate of the present.
Kalman filters are very cool, but when applying them you've got to know that they're not magic. I struggled to apply Kalman Filters for a toy project about ten years ago, because the thing I didn't internalize is that Kalman filters excel at offsetting low-quality data by sampling at a higher rate. You can "retroactively" apply a Kalman filter to a dataset and see some improvement, but you'll only get amazing results if you sample your very-noisy data at a much higher rate than if you were sampling at a "good enough" rate. The higher your sample rate, the better your results will be. In that way, a Kalman filter is something you want to design around, not a "fix all" for data you already have.
1. understand weighted least squares and how you can update an initial estimate (prior mean and variance) with a new measurement and its uncertainty (i.e. inverse variance weighted least squares)
2. this works because the true mean hasn't changed between measurements. What if it did?
3. KF uses a model of how the mean changes to predict what it should be now based on the past, including an inflation factor on the uncertainty since predictions aren't perfect
4. after the prediction, it becomes the same problem as (1) except you use the predicted values as the initial estimate
There are some details about the measurement matrix (when your measurement is a linear combination of the true value -- the state) and the Kalman gain, but these all come from the least squares formulation.
Least squares is the key and you can prove it's optimal under certain assumptions (e.g. Bayesian MMSE).
Spending few weeks trying to understand Kalman filterm, I figured out that I need to understand all if the following:
1. Model of system
2. Internal state
3. How is optimal estimation defined
4. Covariance (statistics)
Kalman filter is optimal estimation of internal state and covariance of system based on measurements so far.
Kalman process/filter is mathematical solution to this problem as the system is evolving based on input and observable measurements. Turns out that internal state that includes both estimated value and covariance is all that is needed to fully capture internal state for such model.
It is important to undrstand, that having different model for what is optimum, uncertenty or system model, compared to what Rudolf Kalman presented, gives just different mathematical solution for this problem. Examples of different optimal solutions for different estimation models are nonlinear Kalman filters and Wiener filter.
---
I think that book on this topic from author Alex Becker is great and possibly best introduction into this topic. It has lot of examples and builds requred intuition really well. All I was missing is little more emphasis into mathematical rigor and chapter about LQG regulator, but you can find both of this in original paper by Rudolf Kalman.
Thanks for your feedback. I am thinking of writing a second volume with more advanced and less introductory topics, but I haven't decided yet. It is a serious commitment and it will take years to complete.
If I take this decision, I will consider a chapter on LQG.
Small clarification: nonlinear Kalman filters are suboptimal. EKF relies on linear approximations, and UKF uses heuristic approximations.
When learning the Kalman filter, it clicks in place much faster when there are two or more inputs with different noise profiles. That's why it exists and that's what was its original use-case.
Yet virtually all tutorials stick to single-input examples, which is really an edge case. This site is no exception.
Kalman filters have always been about state estimation. What you consider an exception is the default in the vast majority of state estimation scenarios.
Before I got into control theory, I've read a lot of HN posts about kalman filters being the "sensor fusion" algorithm, which is the wrong mental model. You can do sensor fusion with state estimation, but you can't do state estimation with sensor fusion.
I have a chapter in my book that introduces sensor fusion as a concept. If you want to dive deeper into the sensor fusion topic, I would recommend Bar-Shalom's or Blackman's book.
Kalman filters are great! For people interested of one used in practice, it's used by Sendspin to keep speakers in sync, even works in browsers on phones on 5G etc.
I recently built a drone from the ground up - learned how to build PCB's with the ESP32, wrote all of the flight firmware, etc. and built a controller iOS app.
Extended Kalman Filters are even more interesting because they let you do sensor fusion and such
I never really understood Kalman filters, but there was a time I knew how to design non-optimal state (Luenberger?) observers, which are a lot easier to design and implement. I wonder if discussing those first would make things easier for the audience.
I have worked with Kalman Filters for years, and gave this quick read. I saw the comments on Process Noise, so I focus there for now. I might get back to other sections tomorrow.
My simple head space (as I was taught and re-learned thru experience, and have passed on)
1. Kalman Gain close to 1 or 0 is a warning sign that careful consideration is needed.
This fact can be brought up immediately in example #5 and continued
2a. K close to 1.0 can be bad because..., however for some applications (dynamic models) it can be acceptable since...
2b. K close to 0.0 can be bad because... however for some applications (dynamic models) it can be acceptable since...
3. To solve the problem from step 2, As a first step, for those applications where K close to zero or one is bad... a fudge factor term (called Q for reasons discussed later) can be added to the Kalman Gain computation
3a. Choosing the correct fudge factor for the application is often very difficult and may require lots of simulation runs (a parameter study) with different measurement sequences (including some expected off-nominals) and various values for the process noise.
Remember we are designing a filter, likely for a new application (or a non-trivial extension of an existing application)... so all the elements of an engineering design are needed. Make solution hypothesis, test them, refine them, test them some more with greater realism and eventually real-world data, continue to refine the solution.
4. For easy case of a simple application and only a few unknown states, the process noise can be guesstimated from experience. For more complex applications (perhaps there are dozens of unknown states to estimate) a more rigorous approach to select the correct mathematical description of Process Noise is needed.
-- End of Fudge Factor discussion --
5. Here you can introduce the notion that the state dynamics cannot model everything and that unmodeled part can be approximated by Process Noise. For example an unmodeled constant acceleration, gives dt^4
Here are some sentences I think are wrong or misleading
"As you can see, the Kalman Gain gradually decreases; therefore, the KF converges." However, the Kalman Filter may converge to garbage. This garbage could be a "lag", or just plain wrong.
"The process noise produces estimation errors."
A well chosen process noise is important to reduce estimation errors over an ensemble of conditions, by accommodating a range of unmodeled state dynamics. A poorly chosen process may not improve anything.
I have worked with Kalman Filters for years, and gave this quick read. I saw the comments on Process Noise, so I focus there for now. I might get back to other sections tomorrow.
My simple head space (as I was taught and re-learned thru experience, and have passed on)
1. Kalman Gain close to 1 or 0 is a warning sign that careful consideration is needed.
This fact can be brought up immediately in example #5 and continued
2a. K close to 1.0 can be bad because..., however for some applications (dynamic models) it can be acceptable since...
2b. K close to 0.0 can be bad because... however for some applications (dynamic models) it can be acceptable since...
3. To solve the problem from step 2, As a first step, for those applications where K close to zero or one is bad... a fudge factor term (called Q for reasons discussed later) can be added to the Kalman Gain computation
3a. Choosing the correct fudge factor for the application is often very difficult and may require lots of simulation runs (a parameter study) with different measurement sequences (including some expected off-nominals) and various values for the process noise.
Remember we are designing a filter, likely for a new application (or a non-trivial extension of an existing application)... so all the elements of an engineering design are needed. Make solution hypothesis, test them, refine them, test them some more with greater realism and eventually real-world data, continue to refine the solution.
4. For easy case of a simple application and only a few unknown states, the process noise can be guesstimated from experience. For more complex applications (perhaps there are dozens of unknown states to estimate) a more rigorous approach to select the correct mathematical description of Process Noise is needed.
-- End of Fudge Factor discussion --
{I think you covered this section well} Then you can introduce the notion that the state dynamics cannot model everything and that unmodeled part can be approximated by Process Noise. For example an unmodeled constant acceleration, gives a process noise of ....
Here are some sentences I think are wrong or misleading
"As you can see, the Kalman Gain gradually decreases; therefore, the KF converges." However, the Kalman Filter may converge to garbage. This garbage could be a "lag", or just plain wrong.
"The process noise produces estimation errors."
A well chosen process noise is important to reduce estimation errors over an ensemble of conditions, by accommodating a range of unmodeled state dynamics. A poorly chosen process may not improve anything.
23 comments
[ 4.5 ms ] story [ 54.3 ms ] threadI recently updated the homepage of my Kalman Filter tutorial with a new example based on a simple radar tracking problem. The goal was to make the Kalman Filter understandable to anyone with basic knowledge of statistics and linear algebra, without requiring advanced mathematics.
The example starts with a radar measuring the distance to a moving object and gradually builds intuition around noisy measurements, prediction using a motion model, and how the Kalman Filter combines both. I also tried to keep the math minimal while still showing where the equations come from.
I would really appreciate feedback on clarity. Which parts are intuitive? Which parts are confusing? Is the math level appropriate?
If you have used Kalman Filters in practice, I would also be interested to hear whether this explanation aligns with your intuition.
The one important point that I think warrants a small paragraph near the end is that the example you gave is a way of doing forecasting (estimating the future state) and nowcasting (estimating the current state), but Kalman filters can also be used retrospectively to do retrocasting (using the present data to get a better estimate of the past).
Nowcasting and retrocasting are concepts that a lot of people have trouble with. That trouble is the crux of the Kalman filter ... combining (noisy) measurements with (noisy) dead reckoning gives us (better) knowledge. For complete symmetry, it is important to point out that we can't just use old measurements to describe the past any more than we should only use current and past measurements to define our estimate of the present.
See for example: https://rlabbe.github.io/Kalman-and-Bayesian-Filters-in-Pyth...
Is there something in this particular resource that makes it worth buying?
1. understand weighted least squares and how you can update an initial estimate (prior mean and variance) with a new measurement and its uncertainty (i.e. inverse variance weighted least squares)
2. this works because the true mean hasn't changed between measurements. What if it did?
3. KF uses a model of how the mean changes to predict what it should be now based on the past, including an inflation factor on the uncertainty since predictions aren't perfect
4. after the prediction, it becomes the same problem as (1) except you use the predicted values as the initial estimate
There are some details about the measurement matrix (when your measurement is a linear combination of the true value -- the state) and the Kalman gain, but these all come from the least squares formulation.
Least squares is the key and you can prove it's optimal under certain assumptions (e.g. Bayesian MMSE).
1. Model of system
2. Internal state
3. How is optimal estimation defined
4. Covariance (statistics)
Kalman filter is optimal estimation of internal state and covariance of system based on measurements so far.
Kalman process/filter is mathematical solution to this problem as the system is evolving based on input and observable measurements. Turns out that internal state that includes both estimated value and covariance is all that is needed to fully capture internal state for such model.
It is important to undrstand, that having different model for what is optimum, uncertenty or system model, compared to what Rudolf Kalman presented, gives just different mathematical solution for this problem. Examples of different optimal solutions for different estimation models are nonlinear Kalman filters and Wiener filter.
---
I think that book on this topic from author Alex Becker is great and possibly best introduction into this topic. It has lot of examples and builds requred intuition really well. All I was missing is little more emphasis into mathematical rigor and chapter about LQG regulator, but you can find both of this in original paper by Rudolf Kalman.
Small clarification: nonlinear Kalman filters are suboptimal. EKF relies on linear approximations, and UKF uses heuristic approximations.
Yet virtually all tutorials stick to single-input examples, which is really an edge case. This site is no exception.
Before I got into control theory, I've read a lot of HN posts about kalman filters being the "sensor fusion" algorithm, which is the wrong mental model. You can do sensor fusion with state estimation, but you can't do state estimation with sensor fusion.
Open the Sendspin live demo in your browser: https://www.sendspin-audio.com/#live-demo
Some more info on Kalman implementation here https://github.com/Sendspin/time-filter/blob/main/docs%2Fthe...
Extended Kalman Filters are even more interesting because they let you do sensor fusion and such
My simple head space (as I was taught and re-learned thru experience, and have passed on)
1. Kalman Gain close to 1 or 0 is a warning sign that careful consideration is needed.
This fact can be brought up immediately in example #5 and continued
2a. K close to 1.0 can be bad because..., however for some applications (dynamic models) it can be acceptable since...
2b. K close to 0.0 can be bad because... however for some applications (dynamic models) it can be acceptable since...
3. To solve the problem from step 2, As a first step, for those applications where K close to zero or one is bad... a fudge factor term (called Q for reasons discussed later) can be added to the Kalman Gain computation
3a. Choosing the correct fudge factor for the application is often very difficult and may require lots of simulation runs (a parameter study) with different measurement sequences (including some expected off-nominals) and various values for the process noise.
Remember we are designing a filter, likely for a new application (or a non-trivial extension of an existing application)... so all the elements of an engineering design are needed. Make solution hypothesis, test them, refine them, test them some more with greater realism and eventually real-world data, continue to refine the solution.
4. For easy case of a simple application and only a few unknown states, the process noise can be guesstimated from experience. For more complex applications (perhaps there are dozens of unknown states to estimate) a more rigorous approach to select the correct mathematical description of Process Noise is needed.
-- End of Fudge Factor discussion --
5. Here you can introduce the notion that the state dynamics cannot model everything and that unmodeled part can be approximated by Process Noise. For example an unmodeled constant acceleration, gives dt^4
Here are some sentences I think are wrong or misleading
"As you can see, the Kalman Gain gradually decreases; therefore, the KF converges." However, the Kalman Filter may converge to garbage. This garbage could be a "lag", or just plain wrong.
"The process noise produces estimation errors." A well chosen process noise is important to reduce estimation errors over an ensemble of conditions, by accommodating a range of unmodeled state dynamics. A poorly chosen process may not improve anything.
My simple head space (as I was taught and re-learned thru experience, and have passed on)
1. Kalman Gain close to 1 or 0 is a warning sign that careful consideration is needed.
This fact can be brought up immediately in example #5 and continued
2a. K close to 1.0 can be bad because..., however for some applications (dynamic models) it can be acceptable since...
2b. K close to 0.0 can be bad because... however for some applications (dynamic models) it can be acceptable since...
3. To solve the problem from step 2, As a first step, for those applications where K close to zero or one is bad... a fudge factor term (called Q for reasons discussed later) can be added to the Kalman Gain computation
3a. Choosing the correct fudge factor for the application is often very difficult and may require lots of simulation runs (a parameter study) with different measurement sequences (including some expected off-nominals) and various values for the process noise.
Remember we are designing a filter, likely for a new application (or a non-trivial extension of an existing application)... so all the elements of an engineering design are needed. Make solution hypothesis, test them, refine them, test them some more with greater realism and eventually real-world data, continue to refine the solution.
4. For easy case of a simple application and only a few unknown states, the process noise can be guesstimated from experience. For more complex applications (perhaps there are dozens of unknown states to estimate) a more rigorous approach to select the correct mathematical description of Process Noise is needed.
-- End of Fudge Factor discussion --
{I think you covered this section well} Then you can introduce the notion that the state dynamics cannot model everything and that unmodeled part can be approximated by Process Noise. For example an unmodeled constant acceleration, gives a process noise of ....
Here are some sentences I think are wrong or misleading
"As you can see, the Kalman Gain gradually decreases; therefore, the KF converges." However, the Kalman Filter may converge to garbage. This garbage could be a "lag", or just plain wrong.
"The process noise produces estimation errors." A well chosen process noise is important to reduce estimation errors over an ensemble of conditions, by accommodating a range of unmodeled state dynamics. A poorly chosen process may not improve anything.