FIR Filter Implementation in Julia

Hello all,

I’m trying to replicate this MATLAB code in Julia for zero-phase filtering:

d = designfilt('bandpassfir', 'StopbandFrequency1', 1e-9, ...
    'PassbandFrequency1', 35, 'PassbandFrequency2', 45, ...
    'StopbandFrequency2', 50, 'StopbandAttenuation1', 120, ...
    'PassbandRipple', 1, 'StopbandAttenuation2', 120, 'SampleRate', 100);

Which results in a filter with the following properties:

d = 

 digitalFilter with properties:

            Coefficients: [1×371 double]

       FrequencyResponse: 'bandpass'
         ImpulseResponse: 'fir'
              SampleRate: 100
    StopbandAttenuation1: 120
      PassbandFrequency1: 1
      StopbandFrequency2: 50
          PassbandRipple: 1
      PassbandFrequency2: 5
    StopbandAttenuation2: 120
      StopbandFrequency1: 1.0000e-09
            DesignMethod: 'equiripple'

And I use this in filtfilt:

filteredData = filtfilt(d, data)

However, I’m having difficulty with the DSP package to replicate this. The FIR method asks for a window and I couldn’t find the equiripple design method for FIR in the documentation. Can anybody help me out?


1 Like

I don’t think DSP.jl supports as many design techniques as Matlab does. You can approximate the same filter response using remez:

fil = remez(371, [0, 34, 35, 45, 46, 50], [0, 1, 0], Hz=100, maxiter=100);

Alternatively, just go with a FIR window design:

fil = digitalfilter(Bandpass(35, 45, fs=100), FIRWindow(blackman(371)));

which actually produces better stopband rejection. I don’t think any of these two methods reaches 120 dB of rejection, though.


Thanks a lot! I’ll use the FIR window then, 120 dB was a bit overkill so something around 60 would do the trick just as well.

1 Like