{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "33b171ca",
            "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": "903a1b12",
            "cell_type": "markdown",
            "source": "The following example shows the frequency response of an analog bandpass filter and\nthe corresponding digital filter derived by utilitzing the bilinear transform:\n",
            "metadata": {}
        },
        {
            "id": "ae016674",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import signal\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfs = 100  # sampling frequency\nom_c = 2 * np.pi * np.array([7, 13])  # corner frequencies\nbb_s, aa_s = signal.butter(4, om_c, btype='bandpass', analog=True, output='ba')\nbb_z, aa_z = signal.bilinear(bb_s, aa_s, fs)\n\nw_z, H_z = signal.freqz(bb_z, aa_z)  # frequency response of digitial filter\nw_s, H_s = signal.freqs(bb_s, aa_s, worN=w_z*fs)  # analog filter response\n\nf_z, f_s = w_z * fs / (2*np.pi), w_s / (2*np.pi)\nHz_dB, Hs_dB = (20*np.log10(np.abs(H_).clip(1e-10)) for H_ in (H_z, H_s))\nfg0, ax0 = plt.subplots()\nax0.set_title(\"Frequency Response of 4-th order Bandpass Filter\")\nax0.set(xlabel='Frequency $f$ in Hertz', ylabel='Magnitude in dB',\n        xlim=[f_z[1], fs/2], ylim=[-200, 2])\nax0.semilogx(f_z, Hz_dB, alpha=.5, label=r'$|H_z(e^{j 2 \\pi f})|$')\nax0.semilogx(f_s, Hs_dB, alpha=.5, label=r'$|H_s(j 2 \\pi f)|$')\nax0.legend()\nax0.grid(which='both', axis='x')\nax0.grid(which='major', axis='y')\nplt.show()",
            "outputs": []
        },
        {
            "id": "6acc4427",
            "cell_type": "markdown",
            "source": "The difference in the higher frequencies shown in the plot is caused by an effect\ncalled \"frequency warping\". [1] describes a method called \"pre-warping\" to\nreduce those deviations.\n",
            "metadata": {}
        }
    ]
}