{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "e8c48c3f",
            "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": "c67e0244",
            "cell_type": "markdown",
            "source": "The following two plots illustrate the effect of the parameter `center_bins`:\nThe grid lines represent the three time and the four frequency values of the\nSTFT.\nThe left plot, where ``(t0, t1, f0, f1) = (0, 3, 0, 4)`` is passed as parameter\n``extent`` to `~matplotlib.pyplot.imshow`, shows the standard behavior of the\ntime and frequency values being at the lower edge of the corrsponding bin.\nThe right plot, with ``(t0, t1, f0, f1) = (-0.5, 2.5, -0.5, 3.5)``, shows that\nthe bins are centered over the respective values when passing\n``center_bins=True``.\n",
            "metadata": {}
        },
        {
            "id": "035ce3f5",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.signal import ShortTimeFFT\n\nn, m = 12, 6\nSFT = ShortTimeFFT.from_window('hann', fs=m, nperseg=m, noverlap=0)\nSxx = SFT.stft(np.cos(np.arange(n)))  # produces a colorful plot\n\nfig, axx = plt.subplots(1, 2, tight_layout=True, figsize=(6., 4.))\nfor ax_, center_bins in zip(axx, (False, True)):\n    ax_.imshow(abs(Sxx), origin='lower', interpolation=None, aspect='equal',\n               cmap='viridis', extent=SFT.extent(n, 'tf', center_bins))\n    ax_.set_title(f\"{center_bins=}\")\n    ax_.set_xlabel(f\"Time ({SFT.p_num(n)} points, Δt={SFT.delta_t})\")\n    ax_.set_ylabel(f\"Frequency ({SFT.f_pts} points, Δf={SFT.delta_f})\")\n    ax_.set_xticks(SFT.t(n))  # vertical grid line are timestamps\n    ax_.set_yticks(SFT.f)  # horizontal grid line are frequency values\n    ax_.grid(True)\nplt.show()",
            "outputs": []
        },
        {
            "id": "9ca47de3",
            "cell_type": "markdown",
            "source": "Note that the step-like behavior with the constant colors is caused by passing\n``interpolation=None`` to `~matplotlib.pyplot.imshow`.\n",
            "metadata": {}
        }
    ]
}