Skip to content

Kernel Based Filter

Sambit Paul edited this page Dec 2, 2023 · 8 revisions

This library provides 3 kinds of kernel-based filters.

  1. Median Filter
  2. Savitzky–Golay Filter
  3. Wiener Filter

This page explains the usage of all these filters in the context of this library.

The examples provided here use a randomly generated signal.

Median Filter

median

The parameters for this filter are as follows:

  • Window Size ⇨ 7
Code
int windowSize = 7; //can be anything less than length of signal  
MedianFilter mf = new MedianFilter(signal, windowSize); //signal is of type double[]  
double[] out = mf.filter(); //get the result after filtering  

Savitzky–Golay Filter

savgol

The parameters for this filter are as follows:

  • Mode ⇨ [pad | signal | pad]
    • "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 = "mirror" //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(signal, windowSize, polyOrder, deriv, delta); //signal is of type double[] 
// ALSO: Savgol s1 = new Savgol(signal, windowSize, polyOrder) set deriv=0, delta=1 by DEFAULT
double[] out = s1.filter(mode); //get the result after filtering 

Wiener Filter

wiener

The parameters for this filter are as follows:

  • Window Size ⇨ 7
Code
int windowSize = 7; //can be anything less than length of signal  
Wiener wf = new Wiener(signal, windowSize); //signal is of type double[]  
double[] out = wf.filter(); //get the result after filtering  
Clone this wiki locally