{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "edd921e2",
            "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": "d16e1dbb",
            "cell_type": "markdown",
            "source": "Design and plot notching comb filter at 20 Hz for a\nsignal sampled at 200 Hz, using quality factor Q = 30\n",
            "metadata": {}
        },
        {
            "id": "47a20d25",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import signal\nimport matplotlib.pyplot as plt\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "f2dc2738",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "fs = 200.0  # Sample frequency (Hz)\nf0 = 20.0  # Frequency to be removed from signal (Hz)\nQ = 30.0  # Quality factor\n# Design notching comb filter\nb, a = signal.iircomb(f0, Q, ftype='notch', fs=fs)",
            "outputs": []
        },
        {
            "id": "0e07dfe9",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "# Frequency response\nfreq, h = signal.freqz(b, a, fs=fs)\nresponse = abs(h)\n# To avoid divide by zero when graphing\nresponse[response == 0] = 1e-20\n# Plot\nfig, ax = plt.subplots(2, 1, figsize=(8, 6), sharex=True)\nax[0].plot(freq, 20*np.log10(abs(response)), color='blue')\nax[0].set_title(\"Frequency Response\")\nax[0].set_ylabel(\"Amplitude [dB]\", color='blue')\nax[0].set_xlim([0, 100])\nax[0].set_ylim([-30, 10])\nax[0].grid(True)\nax[1].plot(freq, (np.angle(h)*180/np.pi+180)%360 - 180, color='green')\nax[1].set_ylabel(\"Phase [deg]\", color='green')\nax[1].set_xlabel(\"Frequency [Hz]\")\nax[1].set_xlim([0, 100])\nax[1].set_yticks([-90, -60, -30, 0, 30, 60, 90])\nax[1].set_ylim([-90, 90])\nax[1].grid(True)\nplt.show()",
            "outputs": []
        },
        {
            "id": "11c4735f",
            "cell_type": "markdown",
            "source": "Design and plot peaking comb filter at 250 Hz for a\nsignal sampled at 1000 Hz, using quality factor Q = 30\n",
            "metadata": {}
        },
        {
            "id": "3a309a91",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "fs = 1000.0  # Sample frequency (Hz)\nf0 = 250.0  # Frequency to be retained (Hz)\nQ = 30.0  # Quality factor\n# Design peaking filter\nb, a = signal.iircomb(f0, Q, ftype='peak', fs=fs, pass_zero=True)",
            "outputs": []
        },
        {
            "id": "b848b89f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "# Frequency response\nfreq, h = signal.freqz(b, a, fs=fs)\nresponse = abs(h)\n# To avoid divide by zero when graphing\nresponse[response == 0] = 1e-20\n# Plot\nfig, ax = plt.subplots(2, 1, figsize=(8, 6), sharex=True)\nax[0].plot(freq, 20*np.log10(np.maximum(abs(h), 1e-5)), color='blue')\nax[0].set_title(\"Frequency Response\")\nax[0].set_ylabel(\"Amplitude [dB]\", color='blue')\nax[0].set_xlim([0, 500])\nax[0].set_ylim([-80, 10])\nax[0].grid(True)\nax[1].plot(freq, (np.angle(h)*180/np.pi+180)%360 - 180, color='green')\nax[1].set_ylabel(\"Phase [deg]\", color='green')\nax[1].set_xlabel(\"Frequency [Hz]\")\nax[1].set_xlim([0, 500])\nax[1].set_yticks([-90, -60, -30, 0, 30, 60, 90])\nax[1].set_ylim([-90, 90])\nax[1].grid(True)\nplt.show()",
            "outputs": []
        }
    ]
}