Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/callumjhays/elm-kalman-filter

Simple 1D Kalman Filters in Elm
https://github.com/callumjhays/elm-kalman-filter

elm elm-lang kalman kalman-filter kalman-filtering signal-processing signals

Last synced: about 1 month ago
JSON representation

Simple 1D Kalman Filters in Elm

Awesome Lists containing this project

README

        

# elm-kalman-filter
Simple 1D Kalman filters in Elm

![kalman filter graph](https://raw.githubusercontent.com/CallumJHays/elm-kalman-filter/master/example.png "Example of a Kalman Filter acting on a noisy quadratic signal")

## Installation

```bash
elm package install CallumJHays/elm-kalman-filter
```

## Example

```elm
-- `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:

```elm
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](https://en.wikipedia.org/wiki/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 :)