Home

Awesome

savitzky-golay

NPM version build status Test coverage npm download

Savitzky–Golay filter in Javascript.

This code is based on the article: Smoothing and Differentiation of Data by Simplified Least Squares Procedures

Installation

$ npm i ml-savitzky-golay

SavitzkyGolay(data, h, [options])

Uses the Savitzky-Golay filter based in the array of y values(data) and the difference between x dots(h).

Options:

Examples

Smoothing

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);

First derivative with padding

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

API Documentation

Contributors

License

MIT