Skip to content

Windowed FIR Filter

Sambit Paul edited this page Dec 2, 2023 · 3 revisions
The examples provided here use this signal:

$\cos(2\pi\times0.5t) + 0.2\sin(2\pi\times2.5t+0.1) + 0.2\sin(2\pi\times15.3t) + 0.1\sin(2\pi\times16.7t + 0.1) + 0.1\sin(2\pi\times23.45t+0.8)$

FIRWin1

firwin1

Low-Pass Filter

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 4
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ 10Hz
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.LOWPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ 10Hz
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.LOWPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);

High-Pass Filter

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 2
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ 10Hz
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.HIGHPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ 10Hz
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.HIGHPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);

Band-Pass Filter

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ [1.0Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {1.0, 10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.BANDPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ [1Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {1.0, 10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.BANDPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);

Band-Stop Filter

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 2
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ [1.0Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 2;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {1.0, 10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.BANDSTOP, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 2
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ [1Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 2;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {1.0, 10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.BANDSTOP, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);

Multi Band-Pass Filter

firwin1_bp

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ [1.0Hz, 2.5Hz, 7.5Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {1.0, 2.5, 7.5, 10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.MULTIBANDPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ [1.0Hz, 2.5Hz, 7.5Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {1.0, 2.5, 7.5, 10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.MULTIBANDPASS, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);

Multi Band-Stop Filter

firwin1_bs

The 'Ripple Value' Approach

The parameters for this filter are as follows:

  • Width ⇨ 2
  • Ripple Value ⇨ 60
  • Cutoff Frequency ⇨ [1.0Hz, 2.5Hz, 7.5Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 2;
double samplingRate = 100;
double rippleVal = 60.0;
double[] cutoff = {1.0, 2.5, 7.5, 10.0};

FIRWin1 fw = new FIRWin1(rippleVal, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.MULTIBANDSTOP, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
The 'Number of Taps' Approach

The parameters for this filter are as follows:

  • Width ⇨ 5
  • Taps ⇨ 5
  • Cutoff Frequency ⇨ [1.0Hz, 2.5Hz, 7.5Hz, 10Hz]
  • Sampling Frequency ⇨ 100Hz
Code
double width = 5;
double samplingRate = 100;
int taps = 5;
double[] cutoff = {1.0, 2.5, 7.5, 10.0};

FIRWin1 fw = new FIRWin1(taps, width, samplingRate);
double[] outCoeffs = fw.computeCoefficients(cutoff, FIRWin1.FIRfilterType.MULTIBANDSTOP, true);
double[] filteredX = fw.firfilter(outCoeffs, signal);
Clone this wiki locally