Code Monkey home page Code Monkey logo

kalmanjs's Introduction

KalmanJS

Javascript based Kalman filter for 1D data. Sometimes you need a simple noise filter without any dependencies; for those cases KalmanJS is perfect.

I wrote two blog posts on explaining Kalman filters in general and applying them on noisy data in particular:

For other languages than Javascript, please see the note on the contrib folder.

Kalman filter applied to a noisy dataset.

Questions?

Please see the blog post (KalmanJS, Lightweight Javascript Library for Noise filtering) for more information about using this library. Any questions can be posted there as comments.

Examples

An collection of examples can be found here:

Installation

The KalmanJS library is a small javascript library and can easily be integrated in to your project manually. Alternatively, the library can be included using npm.

Try KalmanJS in the browser on Runkit

In the browser

Include the kalman.js or kalman.min.js from the dist folder on your webpage, the filter can then be used directly.

<script src="kalman.min.js" type="text/javascript"></script>
<script type="text/javascript">
  var kf = new KalmanFilter();
  console.log(kf.filter(3));
  console.log(kf.filter(2));
  console.log(kf.filter(1));
</script>

Should output (with default settings):

3
2.3333333333333335
1.5000000000000002

Node (es6)

npm install kalmanjs

import KalmanFilter from 'kalmanjs';

const kf = new KalmanFilter();
console.log(kf.filter(3));
console.log(kf.filter(2));
console.log(kf.filter(1));

Should output (with default settings):

3
2.3333333333333335
1.5000000000000002

Node (es5)

npm install kalmanjs

var KalmanFilter = require('kalmanjs')

var kf = new KalmanFilter();
console.log(kf.filter(3));
console.log(kf.filter(2));
console.log(kf.filter(1));

Should output (with default settings):

3
2.3333333333333335
1.5000000000000002

Applying the filter on a dataset

Using the filter is simple. First we create a simple dataset with random noise:

//Generate a simple static dataset
var dataConstant = Array.apply(null, {length: dataSetSize}).map(function() {
  return 4;
});
//Add noise to data
var noisyDataConstant = dataConstant.map(function(v) {
  return v + randn(0, 3);
});

Then we apply the filter iteratively on each data element:

//Apply kalman filter
var kalmanFilter = new KalmanFilter({R: 0.01, Q: 3});

var dataConstantKalman = noisyDataConstant.map(function(v) {
  return kalmanFilter.filter(v);
});

See this blog post for screenshots and more examples.

Reference

This project was part of my research on indoor localization. Please see my paper or this presentation for more information. You can use the following reference if you want to cite my paper:

W. Bulten, A. C. V. Rossum and W. F. G. Haselager, "Human SLAM, Indoor Localisation of Devices and Users," 2016 IEEE First International Conference on Internet-of-Things Design and Implementation (IoTDI), Berlin, 2016, pp. 211-222. doi: 10.1109/IoTDI.2015.19 URL

Or, if you prefer in BibTeX format:

@INPROCEEDINGS{7471364,
author={W. Bulten and A. C. V. Rossum and W. F. G. Haselager},
booktitle={2016 IEEE First International Conference on Internet-of-Things Design and Implementation (IoTDI)},
title={Human SLAM, Indoor Localisation of Devices and Users},
year={2016},
pages={211-222},
keywords={RSSI;data privacy;indoor environment;ubiquitous computing;FastSLAM;RSSI update;SLAC algorithm;device RSSI;device indoor localisation;device location;device position;environment noise;human SLAM;nontrivial environment;received signal strength indicator;simultaneous localisation and configuration;smart space;user indoor localisation;user motion data;user privacy;Estimation;Performance evaluation;Privacy;Simultaneous localization and mapping;Privacy;Simultaneous localization and mapping;Smart Homes;Ubiquitous computing;Wireless sensor networks},
doi={10.1109/IoTDI.2015.19},
month={April},}

Other languages

Kalman filters can be useful in a broad range of projects. Regularly I get questions whether KalmanJS is available in other languages than Javascript and sometimes another library is available. I would encourage searching for it if you require another implementation. For convenience, this repository contains a contrib folder with user-submitted implementations in other languages.

Copyright

MIT License

Copyright (c) 2018 Wouter Bulten

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

kalmanjs's People

Contributors

aeppler avatar benwinding avatar bidh avatar deeplyembeddedwp avatar joshbeckman avatar rishabhkatiyar avatar sashee avatar sye8 avatar wouterbulten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kalmanjs's Issues

GPS data

Hi I'm new to kalman filters so thought I would ask. Is it possible to use this on smoothing out gps signals where the location is jumping around a bit. I know this is a common use for kalman filters, but I'm a little confused on how to weight the filter by the accuracy of the gps fix. is it possible to use the accuracy as a weight for filtering GPS data?

Thanks

Q and R symbol is misrepresented?

I'm kinda new to this kalman filter concept and after few surveys on the web and now I'm really confused about the symbol's representation made in this repository.
I think the measurement noise symbol that is described as Q should be R and process noise symbol that is described as R should be Q.

You can see many of the references are referring Q as a process noise and R as a measurement noise.

https://github.com/rlabbe/filterpy/blob/master/filterpy/kalman/kalman_filter.py
http://www.swarthmore.edu/NatSci/echeeve1/Ref/Kalman/MatrixKalman.html
https://www.diva-portal.org/smash/get/diva2:1041201/FULLTEXT01.pdf
https://arxiv.org/ftp/arxiv/papers/1702/1702.00884.pdf
https://en.wikipedia.org/wiki/Kalman_filter#Underlying_dynamical_system_model

Update*
I saw the comment that you leaved at your blog and I'm still not sure about which definition is closer to the original.
image

I'll leave a pull-request if needed, Thanks :)

Kalmanjs in real time?

Hi

Great job, I have a question, I saw you have a data set to apply Kalman Filter, so, It's possible apply to real time data??

Sorry I newby in javascript

Best regards

Using multiple filters causes filtered data to converge

When using multiple filters to filter multiple signals, e.g.:

var filterBlue = new KalmanFilter();
var filterGreen = new KalmanFilter();
var filterGray = new KalmanFilter();

It appears as if all the filters are using all data, not just the one passed through them. That's an empirical observation, my JS is not great and I couldn't tell if this was the case through the code. I'm attaching a chart for three signals, the light colors are the raw values and the dark colors are the filtered values. The filter works well individually but it doesn't when instantiated multiple times.

screen shot 2016-04-29 at 3 00 59 pm

input data with timestamps

Hi Wouter,

nice and simple library...

I could apply this for various data filtering in a robot environment. (e.g. RSSI from BLE devices for localisation, speed and position from wheel sensors, etc. are areas where I am struggling with accuracy).

Do I assume that the filter requires a constant time interval between measurements, as there seems no concept of time in the filter?

Background:
For wheel sensors, I have microsecond timestamps on the readings - basically I get a new reading each time the sensor detects it.
For RSSI, the timing of values is fairly random, but I do have timestamps.

What would be your approach for using a kalman filter on inputs where the time interval is not constant?

best regards,

Simon

What is the roadmap for release?

Hello,

I have just discovered your plugin and would like to use it in production soon. When do you plan to release this beta version?

Many thanks

Java Version ?

Hai,
I'm a newbee for this, do you have anything which is Java equivalent for this Javascript. If so it could be more helpful. And also could you add some examples for implementing Kalman filter on realtime data.

Because I actually dont know how to implement it. It will be great if you help.

PS: Sorry for opening it as an issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.