{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "74f8b4d1",
            "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": "81c6b230",
            "cell_type": "markdown",
            "source": "Design an analog filter and plot its frequency response, showing the\ncritical points:\n",
            "metadata": {}
        },
        {
            "id": "041ada46",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import signal\nimport matplotlib.pyplot as plt\nimport numpy as np",
            "outputs": []
        },
        {
            "id": "6d94624a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b, a = signal.ellip(4, 5, 40, 100, 'low', analog=True)\nw, h = signal.freqs(b, a)\nplt.semilogx(w, 20 * np.log10(abs(h)))\nplt.title('Elliptic filter frequency response (rp=5, rs=40)')\nplt.xlabel('Frequency [rad/s]')\nplt.ylabel('Amplitude [dB]')\nplt.margins(0, 0.1)\nplt.grid(which='both', axis='both')\nplt.axvline(100, color='green') # cutoff frequency\nplt.axhline(-40, color='green') # rs\nplt.axhline(-5, color='green') # rp\nplt.show()",
            "outputs": []
        },
        {
            "id": "33866936",
            "cell_type": "markdown",
            "source": "Generate a signal made up of 10 Hz and 20 Hz, sampled at 1 kHz\n",
            "metadata": {}
        },
        {
            "id": "f80c023f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "t = np.linspace(0, 1, 1000, False)  # 1 second\nsig = np.sin(2*np.pi*10*t) + np.sin(2*np.pi*20*t)\nfig, (ax1, ax2) = plt.subplots(2, 1, sharex=True)\nax1.plot(t, sig)\nax1.set_title('10 Hz and 20 Hz sinusoids')\nax1.axis([0, 1, -2, 2])",
            "outputs": []
        },
        {
            "id": "ff14a211",
            "cell_type": "markdown",
            "source": "Design a digital high-pass filter at 17 Hz to remove the 10 Hz tone, and\napply it to the signal. (It's recommended to use second-order sections\nformat when filtering, to avoid numerical error with transfer function\n(``ba``) format):\n",
            "metadata": {}
        },
        {
            "id": "93c20824",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "sos = signal.ellip(8, 1, 100, 17, 'hp', fs=1000, output='sos')\nfiltered = signal.sosfilt(sos, sig)\nax2.plot(t, filtered)\nax2.set_title('After 17 Hz high-pass filter')\nax2.axis([0, 1, -2, 2])\nax2.set_xlabel('Time [s]')\nplt.tight_layout()\nplt.show()",
            "outputs": []
        }
    ]
}