Kalman Filter
The Kalman Filter is often used to filter data where you expect some noise. It does so by looking at the previous data point and how certain we are about that data point to decide how much the current measurement should weigh in.
It was formalised by R.E Kalman in 1960 in his paper.
Or as Wikipedia explains it:
The Kalman Filter (…) is an algorithm that uses a series of measurements observed over time, containing statistical noise and other inaccuracies, and produces estimates of unknown variables that tend to be more accurate than those based on a single measurement alone…
A Good Explanation
If you are like me the math is not as intuitive as a verbal explanation. A good video on the subject is Lachlan Blackhall’s 2016 talk on the filter and an implementation in Python. I used his implementation as the foundation for my implementation in Elixir.
My Implementation
The algorithm as described in the original paper is recursive. Being a functional language, Elixir lends itself very well to solving problems recursively. So instead of using an agent or GenServer to store state I implemented the filter in a strictly functional manner.
The Result
I’ve barely tested the code, and it comes with no warranties. But if you can find some use for it, it’s licensed under the MIT license and can be found on my Gitlab.
It’s published as a Hex package and the documentation is available on hexdocs.pm.
All contributions and comments are welcome.
Enjoy!