Savitzky–Golay filter in Javascript.
This code is based on the article: Smoothing and Differentiation of Data by Simplified Least Squares Procedures
$ npm i ml-savitzky-golay
Uses the Savitzky-Golay filter based in the array of y
values(data
) and the difference between x
dots(h
).
Options:
'none'
(default): No padding. The resulting array will be smaller than the original one.'pre'
: Pad the original array before applying the filter'post'
: Pad the resulting array after applying the filter'circular'
: Pad with circular repetition of elements within the dimension.'replicate'
: Pad by repeating border elements of array.'symmetric'
: Pad array with mirror reflections of itself.const savitzkyGolay = require('ml-savitzky-golay');
let data = [
/* ... */
];
let options = { derivative: 0 };
let ans = savitzkyGolay(data, 1, options);
console.log(ans); // smoothed data
or
import savitzkyGolay from 'ml-savitzky-golay';
let data = [
/* ... */
];
let options = { derivative: 0 };
let ans = savitzkyGolay(data, 1, options);
var SG = require('ml-savitzky-golay');
var X = [
/* ... */
];
var options = {
derivative: 1,
pad: 'post',
padValue: 'replicate',
};
var dX = SG(X, 1, options);
console.log(dX); // first derivative