Javascript based Kalman filter for 1D data. Sometimes you need a simple noise filter without any dependencies; for those cases Kalman.js is perfect.
I wrote two blog posts on explaining Kalman filters in general and applying them on noisy data in particular:
- KalmanJS, Lightweight Javascript Library for Noise filtering
- Kalman filters explained: Removing noise from RSSI signals
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.
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.
npm install kalmanjs
import KalmanFilter from 'kalmanjs';
const kf = new KalmanFilter();
kf.filter(2);
npm install kalmanjs
var KalmanFilter = require('kalmanjs').default;
var kf = new KalmanFilter();
kf.filter(2);
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.
Copyright (C) 2015 Wouter Bulten
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.