{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "9bc94589",
            "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": "3c836e36",
            "cell_type": "markdown",
            "source": "The following example shows how to create a Bode plot of a 5-th order\nButterworth lowpass filter with a corner frequency of 100 Hz:\n",
            "metadata": {}
        },
        {
            "id": "05074be2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy import signal\n\nT = 1e-4  # sampling interval in s\nf_c, o = 1e2, 5  # corner frequency in Hz (i.e., -3 dB value) and filter order\nbb, aa = signal.butter(o, f_c, 'lowpass', fs=1/T)\n\nw, mag, phase = signal.dbode((bb, aa, T))\nw /= 2*np.pi  # convert unit of frequency into Hertz\n\nfg, (ax0, ax1) = plt.subplots(2, 1, sharex='all', figsize=(5, 4),\n                              tight_layout=True)\nax0.set_title(\"Bode Plot of Butterworth Lowpass Filter \" +\n              rf\"($f_c={f_c:g}\\,$Hz, order={o})\")\nax0.set_ylabel(r\"Magnitude in dB\")\nax1.set(ylabel=r\"Phase in Degrees\",\n        xlabel=\"Frequency $f$ in Hertz\", xlim=(w[1], w[-1]))\nax0.semilogx(w, mag, 'C0-', label=r\"$20\\,\\log_{10}|G(f)|$\")  # Magnitude plot\nax1.semilogx(w, phase, 'C1-', label=r\"$\\angle G(f)$\")  # Phase plot\n\nfor ax_ in (ax0, ax1):\n    ax_.axvline(f_c, color='m', alpha=0.25, label=rf\"${f_c=:g}\\,$Hz\")\n    ax_.grid(which='both', axis='x')  # plot major & minor vertical grid lines\n    ax_.grid(which='major', axis='y')\n    ax_.legend()\nplt.show()",
            "outputs": []
        }
    ]
}