0
$\begingroup$

I've read the similar question Find the equivalent of this python remez specs in C++ remez or Matlab firpm, which describes a different problem.


In Matlab, I have following remez and firpm function calls:

remez(10,[0 .1 1-.1 1],[1 1 0 0])
firpm(10,[0 .1 1-.1 1],[1 1 0 0])

and in Scipy, I can achieve the same filter by calling:

signal.remez(11, bands=[0, .1, 1.0 - .1, 1], desired=[1, 0], fs=2)

Both 3 function calls returns me the same coefficients:

ans =

    0.0066   -0.0000   -0.0510    0.0000    0.2944    0.5000    0.2944    0.0000   -0.0510   -0.0000    0.0066

The problem is: when I attempt to sharpen the corner frequency from the half pass filter, by substituting the Δf = .1 to Δf = .01, the output from Scipy is an array of nan.

remez(10,[0 .01 1-.01 1],[1 1 0 0])
firpm(10,[0 .01 1-.01 1],[1 1 0 0])

both Matlab calls returns me the same filter coefficients:

ans =

    0.0059   -0.0000   -0.0488    0.0000    0.2930    0.5000    0.2930    0.0000   -0.0488   -0.0000    0.0059

By attempting to get the same filter from Scipy,

signal.remez(11, bands=[0, .01, 1.0 - .01, 1], desired=[1, 0], fs=2)

the result is:

array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])

I don't know exactly if there's something wrong with the arguments or maybe a precision problem in the Python call. Any help is appreciated!

$\endgroup$

1 Answer 1

0
$\begingroup$

The solution is to use the grid_density parameter, which is the dense grid used in the Remez exchange algorithm. The default is 16 and for 11 taps results in a dense grid of 12 x 16 which is too small for such a wide transition range. The following will produce useful results:

sig.remez(11, bands=[0, .01, .99, 1], desired=[1, 0], grid_density=61, fs=2)

This is a rather odd filter to pass only from DC to 0.01 and reject only from 0.99 to 1. If one were to "tighten it" we would move more toward passing DC to 0.49 and rejecting from 0.51 to 1 (or where-ever the desired transition band is) with a corresponding increase in the number of coefficients as detailed here.

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