• alex_be 2 days ago

    Author here.

    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.

    • magicalhippo 2 days ago

      I just glossed through for now so might have missed it, but it seemed you pulled the process noise matrix Q out of a hat. I guess it's explained properly in the book but would be nice with some justification for why the entries are what they are.

      • alex_be 2 days ago

        To keep the example focused and reasonably short, I treated Q matrix as given and concentrated on building intuition around prediction and update. But you're right that this can feel like it appears out of nowhere.

        The derivation of the Q matrix is a separate topic and requires additional assumptions about the motion model and noise characteristics, which would have made the example significantly longer. I cover this topic in detail in the book.

        I'll consider adding a brief explanation or reference to make that step clearer. Thanks for pointing this out.

        • magicalhippo 2 days ago

          Yeah I understand. I do think a brief explanation would help a lot though. As it sits it's not even entirely clear if the presented matrix is general or highly specific. I can easily see someone just use that as their Q matrix because that's what the Q matrix is, says so right there.

      • ted_dunning 19 hours ago

        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.

        • alex_be 18 hours ago

          Thanks a lot for this comment, Ted! This probably deserves its own example, not just a brief mention. I will definitely do that.

        • seanhunter 2 days ago

          Firstly I think the clarity in general is good. The one piece I think you could do with explaining early on is which pieces of what you are describing are the model of the system and which pieces are the Kalman filter. I was following along as you built the markov model of the state matrix etc and then you called those equations the Kalman filter, but I didn't think we had built a Kalman filter yet.

          Your early explanation of the filter (as a method for estimating the state of a system under uncertainty) was great but (unless I missed it) when you introduced the equations I wasn't clear that was the filter. I hope that makes sense.

          • alex_be 2 days ago

            You’re pointing out a real conceptual issue: where the system model ends and where the Kalman filter begins.

            In Kalman filter theory there are two different components:

            - The system model

            - The Kalman filter (the algorithm)

            The state transition and measurement equations belong to the system model. They describe the physics of the system and can vary from one application to another.

            The Kalman filter is the algorithm that uses this model to estimate the current state and predict the future state.

            I'll consider making that distinction more explicit when introducing the equations. Thanks for pointing this out.

          • ediamondscience a day ago

            I read and enjoyed your book a few months ago when a friend recommened it to me. I've been interested in control theory for a few years, but I'm still definitely a beginner when it comes to designing good control systems and have never done it professionally.

            I've been in the process of writing a tutorial on how PID filters work for a much younger audience. As a result, I've been looking back at the original tutorials that made stuff click for me. I had several engineers try to explain PID control to me over the course of about a year, but I don't think I really got it until I ended up watching Terry Davis (yeah, the TempleOS guy) show off how to use PID control in SimStructure using a hovering rocket as an example.

            The way he built the concept up was to take each component and build on the control system until he had something that worked. He started off with a simple proportional controller that ended up having a steady state error with the rocket hovering beneath the target height. Once he had that and pointed out the steady state error, he implemented the integral term showed off how it resulted in overshoot. Once that was working, he implemented the derivative control to back the overshoot off until he had something that settled pretty quickly.

            I'm not sure how you could do something similar for a Kalman Filter, but I did find it genuinely constructive to see the thought process behind adding each component of the equation.

            • forsakenharmony 2 hours ago

              I personally found this video on PID really good

              https://youtu.be/Y3MgFS-9l3s

              • alex_be a day ago

                Yeah. Building things step by step often makes complex topics much easier to understand.

              • alpinisme a day ago

                Tangent but I love the accessibility menu you have. Made it super easy to tweak the page to be more readable for me

              • renjimen 2 days ago

                You lead with "Moreover, it is an optimal algorithm that minimizes state estimation uncertainty." By the end of the tutorial I understood what this meant, but "optimal algorithm" is a vague term I am unfamiliar with (despite using Kalman Filters in my work). It might help to expand on the term briefly before diving into the math, since IIUC it's the key characteristic of the method.

                • alex_be 2 days ago

                  That's a good point. "Optimal" in this context means that, under the standard assumptions (linear system, Gaussian noise, correct model), the Kalman Filter minimizes the estimation error covariance. In other words, it provides the minimum-variance estimate among all linear unbiased estimators.

                  You're right that the term can feel vague without that context. I’ll consider adding a short clarification earlier in the introduction to make this clearer before diving into the math. Thanks for the suggestion.

                • RickHull a day ago

                  I recently (~6 mo ago) made it a goal to understand and implement a useful Kalman filter, but I realized that they are very tightly coupled to their domain and application. I got about half as far as I wanted, and took a pause. I expect your work here will get me to the finish line, so I am psyched! Thank you!

                  • alex_be a day ago

                    Thanks for your feedback! Actually the KF concept is generic, but as mentioned above: "The state transition and measurement equations belong to the system model. They describe the physics of the system and can vary from one application to another."

                    So it is right to say that the implementation of the KF is tightly coupled to the system. Getting that part right is usually the hardest step.

                  • KellyCriterion 2 days ago

                    You could do a line extension of your product, like "Kalman Filter in Financial Markets" and sell additional copies :)

                    • alex_be 2 days ago

                      That's an interesting idea. The Kalman filter is definitely used in finance, often together with time-series models like ARMA. I've been thinking about writing something, although it's a bit outside my usual engineering focus.

                      The challenge would be to keep it intuitive and accessible without oversimplifying. Still, it could be an interesting direction to explore.

                  • roger_ 2 days ago

                    Here's my (hopefully) intuitive guide:

                    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).

                    • palata 2 days ago
                      • ActorNightly 2 days ago

                        I feel like people overcomplicate even the "simple" explanations like the OPs and this one.

                        Basically, a Kalman filter is part of a larger class of "estimators", which take the input data, and run additional processing on top of it to figure out the true measurement.

                        The very basic estimator a low pass filter is also an "estimator" - it rejects high frequency noise, and gives you essentially a moving average. But is a static filter that assumes that your process has noise of a certain frequency, and anything below that is actual changes in the measured variable.

                        You can make the estimator better. Say you have some idea of how the process variable should behave.For a very simple case, say you are measuring temperature, and you have a current measurement, and you know that change in temperature is related to current being put through a winding. You can capture that relationship in a model of the process, which runs along side the measurement of the actual temperature. Now you have the noisy temperature reading, the predicted reading (which acts like a mean), and you can compute the covariance of the noise, which then you can use to tune the parameter of low pass filter. So if your noise changes in frequency for some reason, the filter will adjust and take care of it.

                        The Kalman filter is an enhanced version of above, with the added feature of capturing correlation between process variables and using the measurement to update variables that are not directly measurement. For example, if position and velocity are correlated, a refined measurement on the position from gps, will also correct a refined measurement on velocity even if you are not measuring velocity (since you are computing velocity based of an internal model)

                        The reason it can be kind of confusing is because it basically operates in the matrix linear space, by design to work with other tools that let you do further analysis. So with restriction to linear algebra, you have to assume gaussian noise profile, and estimate process dependence as a covariance measure.

                        But Kalman filter isnt the end/all be all for noise rejection. You can do any sort of estimation in non linear ways. For example, I designed an automated braking system for an aircraft that tracks a certain brake force command, by commanding a servo to basically press on a brake pedal. Instead of a Kalman filter, I basically ran tests on the system and got a 4d map of (position, pressure, servo_velocity)-> new_pressure, which then I inverted to get the required velocity for target new pressure. So the process estimation was basically commanding the servo to move at a certain speed, getting the pressure, then using position, existing pressure, and pressure error to compute a new velocity, and so on.

                        • alex_be a day ago

                          Interesting. It sounds like you ended up with a data-driven estimator. Did you have a chance to compare the data-driven and model-based approaches?

                          • quibono 2 days ago

                            How does braking work in an aircraft?

                            • kortilla a day ago

                              When it lands. Auto brakes apply to the wheels to target a specific deceleration target. You don’t want to brake too hard and cause undue wear and you don’t want to under brake and miss your taxiway or go off the runway.

                              • quibono a day ago

                                Gosh I should have thought of auto-braking. For some reason I kept thinking this was some fancy drone-braking system and couldn't figure out how you'd brake in the air... I never even considered the on-the-ground case. Thanks.

                            • RickHull a day ago

                              Very interesting perspective. I will be reviewing in depth. Much appreciated.

                          • raluk a day ago

                            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.

                            • alex_be a day ago

                              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.

                            • joshu 2 days ago

                              i liked how https://www.bzarg.com/p/how-a-kalman-filter-works-in-picture... uses color visualization to explain

                              • alex_be 2 days ago

                                That's a good article. I also like the visual approach there. My goal here was a bit different. I walk through a concrete radar example step by step, and use multiple examples throughout the tutorial to build intuition and highlight common pitfalls.

                              • eps a day ago

                                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.

                                • alex_be a day ago

                                  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.

                                  • imtringued a day ago

                                    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.

                                  • bsoles 14 hours ago

                                    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.

                                    • nightsd01 14 hours ago

                                      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

                                      • Miniminix 12 hours ago

                                        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.

                                        • alex_be 3 hours ago

                                          Thanks a lot for your detailed and valuable comments. I will definitely include them in the tutorial. If you have additional comments, I would be happy to hear them.

                                        • balloob a day ago

                                          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.

                                          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...

                                          • Miniminix 12 hours ago

                                            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.

                                            • smokel 2 days ago

                                              This seems to be an ad for a fairly expensive book on a topic that is described in detail in many (free) resources.

                                              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?

                                              • alex_be 2 days ago

                                                That's a fair question. My goal with the site was to make as much material available for free as possible, and the core linear Kalman filter content is indeed freely accessible.

                                                The book goes further into topics like tuning, practical design considerations, common pitfalls, and additional examples. But there are definitely many good free resources out there, including the one you linked.

                                                • cwood-sdf 2 days ago

                                                  i haven't seen much from other kalman filter resources, but i can say that this book is incredibly detailed and i would highly recommend it

                                                  if you dont want to buy the book, most of the linear kalman filter stuff is available for free: https://kalmanfilter.net/kalman-filter-tutorial.html

                                                  • cameldrv 2 days ago

                                                    Huge +1 for Roger Labbe's book/jupyter notebooks. They really helped me grok Kalman filters but also the more general problem and the various approaches that approximate the general problem from different directions.

                                                    • bmitc 2 days ago

                                                      There are not many good resources on Kalman filters. In fact, I have found a single one that I'd consider good. This is someone who has spent a lot of time to newly understand Kalman filters.

                                                      • memming 2 days ago

                                                        Link to that good one?

                                                        • bmitc 2 days ago

                                                          It was a typo. I meant to say I haven't found a good one yet.

                                                      • the__alchemist 2 days ago

                                                        That link is a classic!

                                                      • anamax a day ago
                                                        • lelandbatey 2 days ago

                                                          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.

                                                          • alex_be 2 days ago

                                                            I agree that Kalman filters are not magic and that having a reasonable model is essential for good performance.

                                                            Higher sampling rates can help in some cases, especially when tracking fast dynamics or reducing measurement noise through repeated updates. However, the main strength of the Kalman filter is combining a model with noisy measurements, not necessarily relying on high sampling rates.

                                                            In practice, Kalman filters can work well even with relatively low-rate measurements, as long as the model captures the system dynamics reasonably well.

                                                            I also agree that it's often something you design into the system rather than applying as a post-processing step.

                                                            • ActorNightly 2 days ago

                                                              Thats just a consequence of sample rate as a whole. The entire linear control space is intricately tied to frequency domain, so you have to sample at a rate at least twice higher than your highest frequency event for accurate capture, as per Nyquist theorem.

                                                              All of that stuff is used in industry because a lot of regulation (for things like aircraft) basically requires your control laws to be linear so that you can prove stability.

                                                              In reality, when you get into non linear control, you can do a lot more stuff. I did a research project in college where we had an autonomous underwater glider that could only get gps lock when it surfaced, and had to rely on shitty MEMS imu control under water. I actually proposed doing a neural network for control, but it got shot down because "neural nets are black boxes" lol.

                                                              • pjbk a day ago

                                                                True. I have often encountered motion controllers where the implementer failed to realize that calculating derived variables like acceleration from position and velocity using a direct derivative formula will violate the Nyquist condition, and therefore yields underperforming controllers or totally noisy signal inputs to them. You either need to adjust your sample or control loop rates, or run an appropriate estimator. Depending on the problem it can be something sophisticated like an LQR/KF, or even in some cases a simple alpha-beta-gamma filter (poor version of a predictor-corrector process) can be adequate.

                                                              • moffkalast 2 days ago

                                                                Yeah, I try to err on the side of not using them unless the accuracy obtained through more robust methods is just a no-go, because there are so many ways they can suddenly and irrecoverably fail if some sensor randomly produces something weird that wasn't accounted for. Which happens all the time in practice.

                                                                • alex_be 2 days ago

                                                                  It is always a good idea to include outliers treatment in KF algorithm to filter out weird measurements.

                                                                  • moffkalast 21 hours ago

                                                                    Ah but then you just move the error case to outlier detection.

                                                                    • alex_be 18 hours ago

                                                                      True. It's about managing the risk rather than eliminating it. If you remove an outlier, you get a missing measurement and, as a result, higher uncertainty (error). But it is still better than keeping the outlier.

                                                              • pmarreck a day ago

                                                                Could the Kalman Filter idea be applied to human witnesses to an event, where you model the person as a faulty sensor?

                                                                • alex_be a day ago

                                                                  Kalman filter is about combining uncertain measurements, and human observations could be viewed as noisy sensors. On the other hand, the standard KF assumes unbiased sensors with Gaussian noise, and I don't know if those assumptions hold for human witnesses.

                                                                  • pmarreck 13 hours ago

                                                                    That's an interesting wrinkle. How would you model the potential bias in order to neutralize it though? Or would enough measurements simply cancel out any bias (or be very likely to)?

                                                                • anilakar a day ago

                                                                  The missile knows...

                                                                  • alex_be a day ago

                                                                    Classic :)