CallumJHays/elm-kalman-filter

Simple 1D Kalman filters


License
MIT
Install
elm-package install CallumJHays/elm-kalman-filter 2.0.0

Documentation

elm-kalman-filter

Simple 1D Kalman filters in Elm

kalman filter graph

Installation

elm package install CallumJHays/elm-kalman-filter

Example

-- `model.noise` contains 100 gaussian-random numbers generated by
-- elm-community/random-extra: `Random.Float.standardNormal`

xAxis =
    List.Range 0 1000

-- Apply a quadratic function
signal =
    xAxis |> List.map (\x -> 0.001 * (x - 10) ^ 2 - (x - 10))

noisySignal =
    signal |> List.map2 (+) model.noise

predictedSignal : List Float
predictedSignal =
    KalmanFilter.filter Nothing noisySignal

Getting Started

The filter functon is the easiest way to use a Kalman Filter:

predictedSignal : List Float
predictedSignal =
    KalmanFilter.filter Nothing noisySignal

However, it might not be the most appropriate for your use case. For example, if your application recieves rolling updates of a signal from an API server that you need filtered, it would be more appropriate to keep a copy of KalmanFilter.Model in your application Model, and to use it along with KalmanFilter.filterMeasurement to provide less noisy signals as they come in.

One great concrete use-case for usage with an API server is multiplayer video- games that require a mechanism for preventing Rubber-banding. The Kalman filter may be used without smoothing to observe the values being passed in (using filter with the Param.expectedNoisePower parameter set to 0). Backup values can then be provided in durations when the network lags using predictNext. Of course, this use-case would be far more relevant if this library was generalised to N-Dimensional data (2D, 3D) - but that's still a work in progress :)