Note
Go to the end to download the full example code.
Maximize stopband attenuation.ΒΆ
Often one wants to maximize the stopband attenuation of a filter subject to a given passband ripple and filter order. This can be done by minimizing the approximation error in the stopband subject to a constraint on the passband ripple. This example shows how to do this.
from mplsignal import freqz_fir
from fird.constraint import PiecewiseLinearConstraint
from fird.designer import FIRDesigner
from fird.objective import PiecewiseLinearObjective
Create a constraint for the passband ripple of maximum 0.01 and an objective to minimize the approximation error in the stopband. First, design a filter minimizing the approximation error using a filter order of 30.
c = PiecewiseLinearConstraint([0, 0.3], [1, 1], [0.01])
o = PiecewiseLinearObjective([0.5, 1], [0, 0])
d = FIRDesigner(31, o, c)
d.solve()
h30 = d.get_impulse_response()
freqz_fir(h30).show()

Total running time of the script: (0 minutes 0.236 seconds)