2
$\begingroup$

I'm starting to use both the fir1 MATLAB and firwin Scipy functions. Both are window-based FIR filter design methods.

I would like to know why the fir1 filter has one more tap than its order. The firwin filter has the same amount of samples than its order.

MATLAB console:

>> filter = fir1(512, .001);
>> size(filter)

ans =

     1   513

>> plot(filter)

Python console:

>>> import matplotlib.pyplot as plt
>>> from scipy import signal
>>> import numpy as np
>>> filter = signal.firwin(numtaps=512, cutoff=.001)
>>> filter.shape
(512,)
>>> plt.plot(filter); plt.show()

The left one is the plot from MATLAB, and then the Python plot:

enter image description here

By incrementing/decrementing one of the arguments, so they can have the same length, both filter values get very close.

$\endgroup$

1 Answer 1

2
$\begingroup$

There is a slight difference in how python and MATLAB define their input parameters.

MATLAB takes the filter order (which is defined as the greatest tap delay), while Python takes the number of coefficients in the filter. For instance, a filter like

y(n) = ax(n) + bx(n - 1)

Has 2 coefficients, but is a first order filter.

$\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.