Hacker News new | ask | show | jobs
by lelandbatey 69 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.
3 comments

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.

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

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.
It is always a good idea to include outliers treatment in KF algorithm to filter out weird measurements.
Ah but then you just move the error case to outlier detection.
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.