{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "88163648",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "852ee06b",
            "cell_type": "markdown",
            "source": "Design an analog bandpass filter with passband within 3 dB from 20 to\n50 rad/s, while rejecting at least -40 dB below 14 and above 60 rad/s.\nPlot its frequency response, showing the passband and stopband\nconstraints in gray.\n",
            "metadata": {}
        },
        {
            "id": "4f6340ff",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import signal\nimport matplotlib.pyplot as plt\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "f9fbb538",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "N, Wn = signal.buttord([20, 50], [14, 60], 3, 40, True)\nb, a = signal.butter(N, Wn, 'band', True)\nw, h = signal.freqs(b, a, np.logspace(1, 2, 500))\nplt.semilogx(w, 20 * np.log10(abs(h)))\nplt.title('Butterworth bandpass filter fit to constraints')\nplt.xlabel('Frequency [rad/s]')\nplt.ylabel('Amplitude [dB]')\nplt.grid(which='both', axis='both')\nplt.fill([1,  14,  14,   1], [-40, -40, 99, 99], '0.9', lw=0) # stop\nplt.fill([20, 20,  50,  50], [-99, -3, -3, -99], '0.9', lw=0) # pass\nplt.fill([60, 60, 1e9, 1e9], [99, -40, -40, 99], '0.9', lw=0) # stop\nplt.axis([10, 100, -60, 3])\nplt.show()",
            "outputs": []
        }
    ]
}