Lowpass Filter in python Lowpass Filter in python numpy numpy

Lowpass Filter in python


A very basic approach would be to invoke

# spell out the args that were passed to the Matlab functionN = 10Fc = 40Fs = 1600# provide them to firwinh = scipy.signal.firwin(numtaps=N, cutoff=40, nyq=Fs/2)# 'x' is the time-series data you are filteringy = scipy.signal.lfilter(h, 1.0, x)

This should yield a filter similar to the one that ends up being made in the Matlab code.If your goal is to obtain functionally equivalent results, this should provide a usefulfilter.

However, if your goal is that the python code provide exactly the same results,then you'll have to look under the hood of the design call (in Matlab); From my quick check, it's not trivial to parse through the Matlab calls to identify exactly what it is doing, i.e. what design method is used and so on, and how to map that into corresponding scipy calls. If you really want compatibility, and you only need to do this for a limited numberof filters, you could, by hand, look at the Hd.Numerator field -- this array of numbers directly corresponds to the h variable in the python code above. So if you copy thosenumbers into an array by hand, you'll get numerically equivalent results.