This code is based on the article: Smoothing and Differentiation of Data by Simplified Least Squares Procedures
$ npm i ml-savitzky-golay
SavitzkyGolay(data, h, [options])
Uses the Savitzky-Golay filter based in the array of
data) and the difference between
- windowSize: The amount of dots used to make the filtering evaluation, the default value is 5.
- derivative: The grade for the derivative, the default value is 1.
- polynomial: The grade of the polynomial function to use for calculation, the default value is 2.
- pad: How to pad the array to handle borders. Can be one of:
'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
- padValue: If pad is not none, Determine how to fill the values, if the value don't match with the next strings, the new values are going to be filled with that value.
The default value is 0. The special strings are:
'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 = ;let data =/* ... */;let options = derivative: 0 ;let ans = ;console; // smoothed data
;let data =/* ... */;let options = derivative: 0 ;let ans = ;
First derivative with padding
var SG = ;var X =/* ... */;var options =derivative: 1pad: 'post'padValue: 'replicate';var dX = ;console; // first derivative