lowpassf

lowpass filter for javascript/node

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
lowpassf
200.5.07 years ago7 years agoMinified + gzip package size for lowpassf in KB

Readme

Overview
lowpassf is simple lowpass filter libary for javascipt/node.js. It can be used to smooth real-time data including high frequency noises. This library provides 2 ways.
  • Simple moving average
  • Weighted moving average
It is licensed under MIT license.
Usage
```javascript var filter = new LowpassFilter(); //Set average logic from ( filter.LinearWeightAverage/filter.SimpleAverage) filter.setLogic(filter.LinearWeightAverage);
var data = [100, 100, 200, 200, 300, 300]
var i;
for (i = 0; i < data.length; i++) {
//put current value
filter.putValue(data[i]);
//Get the latest calculated moving average of the values putted so far
var filteredValue=filter.getFilteredValue();
console.log(filteredValue);
}
```
Examples
Here is a simple example. https://riversun.github.io/lowpassf/

Run on node.js

You can import library with npm. Install ``` npm install --save-dev lowpassf ``` app.js ```javascript var LowpassFilter = require('lowpassf'); var filter = new LowpassFilter(); //Set average logic from ( filter.LinearWeightAverage/filter.SimpleAverage) filter.setLogic(filter.LinearWeightAverage); var data = 100, 100, 200, 200, 300, 300 var i; var sampleRange = 20; console.log("Prepare data..."); for (i = 0; i < data.length; i++) {
console.log("data[" + i + "]=" + data[i]);
} console.log(""); console.log("Start filtering..."); //Specify how many items to buffer filter.setSamplingRange(sampleRange); for (i = 0; i < data.length; i++) {
//put current value
filter.putValue(data[i]);
//get current "filtered" value
//Get the latest calculated moving average of the values putted so far
var filteredValue = filter.getFilteredValue();
var logStr = "data[" + i + "]=" + data[i]
+ " added. current filtered val is "
+ filteredValue;
console.log(logStr);
} ``` run on node.js ``` node app.js ```

Run on browser

```html ```