{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "6e098ac3",
            "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": "8ac009b0",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy import special\nimport matplotlib.pyplot as plt",
            "outputs": []
        },
        {
            "id": "c08942f6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.linspace(-8*np.pi, 8*np.pi, num=201)\nplt.figure(figsize=(8, 8));\nfor idx, n in enumerate([2, 3, 4, 9]):\n    plt.subplot(2, 2, idx+1)\n    plt.plot(x, special.diric(x, n))\n    plt.title('diric, n={}'.format(n))\nplt.show()",
            "outputs": []
        },
        {
            "id": "aa273b3d",
            "cell_type": "markdown",
            "source": "The following example demonstrates that `diric` gives the magnitudes\n(modulo the sign and scaling) of the Fourier coefficients of a\nrectangular pulse.\n\nSuppress output of values that are effectively 0:\n",
            "metadata": {}
        },
        {
            "id": "ae24bb6d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.set_printoptions(suppress=True)",
            "outputs": []
        },
        {
            "id": "2cc7b20c",
            "cell_type": "markdown",
            "source": "Create a signal `x` of length `m` with `k` ones:\n",
            "metadata": {}
        },
        {
            "id": "8b25ac88",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "m = 8\nk = 3\nx = np.zeros(m)\nx[:k] = 1",
            "outputs": []
        },
        {
            "id": "80bdd363",
            "cell_type": "markdown",
            "source": "Use the FFT to compute the Fourier transform of `x`, and\ninspect the magnitudes of the coefficients:\n",
            "metadata": {}
        },
        {
            "id": "b6a6d496",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "np.abs(np.fft.fft(x))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 3.        ,  2.41421356,  1.        ,  0.41421356,  1.        ,\n        0.41421356,  1.        ,  2.41421356])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "32675a75",
            "cell_type": "markdown",
            "source": "Now find the same values (up to sign) using `diric`. We multiply\nby `k` to account for the different scaling conventions of\n`numpy.fft.fft` and `diric`:\n",
            "metadata": {}
        },
        {
            "id": "ba6df005",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "theta = np.linspace(0, 2*np.pi, m, endpoint=False)\nk * special.diric(theta, k)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 3.        ,  2.41421356,  1.        , -0.41421356, -1.        ,\n       -0.41421356,  1.        ,  2.41421356])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}