If I run this in matlab:

h = firpm(100,[0 0.1 0.2 1],[0 0 1 1])

and this in scipy:

h = remez(100,[0, 0.05, 0.1, 0.5],[0, 1])

I think I'm asking for the same thing, but the results are totally different and the scipy response is garbage. What am I doing wrong? I don't need the results to be exact, just similar.


1 Answer 1


The firpm and remez commands return symmetric linear phase filter solutions. In order to create a symmetric linear phase high pass filter, you must have an odd number of taps (Type 1 filter, see chart below). An even number of taps with a symmetric filter will have a zero at Nyquist and thus you can't (successfully) create a high pass.

In the Matlab firpm command as entered with N=100, the first parameter N is the order of taps in the filter (one less than the number of taps) so will result in an odd number of taps as required, while in the Python scipy.signal remez command, the first parameter N is the number of taps and thus for N=100 will come out as an even number which can't be realized. Confirming this, if you increase N by one in Matlab you will get the same (bad) result. Or similarly, if you increase N by one in the Python example you will get the same (good) result.

Matlab doc: "b = firpm(n,f,a) returns row vector b containing the n+1 coefficients of an order-n FIR filter."

Python doc: "Parameters ---------- numtaps : int The desired number of taps in the filter. The number of taps is the number of terms in the filter, or the filter order plus one."

Linear Phase Filter Types

As a simplest confirmation / demonstration of the forced zero location for Type II (always has a zero at $z=-1$ or Nyquist) and Type IV (always has a zero at $z=1$ or DC) I have added the graphic below:

example Type II and Type IV FIR filters


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.