npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ml-savitzky-golay

v5.0.0

Published

Savitzky–Golay filter

Downloads

9,518

Readme

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:

  • 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.

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