2
$\begingroup$

I created a equiripple FIR filter in Matlab using filterDesigner and exported it to an ASCII file. The file contains the numerator values as a list of 51 numbers tagged under Numerator: (this is all the data the file has)

Now I read this 51 values into a python array named num and try to recreate the filter in python using scipy.signal.lfilter

from scipy import signal

x_filt = signal.lfilter(num, np.ones_like(num), x)  # x is my input signal

This is my original signal

enter image description here

Here's the filtered signal from Matlab (Fpass-800Hz, Fstop-1200Hz)

enter image description here

But this is what I get from the python code using scipy.signal.lfilter

enter image description here

Can somebody please show me what I am doing wrong here?


EDIT: (After getting the answer) Here's the correct python code

x_filt = signal.lfilter(num, 1, x)
$\endgroup$
  • 2
    $\begingroup$ You don't want np.ones_like(num) in the denominator. That's making a denominator of all ones, with lots of possibly unstable poles. Your denominator in Python needs to be [1,0,0,0,0,0,...]. Or just [1] if possible. $\endgroup$ – Peter K. Nov 20 at 18:42
  • $\begingroup$ It worked. thanks. Can you please add this as an answer? $\endgroup$ – Teshan Shanuka J Nov 21 at 9:52
  • $\begingroup$ Done! Glad it worked out. $\endgroup$ – Peter K. Nov 21 at 16:32
4
$\begingroup$

You don't want np.ones_like(num) in the denominator. That's making a denominator of all ones, with lots of possibly unstable poles. Your denominator in Python needs to be [1,0,0,0,0,0,...]. Or just [1] if possible.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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