Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ml-savitzky-golay-generalized

Package Overview
Dependencies
Maintainers
6
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-savitzky-golay-generalized

Savitzky–Golay filter in Javascript

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
increased by0.24%
Maintainers
6
Weekly downloads
 
Created
Source

savitzky-golay-generalized

General Least-Squares Smoothing and Differentiation by the Convolution (Savitzky-Golay) Method Peter A. Gorry

Pretty much the same as the savitzky-golay method, but without border problems, and without inventing points. It can be maybe merged into the savitzky-golay project but by the now this is the version used in the last GSD project.

I'll try an automatic parameter tunning based on the SNR or in the entropy of the signal. #Usage

npm i ml-savitzky-golay-generalized
const SG = var SG = require("ml-savitzky-golay-generalized");
SG(dataY, deltaX|X, options)

##Parameters

dataY

The data to be filtered.

###deltaX | X deltaX specifies the difference between 2 consecutive points of the independent: deltaX = X[i+1] - X[i]. Specficiying a deltaX suppose that all your points are equally spaced on the independent variable. If your points are not equally spaced in the ordinate variable, then you have to provide explicitelly your X values. The algorithm will use the average deltaX within each bin of 'windowSize' points to approximate the derivatives. This fast approximation only works if the X is almost locally equally spaced.

###options ####windowSize: The odd number of points to approximate the regresion polynomial. Default 9 ####derivative: The grade of the derivative. 0 by defualt(Smoothing) ####polynomial: The order of the regresion polynomial. Default 3

Examples

var SG = require("ml-savitzky-golay-generalized");

Smoothing example

var options = {
            windowSize: 15,
            derivative: 0,
            polynomial: 3
        };

var noiseLevel = 0.1;
var data = new Array(200);
for (var i = 0; i < data.length; i++)
     data[i] = Math.sin(i*Math.PI*2/data.length)+(Math.random()-0.5)*noiseLevel;
var ans = SG(data, Math.PI*2/data.length, options);
console.log(ans);

First derivative test (Equally spaced x)

var options = {
    windowSize: 47,
    derivative: 1,
    polynomial: 3
    };

var noiseLevel = 0.1;
var data = new Array(200);
for (var i = 0; i < data.length; i++)
     data[i] = Math.sin(i*Math.PI*2/data.length)+(Math.random()-0.5)*noiseLevel;
var ans = SG(data, Math.PI*2/data.length, options);
console.log(ans);

First derivative test x as vector(It could be non-equally spaced!!)

var options = {
            windowSize: 47,
            derivative: 1,
            polynomial: 3
    };

var noiseLevel = 0.1;
var data = new Array(200);
var x = new Array(200);
for (var i = 0; i < data.length; i++){
    data[i] = Math.sin(i*Math.PI*2/data.length)+(Math.random()-0.5)*noiseLevel;
    x[i]=i*Math.PI*2/data.length;
}

var ans = SG(data, Math.PI*2/data.length, options);
var ans2 = SG(data, x, options);

/*for (var j = 0; j < data.length; j++){
      console.log(ans[j]+" "+ans2[j]);
 }*/
/* The result should be the approximately the same
for (var j = Math.round(options.windowSize/2); j < data.length-Math.round(options.windowSize/2); j++){
    ans[j].should.be.approximately(ans2[j], 10e-10);
 }
*/

Keywords

FAQs

Package last updated on 24 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc