1
$\begingroup$

I have used a bandpass filter function in Matlab as follows

Fs = 128;  sampling rate
Fd = [1 4]; passband freq
[data_1_bandpassed, digital_filter] = bandpass(signal, Fd, Fs); 

How can we design this bandpass filter in Python to recreate the exact same output?

When using butter & filtfilt commands in Matlab & Python, I am able to get the exact same filtered signals between the two programming languages. However, I explicilty need to recreate this output of Matlabs bandpass function in Python.

I have also attached the output of the digital filter properties and values created using Matlab bandpass function.

Digital filter values produced by Matlabs bandpass function

A similar question is already asked by another user few months ago in different domain but with no solution, so I am adding that here for reference as well!

$\endgroup$

1 Answer 1

1
$\begingroup$

I know it is a bit late, but i had the SAME issue as you today. But from what you showed, i may got the solution similar to Matlab. I don't know if it is the right answer but you could tell me in a future!

Just to complement what you have already said, in the matlab documentation for the function, we have: stopband attenuation of 60 dB. I did some changes from my variables, to fit your variables.

from scipy.signal import firwin, remez, kaiser_atten, kaiser_beta, kaiserord 
Fs = 128.0
lowcut = 1 #In Hertz
highcut = 5 #In Hertz
stopbbanAtt = 60  #stopband attenuation of 60 dB.
width = .5 #This sets the cutoff width in Hertz
nyq = 0.5*Fs
ntaps, gb= kaiserord(stopbbanAtt, width/nyq)
atten = kaiser_atten(ntaps, width/nyq)
beta = kaiser_beta(atten)
a = 1.0
taps = firwin(ntaps, [lowcut, highcut], nyq=nyq, pass_zero=False,window=('kaiser', beta), scale=False)
filtered_signal = signal.filtfilt(taps, a, signal)

From that, i applied FFT in both: Matlab & Python and in spectral analisys i've got the same cut frequencies with my own 1-D data from EEG .

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.