Skip to content

Windowed FIR Filter with Gain

Sambit Paul edited this page Dec 2, 2023 · 2 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)$

FIRWin2

firwin2

Type 1 Filter

The parameters for this filter are as follows:

  • Taps ⇨ 15
  • Cutoff Frequency ⇨ [0Hz, 25Hz, 50Hz]
  • Gains ⇨ [0.0, 1.0, 1.0]
  • Sampling Frequency ⇨ 100Hz
Code
double samplingRate = 100;
double[] freqs = {0.0, 25, 50};
double[] gains = {0.0, 1.0, 1.0};
int taps = 15;

FIRWin2 fw2 = new FIRWin2(taps, samplingRate);
double[] outCoeffs = fw2.computeCoefficients(freqs, gains);
double[] filteredX = fw2.firfilter(outCoeffs, signal);

Type 2 Filter

The parameters for this filter are as follows:

  • Taps ⇨ 10
  • Cutoff Frequency ⇨ [0Hz, 25Hz, 50Hz]
  • Gains ⇨ [1.0, 1.0, 0.0]
  • Sampling Frequency ⇨ 100Hz
Code
double samplingRate = 100;
double[] freqs = {0.0, 25, 50};
double[] gains = {1.0, 1.0, 0.0};
int taps = 10;

FIRWin2 fw2 = new FIRWin2(taps, samplingRate);
double[] outCoeffs = fw2.computeCoefficients(freqs, gains);
double[] filteredX = fw2.firfilter(outCoeffs, signal);

Type 3 Filter

The parameters for this filter are as follows:

  • Taps ⇨ 15
  • Cutoff Frequency ⇨ [0Hz, 25Hz, 50Hz]
  • Gains ⇨ [0.0, 1.0, 0.0]
  • Sampling Frequency ⇨ 100Hz
Code
double samplingRate = 100;
double[] freqs = {0.0, 25, 50};
double[] gains = {0.0, 1.0, 0.0};
int taps = 15;

FIRWin2 fw2 = new FIRWin2(taps, samplingRate, true);
double[] outCoeffs = fw2.computeCoefficients(freqs, gains);
double[] filteredX = fw2.firfilter(outCoeffs, signal);

Type 4 Filter

The parameters for this filter are as follows:

  • Taps ⇨ 10
  • Cutoff Frequency ⇨ [0Hz, 25Hz, 50Hz]
  • Gains ⇨ [0.0, 1.0, 1.0]
  • Sampling Frequency ⇨ 100Hz
Code
double samplingRate = 100;
double[] freqs = {0.0, 25, 50};
double[] gains = {0.0, 1.0, 1.0};
int taps = 10;

FIRWin2 fw2 = new FIRWin2(taps, samplingRate, true);
double[] outCoeffs = fw2.computeCoefficients(freqs, gains);
double[] filteredX = fw2.firfilter(outCoeffs, signal);
Clone this wiki locally