Filtfilt in DSP.jl - I really don't get it

Hi dear community members,

while making bigger steps forwards switching completely from Matlab to Julia here and there I am often struggling to solve some issues. This is mainly due to the poor/missing documentation of the packages. At the moment I am trying to make the filtfilt function run in DSP.jl (BTW: I am not an expert in filter designing…). Just to make it simple: My corresesponding matlab code is given below. But for hours now I have no idea how to realize that with DSP.jl. Anyone able to help ? Thank you…

Bandpass Filter in Matlab
Wn=[0.5 15]/((1/dt)/2); % Cut off frequencies 0.5 Hz & 15 Hz
[b,a] = butter(4,Wn,‘bandpass’); % Filter coefficients for bandpass
filtered_signal = filtfilt(b,a,raw_signal); % Application of the filter

julia> using DSP

julia> myfilter = digitalfilter(Bandpass(0.1,0.15),Butterworth(2));

julia> mydata = rand(100);

julia> filtfilt(myfilter,mydata)

This seems to work, hopefully it will help you make some progress. This is adapted from the example section on this page: https://juliadsp.github.io/DSP.jl/latest/filters.html#Filter-design-1

5 Likes

It was a simple and nice answer, but can I ask you one more, plz?

What should I do to use the Bandpass with high frequencies, such as 500 ~ 800 Hz?
I am not sure how to control the Nyquest frequency or time step in your Julia code example.

Thanks for your help.

You can type ?Bandpass in REPL after using DSP

help?> Bandpass
search: Bandpass filter_type_bandpass

  Bandpass(Wn1, Wn2[; fs])

  Band pass filter with normalized pass band (Wn1, Wn2). If fs is not specified, Wn1 and Wn2 are interpreted as
  normalized frequencies in half-cycles/sample.

So you can either specify cutoff frequencies in Hz and the sampling frequency fs, or specify cutoff frequencies normalized to fs/2.

1 Like