Low pass filter in python

I am trying to convert Matlab code to Python. I want to implement fdesign.lowpass() Matlab in Python. What would be the exact replacement for this Matlab code with scipy.signal.firwin() :

 demod_1_a = mod_noisy * 2.*cos(2*pi*Fc*t+phi); d = fdesign.lowpass('N,Fc', 10, 40, 1600); Hd = design(d); y = filter(Hd, demod_1_a); 
+7
python filter numpy scipy
source share
1 answer

The easiest approach is to call

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

This will give a filter similar to the one created in the Matlab code. If your goal is to get functionally equivalent results, this should provide a useful filter.

However, if your goal is that the python code provides exactly the same results, then you will have to search under the hood of the design call (in Matlab); From my quick check, there is no trivial analysis through Matlab calls to determine exactly what it does, i.e. What design method is used, etc., and how to match this with the corresponding scipy calls. If you really need compatibility, and you only need to do this for a limited number of filters, you could manually look at the Hd.Numerator field - this array of numbers directly matches the h variable in the above python code. Therefore, if you copy these numbers into an array manually, you will get results equivalent to a digit.

+5
source share

All Articles