Skip to content

IIR Filter

Sambit Paul edited this page Jun 5, 2021 · 2 revisions

This library provides 3 kinds of frequency-based filters.

  1. Butterworth Filter
  2. Chebyshev Filter (Type I and Type II)
  3. Bessel Filter

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

The examples provided here use this signal:

\sin(10\pi t) + \sin(30\pi t) + \sin(60\pi t)

Butterworth Filter

butterworth

Low-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 9Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 9; //Cut-off Frequency  
Butterworth flt = new Butterworth(signal, Fs); //signal is of type double[]  
double[] result = flt.lowPassFilter(order, cutOff); //get the result after filtering  

High-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 29Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 29; //Cut-off Frequency  
Butterworth flt = new Butterworth(signal, Fs); //signal is of type double[]  
double[] result = flt.highPassFilter(order, cutOff); //get the result after filtering  

Band-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 12Hz
  • Upper Cutoff Frequency ⇨ 18Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 12; //Lower Cut-off Frequency  
int highCutOff = 18; //Higher Cut-off Frequency  
Butterworth flt = new Butterworth(signal, Fs); //signal is of type double[]  
double[] result = flt.bandPassFilter(order, lowCutOff, highCutOff); //get the result after filtering  

Band-Stop Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 7Hz
  • Upper Cutoff Frequency ⇨ 28Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 7; //Lower Cut-off Frequency  
int highCutOff = 28; //Higher Cut-off Frequency  
Butterworth flt = new Butterworth(signal, Fs); //signal is of type double[]  
double[] result = flt.bandStopFilter(order, lowCutOff, highCutOff); //get the result after filtering  

Chebyshev Filter Type I

cheby1

Low-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 9Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 1; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 9; //Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.lowPassFilter(order, cutOff); //get the result after filtering  

High-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 29Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 1; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 29; //Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.highPassFilter(order, cutOff); //get the result after filtering  

Band-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 12Hz
  • Upper Cutoff Frequency ⇨ 18Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 1; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 12; //Lower Cut-off Frequency  
int highCutOff = 18; //Higher Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.bandPassFilter(order, lowCutOff, highCutOff); //get the result after filtering

Band-Stop Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 7Hz
  • Upper Cutoff Frequency ⇨ 28Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 1; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 7; //Lower Cut-off Frequency  
int highCutOff = 28; //Higher Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.bandStopFilter(order, lowCutOff, highCutOff); //get the result after filtering  

Chebyshev Filter Type II

cheby2

Low-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 9Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 2; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 9; //Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.lowPassFilter(order, cutOff); //get the result after filtering  

High-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 29Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 2; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 29; //Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.highPassFilter(order, cutOff); //get the result after filtering  

Band-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 12Hz
  • Upper Cutoff Frequency ⇨ 18Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 2; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 12; //Lower Cut-off Frequency  
int highCutOff = 18; //Higher Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.bandPassFilter(order, lowCutOff, highCutOff); //get the result after filtering

Band-Stop Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 7Hz
  • Upper Cutoff Frequency ⇨ 28Hz
  • Sampling Frequency ⇨ 100Hz
Code
int filterType = 2; //Can be 1 (for type 1) or 2 (for type 2)
double rippleFactor = 1; //maximum ripple allowed below unity gain 
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 7; //Lower Cut-off Frequency  
int highCutOff = 28; //Higher Cut-off Frequency  
Chebyshev flt = new Chebyshev(signal, Fs, filterType, rippleFactor); //signal is of type double[]  
double[] result = flt.bandStopFilter(order, lowCutOff, highCutOff); //get the result after filtering  

Bessel Filter

bessel

Low-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 9Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 9; //Cut-off Frequency  
Bessel flt = new Bessel(signal, Fs); //signal is of type double[]  
double[] result = flt.lowPassFilter(order, cutOff); //get the result after filtering

High-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Cutoff Frequency ⇨ 29Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int cutOff = 29; //Cut-off Frequency  
Bessel flt = new Bessel(signal, Fs); //signal is of type double[]  
double[] result = flt.highPassFilter(order, cutOff); //get the result after filtering  

Band-Pass Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 12Hz
  • Upper Cutoff Frequency ⇨ 18Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 12; //Lower Cut-off Frequency  
int highCutOff = 18; //Higher Cut-off Frequency  
Bessel flt = new Bessel(signal, Fs); //signal is of type double[]  
double[] result = flt.bandPassFilter(order, lowCutOff, highCutOff); //get the result after filtering  

Band-Stop Filter

The parameters for this filter are as follows:

  • Order ⇨ 4
  • Lower Cutoff Frequency ⇨ 7Hz
  • Upper Cutoff Frequency ⇨ 28Hz
  • Sampling Frequency ⇨ 100Hz
Code
int Fs = 100; //Sampling Frequency in Hz  
int order = 4; //order of the filter  
int lowCutOff = 7; //Lower Cut-off Frequency  
int highCutOff = 28; //Higher Cut-off Frequency  
Bessel flt = new Bessel(signal, Fs); //signal is of type double[]  
double[] result = flt.bandStopFilter(order, lowCutOff, highCutOff); //get the result after filtering  
Clone this wiki locally