Skip to content

Savitzky Golay Filter

psambit9791 edited this page Dec 3, 2023 · 5 revisions
The examples provided here use a randomly generated signal.

The default operating mode is set to interp which uses a least squares polynomial fit on the last 'window_length' values to evaluate the extensions on the extremities.x

Savitzky–Golay Filter

savgol

The parameters for this filter are as follows:

  • Mode ⇨ [pad | signal | pad]
    • "interp": fitted polynomial | 1 2 3 4 5 6 7 8 | fitted polynomial
    • "mirror": 4 3 2 | 1 2 3 4 5 6 7 8 | 7 6 5
    • "constant": 0 0 0 | 1 2 3 4 5 6 7 8 | 0 0 0
    • "nearest": 1 1 1 | 1 2 3 4 5 6 7 8 | 8 8 8
    • "wrap": 6 7 8 | 1 2 3 4 5 6 7 8 | 1 2 3
  • Window Size ⇨ 7
  • Polynomial Order ⇨ 2
  • Derivative ⇨ 0
  • Delta ⇨ 1
Code
String mode = "interp" //can be any of the operating modes described above
int windowSize = 5; //can be anything less than length of signal  
int polyOrder = 2; //Order of the polynomial used to generate coefficients
int deriv = 0; // Order of derivative
int delta = 1; // Spacing of samples to which filter is applied
Savgol s1 = new Savgol(windowSize, polyOrder, deriv, delta);
// ALSO: Savgol s1 = new Savgol(windowSize, polyOrder) set deriv=0, delta=1 by DEFAULT
double[] out = s1.filter(signal, mode); //get the result after filtering 
Clone this wiki locally