.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/maximizestopbandattenuation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_maximizestopbandattenuation.py: ============================== 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. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: Python from mplsignal import freqz_fir from fird.constraint import PiecewiseLinearConstraint from fird.designer import FIRDesigner from fird.objective import PiecewiseLinearObjective .. GENERATED FROM PYTHON SOURCE LINES 18-20 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. .. GENERATED FROM PYTHON SOURCE LINES 20-26 .. code-block:: Python 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() .. image-sg:: /examples/images/sphx_glr_maximizestopbandattenuation_001.png :alt: maximizestopbandattenuation :srcset: /examples/images/sphx_glr_maximizestopbandattenuation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.236 seconds) .. _sphx_glr_download_examples_maximizestopbandattenuation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: maximizestopbandattenuation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: maximizestopbandattenuation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: maximizestopbandattenuation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_