{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "tutorial:fft",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\newcommand{\\IC}{{\\mathbb{C}}}  % set of complex numbers\n\\newcommand{\\IN}{{\\mathbb{N}}}  % set of natural numbers\n\\newcommand{\\IR}{{\\mathbb{R}}}  % set of real numbers\n\\newcommand{\\IZ}{{\\mathbb{Z}}}  % set of integers\n\\newcommand{\\jj}{{\\mathbb{j}}}  % imaginary unit\n\\newcommand{\\e}{\\operatorname{e}}  % Euler's number\n\\newcommand{\\dd}{\\operatorname{d}} % infinitesimal operator\n\\newcommand{\\abs}[1]{\\left|#1\\right|} % absolute value\n\\newcommand{\\conj}[1]{\\overline{#1}} % complex conjugate\n\\newcommand{\\conjT}[1]{\\overline{#1^T}} % transposed complex conjugate\n\\newcommand{\\inv}[1]{\\left(#1\\right)^{\\!-1}} % inverse\n\\newcommand{\\rect}{\\operatorname{rect}}  % rect or boxcar function\n\\newcommand{\\sinc}{\\operatorname{sinc}}  % sinc(t) := sin(pi*t) / (pi*t)\n% overwrite macros:\n\\renewcommand{\\Re}{\\operatorname{Re}}  % real part of a complex number\n\\renewcommand{\\Im}{\\operatorname{Im}}  % imaginary part of a complex number\n% Since the physics package is not loaded, we define the macros ourselves:\n\\newcommand{\\vb}[1]{\\mathbf{#1}} % vectors  are bold\n\\newcommand{\\mat}[1]{\\mathrm{#1}} % matrices are upright\n%\n% Abbreviations of matrices and vectors :\n\\newcommand{\\mF}{\\mat{F}}  % matrix with DFT coefficients\n\\newcommand{\\mI}{\\mat{I}}  % unity matrix"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Fourier analysis is a method for expressing a function as a sum of periodic components, and for recovering the signal from those components. When both the function and its Fourier transform are replaced with discretized counterparts, it is called the discrete Fourier transform (DFT). The DFT has become a mainstay of numerical computing in part because of a very fast algorithm for computing it, called the Fast Fourier Transform (FFT), which was known to Gauss (1805) and was brought to light in its current form by Cooley and Tukey "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Press et al. "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " provide an accessible introduction to Fourier analysis and its applications."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This chapter is structured as follows: The first section defines the discrete Fourier transform and presents its key properties. The second section discusses the relationship to continuous Fourier series and introduces various forms of its Fourier transform. Then practical implications, which mainly results from the DFT's periodicity properties, are discussed in the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "tutorial_FFT_Caveats",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:fft"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section. The remaining sections give definitions of higher-dimensional DFTs, discrete sine and cosine transforms as well as the Hankel transform."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Discrete Fourier Transforms ("
        },
        {
          "__type": "CrossRef",
          "__tag": 4002,
          "value": "scipy.fft",
          "reference": {
            "__type": "LocalRef",
            "__tag": 4022,
            "kind": "module",
            "path": "scipy.fft"
          },
          "kind": "module"
        },
        {
          "__type": "Text",
          "__tag": 4046,
          "value": ")"
        }
      ],
      "level": 0,
      "target": "tutorial_FFT"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The discrete Fourier Transform "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "3"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a one-to-one mapping between two complex-valued sequences of length "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The mappings between "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x[k], X[l]\\in\\IC"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k, l \\in\\{0, \\ldots, N-1\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", are defined by"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "X[l] = \\frac{1}{\\gamma} \\sum_{k=0}^{N-1} x[n] \\e^{-\\jj 2 \\pi l k / N}\\,,\\qquad\nx[k] = \\frac{\\gamma}{N}\\sum_{l=0}^{N-1} X[l] \\e^{\\jj 2 \\pi k l / N}\\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "which are implemented by the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " / "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ifft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:ifft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " functions. "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\gamma"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a normalization constant, which is set by the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "norm",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " parameter. It may have the values "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='backward'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", default), "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='forward'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), or "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sqrt{N}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ")."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "X[l]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be continued periodically outside its domain "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\{0, \\ldots, N-1\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". I.e., "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "X[l+pN] = X[l]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p\\in\\IZ"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "  when "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "X[l]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is calculated with Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This allows to define the DFT over shifted coefficients, e.g., using "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "l\\in\\{-N//2, \\ldots, (N-1)-N//2\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The same holds for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ": When determined with Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x[k + pN] = x[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "p \\in\\IZ"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is true."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This DFT can be rewritten in vector-matrix form as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\underbrace{\\begin{bmatrix} X[0]\\\\ X[1]\\\\ \\vdots\\\\ X[N-1] \\end{bmatrix}}_{=:\\vb{X}}\n  = \\frac{1}{\\gamma}\\underbrace{\\begin{bmatrix}\n     \\e^{-\\jj 2 \\pi \\cdot 0 \\cdot 0 / N} & \\cdots & \\e^{-\\jj 2 \\pi \\cdot 0 \\cdot (N-1) / N}\\\\\n     \\vdots & \\ddots & \\vdots\\\\\n     \\e^{-\\jj 2 \\pi (N-1) \\cdot 0 / N} & \\cdots & \\e^{-\\jj 2 \\pi (N-1) (N-1) / N}\n   \\end{bmatrix}}_{=:\\mF}\n\\underbrace{\\begin{bmatrix} x[0]\\\\ x[1]\\\\ \\vdots\\\\ x[N-1] \\end{bmatrix}}_{=:\\vb{x}}\\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with the matrix "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mF\\in\\IC^{N\\times N}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " being symmetric, i.e., "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mF^T=\\mF"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". It has the elements "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "F[l, k] = \\exp(-\\jj2\\pi l k / N)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and allows the DFT and its inverse to be expressed as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\vb{X} = \\frac{1}{\\gamma}\\mF\\,\\vb{x}\\,, \\qquad\n\\vb{x} = \\frac{\\gamma}{N}\\conj{\\mF}\\,\\vb{X}\n       = \\frac{\\gamma}{N}\\conjT{\\mF}\\,\\vb{X} \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\conjT{\\mF}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " being the conjugate transpose of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mF"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". It can be shown that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\conjT{\\mF}\\mF = N\\mI"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " holds and thus "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mF^{-1} = \\conjT{\\mF}/N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which makes it straightforward to verify that the two relations of Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are inverses of each other. The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "linalg",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.linalg"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides the function "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "dft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.linalg._special_matrices:dft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to calculate the matrix "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mF / \\gamma"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> from scipy.linalg import dft\n>>> from scipy.fft import fft\n>>> np.set_printoptions(precision=2, suppress=True)  # for compact output\n...\n>>> dft(4)\narray([[ 1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j],\n       [ 1.+0.j,  0.-1.j, -1.-0.j, -0.+1.j],\n       [ 1.+0.j, -1.-0.j,  1.+0.j, -1.-0.j],\n       [ 1.+0.j, -0.+1.j, -1.-0.j,  0.-1.j]])\n>>> fft(np.eye(4)) # produces the same matrix\narray([[ 1.-0.j,  1.+0.j,  1.-0.j,  1.-0.j],\n       [ 1.-0.j,  0.-1.j, -1.-0.j,  0.+1.j],\n       [ 1.-0.j, -1.+0.j,  1.-0.j, -1.-0.j],\n       [ 1.-0.j,  0.+1.j, -1.-0.j,  0.-1.j]])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This notation makes it also easy to show that the DFT changes the inner product (or scalar product) only by the scaling factor "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N/\\gamma^2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". I.e., expressing the inner product of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\vb{X}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\vb{Y}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in terms of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\vb{x}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\vb{y}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " gives"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\langle \\vb{X}, \\vb{Y}\\rangle := \\conjT{\\vb{X}}\\vb{Y} =\n \\conjT{\\big(\\frac{1}{\\gamma}\\mF\\,\\vb{x}\\big)}\n        \\big(\\frac{1}{\\gamma}\\mF\\,\\vb{y}\\big) =\n\\frac{1}{\\gamma^2}\\conjT{\\vb{x}} \\conjT{\\mF} \\mF \\vb{y} =\n\\frac{N}{\\gamma^2}\\conjT{\\vb{x}} \\vb{y} =\n\\frac{N}{\\gamma^2} \\langle \\vb{x}, \\vb{y}\\rangle\\,."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This illustrates that the DFT is a unitary transform for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\gamma = \\sqrt{N}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The sums of the absolute squares are a special case, i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\sum_{l=0}^{N-1} \\abs{X[l]}^2 =\n\\langle \\vb{X}, \\vb{X}\\rangle =\n\\frac{N}{\\gamma^2} \\langle \\vb{x}, \\vb{x}\\rangle =\n\\frac{N}{\\gamma^2} \\sum_{k=0}^{N-1} \\abs{x[k]}^2\\,."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that the sum of the unsquared values can be retrieved from the zeroth DFT component, i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "X[0] = \\frac{1}{\\gamma} \\sum_{k=0}^{N-1} x[n]\\,,\\qquad\nx[0] = \\frac{\\gamma}{N}\\sum_{l=0}^{N-1} X[l]\\,."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The circular convolution of two sequences of length "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "z[k] = x[k] \\ast y[k] := \\sum_{q=0}^{N-1} x[q]\\, y\\big[(k-q) \\bmod N\\big]"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "can be expressed as a multiplication of their DFTs and vice versa, i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\begin{align}\n   z[k] &= x[k] \\ast y[k] & \\Leftrightarrow &&\n   Z[l] &= \\gamma\\, X[l]\\, Y[l] \\,,\\\\\n   Z[l] &= X[l] \\ast Y[l]  & \\Leftrightarrow &&\n   z[l] &= \\frac{N}{\\gamma} x[k] \\,y[k] \\,.\n\\end{align}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here, the circular convolution is defined over finite length sequences, whereas in literature it is often defined over infinite length sequences. For sufficiently large "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (roughly: "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N > 500"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), it is typically computationally more efficient to use this multiplication together with the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " / "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "ifft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:ifft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " functions than to calculate the convolution directly. Note that "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "convolve",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.signal._signaltools:convolve"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fftconvolve",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.signal._signaltools:fftconvolve"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "numpy.convolve",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "?",
                "kind": "module",
                "path": "numpy:convolve"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " implement the non-circular convolution by using appropriate zero-padding before applying the FFT."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "The Discrete Fourier Transform"
        }
      ],
      "level": 1,
      "target": "tutorial_FFT_DFT"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A Fourier series"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "z(t) = \\frac{\\gamma}{N}\n         \\sum_{l=-N_2}^{N_2} c_l\\, \\e^{\\jj2\\pi l t/\\tau}\\,, \\qquad t\\in[0, \\tau]\\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N=2N_2+1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " complex-valued Fourier coefficients "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "c_l"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " represents a closed curve "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z: [0, \\tau] \\mapsto \\IC"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Determining the values of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " equidistant samples with sampling interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "T := \\tau / N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "z[k] := z(kT) = \\frac{\\gamma}{N}\n    \\sum_{l=-N_2}^{N_2} c_l\\, \\e^{\\jj2\\pi l k / N}\\,, \\qquad\n    k \\in \\{0,\\ldots,N-1\\}\\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "may be interpreted as a shifted version the inverse DFT of Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Since the (inverse) DFT is a one-to-one mapping, the "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " samples are an alternative representation of the "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " Fourier coefficients. Here, the scaling factor "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\gamma/N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " exists only to ensure notational consistency with Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The following example produces a closed curve "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " resembling the letter ω by utilizing a Fourier series: The Fourier coefficients are calculated by the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function from 31 provided samples. In the plot, the dots represent the samples "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and the coloration of the line the value of the parameter "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "t\\in[0, 1]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Since the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function expects indexes "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\{0,\\ldots,N-1\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " but "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is defined on the indexes "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\{-N_2,\\ldots,N_2\\}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fftshift",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._helper:fftshift"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function is utilized."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Remarks:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "That the plot is a closed curve is due to the periodic nature of Fourier series,   i.e., "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z(t+p\\tau) = z(t)\\,,\\ p\\in\\IZ"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". As a consequence, a given closed curve   can be represented by various Fourier series and with that by various sets of   samples. E.g., increasing the number of samples can be achieved by adding zero-valued   Fourier coefficients to their DFT and then calculating the corresponding inverse DFT.   This technique is used in the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "resample",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.signal._signaltools:resample"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A Fourier series is a decomposition of a complex-valued closed curve into circular   closed curves with various frequencies: The "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "l"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "-th term "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z_l(t) :=   \\tfrac{\\gamma}{N} c_l\\, \\exp(\\jj2\\pi l t / \\tau)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " may be interpreted as a circular   curve centered at the origin with radius "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "|\\gamma c_l / N|"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and starting point   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z_l(0)= \\gamma c_l / N"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". For "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "t\\in[0,\\tau]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", it cycles the circle   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "l"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " times in counterclockwise direction if "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "l > 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or clockwise direction   if "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "l < 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". The number of cycles per unit interval, i.e, "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "f_l := l /   \\tau"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", is usually called the frequency of "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z_l(t)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (having the same sign as   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "l"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "). The "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "fftfreq",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._helper:fftfreq"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " function determines those corresponding   frequencies for the Fourier coefficients."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Especially in signal processing, "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "t"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " frequently represents time. Hence, the   sample values "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z[k]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with their associated sample times "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "t[k] = k T"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are   commonly referred to as being in the so-called \"time-domain\", whereas coefficients   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "c_l"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with their associated frequency values "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "f_l = l \\Delta f"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "\\Delta f := 1/\\tau = 1 / (NT)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", are referred as to being in the so-called   \"frequency domain\" or \"Fourier domain\"."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If only real-valued curves are of interest, then   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "\\Im\\{z(t)\\} = \\big(z(t) - \\conj{z(t)}\\big)/2\\jj \\equiv 0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " holds. This is   equivalent to "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "z(t) = \\conj{z(t)}"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " as well as to "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "c_l = \\conj{c_{-l}}"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ".   As a consequence, for DFTs with real-valued inputs only the non-negative DFT   coefficients need to be calculated. This is implemented by the   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "rfft",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._basic:rfft"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " / "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "irfft",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._basic:irfft"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " / "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "rfftfreq",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._helper:rfftfreq"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   functions."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Besides the DFT, other variations for calculating a Fourier transform of a Fourier series exist. The important case of extending the domain from the fixed interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[0, \\tau]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to the real axis "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\IR"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is discussed in the following: When assuming "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t)\\equiv 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " holds for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "t \\not\\in[0, \\tau]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", it is straightforward to apply the continuous Fourier transform to the Fourier Series of Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_FSeries"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Z(f) &:= \\int_\\IR z(t)\\, \\e^{-\\jj2\\pi t f} \\dd t\n  = \\frac{\\gamma}{N}\\sum_{l=-N_2}^{N_2}\n           c_l \\int_0^\\tau \\exp\\!\\big(\\jj2\\pi (l - f\\tau) t / \\tau\\big)\\,  \\dd t \\\\\n &=  \\frac{\\gamma}{N} \\sum_{l=-N_2}^{N_2}\n                 c_l\\frac{\\tau (\\e^{\\jj2\\pi (l - f\\tau)} - 1)}{\\jj2\\pi (l - f\\tau)}\n  = \\tau \\frac{\\gamma}{N}\\sum_{l=-N_2}^{N_2}\n                               c_l\\, \\sinc(l - f\\tau)\\, \\e^{\\jj\\pi (l - f\\tau)} \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\sinc(f) := \\sin(\\pi f) / (\\pi f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Note that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z(f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is continuous and its support extends over the complete real axis. The DFT may be interpreted as sampling the continuous Fourier transform due to"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Z(l \\Delta f) = \\tau\\frac{\\gamma}{N} c_l = T \\gamma c_l\n                                                     \\quad\\text{ for }\\quad l\\in\\IZ"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "being true. When continuing "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " periodically outside the interval "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "[0, \\tau]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "z_p(t) = \\sum_{p\\in\\IZ} z(t + p\\tau) \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "then the continuous Fourier transform can be expressed as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Z_p(f) = \\frac{\\gamma}{N}\\sum_{l=-N_2}^{N_2} c_l\\, \\delta(f- l \\Delta f) \\,,\\qquad\n         \\Delta f = 1 / \\tau = 1/ (NT) \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "where "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\delta(.)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " denotes the Dirac delta function. Note that "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z_p(f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is only non-zero at multiples of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Delta f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Furthermore, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z_p(f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is bandlimited, i.e., "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z_p(f)\\equiv 0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "|f| > N \\Delta f / 2 = 1 / (2T)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". In signal processing, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f_S := 1/T"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is usually referred to as sampling frequency and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f_\\text{Ny} := f_S / 2 = 1 / (2T)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is called the Nyquist frequency."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The so-called \"discrete-time Fourier transform\" (DTFT) "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of the sampled signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z_p[k] := z_p(kT)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is defined as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Z_p^\\text{DTFT}(f) := \\sum_{k\\in\\IZ}  z_p[k] \\e^{-2\\jj\\pi f k T}\n\\quad\\text{ or }\\quad\nZ_p^\\text{DTFT}(\\jj\\Omega) := \\sum_{k\\in\\IZ}  z_p[k] \\e^{-\\jj k \\Omega}\\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Omega:= 2\\pi f/f_S = 2\\pi f T"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The convention of using the normalized frequency "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Omega"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " instead of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is common in signal processing. "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z_p^\\text{DTFT}(f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a continuous function in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with a periodicity of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f_S"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Due to "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "z_p[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " being periodic in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", it can be expressed in terms of the Fourier coefficients as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "Z_p^\\text{DTFT}(f) = \\frac{\\gamma}{N T} \\sum_{l=-N_2}^{N_2} \\sum_{p\\in\\IZ}\n                                  c_l\\, \\delta(f - \\frac{l}{N T} - \\frac{p}{T})\n                   = \\frac{1}{T} \\sum_{p\\in\\IZ}  Z_p(f - \\frac{p}{T}) \\,."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Hence, the DTFT may be interpreted as a periodic continuation of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "Z_p(f)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", i.e., as the periodic continuation in "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of the Fourier transform of the continuous-time periodic signal."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A brief introduction about analyzing the spectral properties of sampled signals can be found in the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "tutorial_SpectralAnalysis",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Fourier Series and the DFT"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This subsection briefly discusses practical implications of the periodicity properties of Fourier transforms and provides recommendations for improving computational efficiency."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Caveats"
        }
      ],
      "level": 1,
      "target": "tutorial_FFT_Caveats"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When working with sampled signals, it is typically assumed that the underlying continuous signals are represented by Fourier series. The circumstance that to accurately model signals with discontinuities requires many Fourier coefficients is known as Gibbs phenomenon. Since Fourier series are inherently periodic, representing non-periodic signals introduces artificial discontinuities. A common technique to make non-periodic signals \"more\" periodic is subtracting a best-fit polynomial. "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "detrend",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.signal._signaltools:detrend"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be used to subtract a signal's mean (\\ "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "th"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " order polynomial) or linear trend (\\ "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "st"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " order polynomial). NumPy's "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "Polynomial",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "?",
                "kind": "module",
                "path": "numpy.polynomial.polynomial:Polynomial"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " class provides means to "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fit",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "numpy",
                "version": "?",
                "kind": "module",
                "path": "numpy.polynomial._polybase:ABCPolyBase.fit"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " higher order polynomials."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The following example illustrates the effect of removing the linear trend from a noisy signal on its spectrum: The signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is represented by "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N=1000"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " samples with a sampling interval of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "T=0.1\\,"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "ms. The first row depicts "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (with linear trend) and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_d(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (with removed linear trend). To determine the periodic components, a magnitude spectrum of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_d(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is calculated and drawn is second and third row."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The signal's trend manifests as a decreasing slope in the spectrum's low-frequency part. Removing the linear trend steepens this slope significantly, making the peaks at "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "200"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "300"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "400\\,"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Hz much better distinguishable. These peaks, which correspond to the sinusoidal components of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x(t)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", would have a magnitude of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "0.5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in a noise- and trend-free signal."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that detrending a signal does not necessarily improve its spectrum. I.e., periodic components whose frequencies are not integer multiples of the frequency resolution "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\Delta f"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " produce a trend that should not be removed. More information on calculating and interpreting spectra can be found in the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "tutorial_SpectralAnalysis",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Periodicity in the Time Domain"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The following plot compares "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "rfft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:rfft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " representations of two signals made up of an odd number ("
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N=5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", left column) and an even number of samples ("
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N=4"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", right column). The real-valued input signals were chosen in such a way so that their Fourier transforms are real-valued, i.e., "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x[k] = x[N-k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The first row shows the DFTs of Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_DFT"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with its non-negative frequencies. The gray stems represent the periodic continuation to the left and to the right. The center row shows the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with the shifted frequencies produced by "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fftfreq",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._helper:fftfreq"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where the two highest frequencies are shifted to the negative side. The last row depicts the one-sided "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "rfft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:rfft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which produces only the non-negative frequencies of the (two-sided) "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._basic:fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This plot illustrates the following two aspects:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "For an odd number of samples (here: "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "N=5"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "), "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "fftfreq",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._helper:fftfreq"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " produces   an equal number of positive and negative frequencies, i.e. "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "[-2, -1, 0, 1, 2]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". For   an even number of samples (here: "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "N=4"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "), it would be valid to have either the   frequencies,  "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "[-2, -1, 0, 1]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " or the frequencies "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "[-1, 0, 1, 2]"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " due to the FFT   values at "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "f = \\pm2\\,"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Hz being identical. By convention,   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "fftfreq",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._helper:fftfreq"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " places the Nyquist frequency   "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "f_\\text{Ny} = \\Delta f\\, N/2 = 2\\,"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Hz on the negative side."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Here, the "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "rfft",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._basic:rfft"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " values for input lengths of "
                    },
                    {
                      "__type": "InlineMath",
                      "__tag": 4057,
                      "value": "N=4,5"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are equal   in spite of the input signals being different. This illustrates that the number   of signal samples "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "N",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " need to be passed to "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "irfft",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "?",
                        "kind": "module",
                        "path": "scipy.fft._basic:irfft"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " to be able   reconstruct the original signal, e.g.:"
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": ">>> import numpy as np\n>>> from scipy.fft import fft, irfft, rfft\n...\n>>> x = np.array([4, 1, 0, 1])  # n = 4\n>>> X = rfft(x)\n>>> y0, y1 = irfft(X, n=4), irfft(X, n=5)\n>>> np.allclose(y0, x)\nTrue\n>>> len(y1) == len(x)  # signals differ\nFalse\n>>> np.allclose(rfft(y1), rfft(x))  # one-sided FFTs are equal\nTrue",
                  "execution_status": null,
                  "out": ""
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Periodicity in the Frequency Domain"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The efficiency of the FFT algorithm depends on how well the number of input samples "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be factored into small prime factors. I.e., it is slowest if "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is prime and fastest if "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a power of 2. The "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides the functions "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "prev_fast_len",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._helper:prev_fast_len"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "next_fast_len",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._helper:next_fast_len"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for determining adequate input lengths for fast execution."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Furthermore, the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fft",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.fft"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " module provides also the context manager "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "set_workers",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._duccfft.helper:set_workers"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to set the maximum number of allowed threads when calculating the FFT. Note that some third-party FFT libraries provide SciPy backends, which can be activated by utilizing "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "set_backend",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "?",
                "kind": "module",
                "path": "scipy.fft._backend:set_backend"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Speed Considerations"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The functions "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "fft2",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "ifft2",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " provide 2-D FFT and IFFT, respectively. Similarly, "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "fftn",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "ifftn",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " provide N-D FFT, and IFFT, respectively."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For real-input signals, similarly to "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "rfft",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", we have the functions "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "rfft2",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "irfft2",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for 2-D real transforms; "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "rfftn",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "irfftn",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for N-D real transforms."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The example below demonstrates a 2-D IFFT and plots the resulting (2-D) time-domain signals."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.fft import ifftn\n>>> import matplotlib.pyplot as plt\n>>> import matplotlib.cm as cm\n>>> import numpy as np\n>>> N = 30\n>>> f, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(2, 3, sharex='col', sharey='row')\n>>> xf = np.zeros((N,N))\n>>> xf[0, 5] = 1\n>>> xf[0, N-5] = 1\n>>> Z = ifftn(xf)\n>>> ax1.imshow(xf, cmap=cm.Reds)\n>>> ax4.imshow(np.real(Z), cmap=cm.gray)\n>>> xf = np.zeros((N, N))\n>>> xf[5, 0] = 1\n>>> xf[N-5, 0] = 1\n>>> Z = ifftn(xf)\n>>> ax2.imshow(xf, cmap=cm.Reds)\n>>> ax5.imshow(np.real(Z), cmap=cm.gray)\n>>> xf = np.zeros((N, N))\n>>> xf[5, 10] = 1\n>>> xf[N-5, N-10] = 1\n>>> Z = ifftn(xf)\n>>> ax3.imshow(xf, cmap=cm.Reds)\n>>> ax6.imshow(np.real(Z), cmap=cm.gray)\n>>> plt.show()",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Figure",
          "__tag": 4024,
          "value": {
            "__type": "RefInfo",
            "__tag": 4000,
            "module": "scipy",
            "version": "2.0.0.dev0+git20260907.41eeb59",
            "kind": "assets",
            "path": "fig-plot-0.png"
          }
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "2- and N-D discrete Fourier transforms"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy provides a DCT with the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "dct",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a corresponding IDCT with the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "idct",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". There are 8 types of the DCT "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "; however, only the first 4 types are implemented in SciPy. \"The\" DCT generally refers to DCT type 2, and \"the\" Inverse DCT generally refers to DCT type 3. In addition, the DCT coefficients can be normalized differently (for most types, scipy provides "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "ortho"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). Two parameters of the dct/idct function calls allow setting the DCT type and coefficient normalization."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For a single dimension array "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "x",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "dct(x, norm='ortho')"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is equal to MATLAB's \"dct(x)\"."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Discrete Cosine Transforms"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy uses the following definition of the unnormalized DCT-I ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = x_0 + (-1)^k x_{N-1} + 2\\sum_{n=1}^{N-2} x[n]\n\\cos\\left(\\frac{\\pi nk}{N-1}\\right),\n\\qquad 0 \\le k < N."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that the DCT-I is only supported for input size > 1."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type I DCT"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy uses the following definition of the unnormalized DCT-II ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = 2 \\sum_{n=0}^{N-1} x[n] \\cos \\left({\\pi(2n+1)k \\over 2N} \\right)\n\\qquad 0 \\le k < N."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In case of the normalized DCT ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), the DCT coefficients "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "y[k]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " are multiplied by a scaling factor "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "f",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "f = \\begin{cases} \\sqrt{1/(4N)}, & \\text{if $k = 0$} \\\\    \\sqrt{1/(2N)},\n& \\text{otherwise} \\end{cases} \\, ."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "In this case, the DCT \"base functions\" "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\phi_k[n] = 2 f \\cos \\left({\\pi(2n+1)k \\over 2N} \\right)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " become orthonormal:"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "\\sum_{n=0}^{N-1} \\phi_k[n] \\phi_l[n] = \\delta_{lk}."
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type II DCT"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy uses the following definition of the unnormalized DCT-III ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = x_0 + 2 \\sum_{n=1}^{N-1} x[n] \\cos\\left({\\pi n(2k+1) \\over 2N}\\right)\n\\qquad 0 \\le k < N,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or, for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = {x_0\\over\\sqrt{N}} + {2\\over\\sqrt{N}} \\sum_{n=1}^{N-1} x[n]\n\\cos\\left({\\pi n(2k+1) \\over 2N}\\right) \\qquad 0 \\le k < N."
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type III DCT"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy uses the following definition of the unnormalized DCT-IV ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = 2 \\sum_{n=0}^{N-1} x[n] \\cos\\left({\\pi (2n+1)(2k+1) \\over 4N}\\right)\n\\qquad 0 \\le k < N,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or, for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = \\sqrt{2\\over N}\\sum_{n=0}^{N-1} x[n] \\cos\\left({\\pi (2n+1)(2k+1) \\over 4N}\\right)\n\\qquad 0 \\le k < N"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type IV DCT"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up to a factor of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "2N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The orthonormalized DCT-III is exactly the inverse of the orthonormalized DCT- II. The function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "idct",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " performs the mappings between the DCT and IDCT types, as well as the correct normalization."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The following example shows the relation between DCT and IDCT for different types and normalizations."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.fft import dct, idct\n>>> x = np.array([1.0, 2.0, 1.0, -1.0, 1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The DCT-II and DCT-III are each other's inverses, so for an orthonormal transform we return back to the original signal."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dct(dct(x, type=2, norm='ortho'), type=3, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Doing the same under default normalization, however, we pick up an extra scaling factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2N=10"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " since the forward transform is unnormalized."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dct(dct(x, type=2), type=3)\narray([ 10.,  20.,  10., -10.,  15.])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For this reason, we should use the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "idct",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " using the same type for both, giving a correctly normalized result."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> # Normalized inverse: no scaling factor\n>>> idct(dct(x, type=2), type=2)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Analogous results can be seen for the DCT-I, which is its own inverse up to a factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2(N-1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dct(dct(x, type=1, norm='ortho'), type=1, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])\n>>> # Unnormalized round-trip via DCT-I: scaling factor 2*(N-1) = 8\n>>> dct(dct(x, type=1), type=1)\narray([ 8. ,  16.,  8. , -8. ,  12.])\n>>> # Normalized inverse: no scaling factor\n>>> idct(dct(x, type=1), type=1)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "And for the DCT-IV, which is also its own inverse up to a factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dct(dct(x, type=4, norm='ortho'), type=4, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])\n>>> # Unnormalized round-trip via DCT-IV: scaling factor 2*N = 10\n>>> dct(dct(x, type=4), type=4)\narray([ 10.,  20.,  10., -10.,  15.])\n>>> # Normalized inverse: no scaling factor\n>>> idct(dct(x, type=4), type=4)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "DCT and IDCT"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The DCT exhibits the \"energy compaction property\", meaning that for many signals only the first few DCT coefficients have significant magnitude. Zeroing out the other coefficients leads to a small reconstruction error, a fact which is exploited in lossy signal compression (e.g. JPEG compression)."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The example below shows a signal x and two reconstructions ("
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_{20}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_{15}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") from the signal's DCT coefficients. The signal "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_{20}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is reconstructed from the first 20 DCT coefficients, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "x_{15}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is reconstructed from the first 15 DCT coefficients. It can be seen that the relative error of using 20 coefficients is still very small (~0.1%), but provides a five-fold compression rate."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.fft import dct, idct\n>>> import matplotlib.pyplot as plt\n>>> N = 100\n>>> t = np.linspace(0,20,N, endpoint=False)\n>>> x = np.exp(-t/3)*np.cos(2*t)\n>>> y = dct(x, norm='ortho')\n>>> window = np.zeros(N)\n>>> window[:20] = 1\n>>> yr = idct(y*window, norm='ortho')\n>>> sum(abs(x-yr)**2) / sum(abs(x)**2)\n0.0009872817275276098\n>>> plt.plot(t, x, '-bx')\n>>> plt.plot(t, yr, 'ro')\n>>> window = np.zeros(N)\n>>> window[:15] = 1\n>>> yr = idct(y*window, norm='ortho')\n>>> sum(abs(x-yr)**2) / sum(abs(x)**2)\n0.06196643004256714\n>>> plt.plot(t, yr, 'g+')\n>>> plt.legend(['x', '$x_{20}$', '$x_{15}$'])\n>>> plt.grid()\n>>> plt.show()",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Figure",
          "__tag": 4024,
          "value": {
            "__type": "RefInfo",
            "__tag": 4000,
            "module": "scipy",
            "version": "2.0.0.dev0+git20260907.41eeb59",
            "kind": "assets",
            "path": "fig-plot-1.png"
          }
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Example"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy provides a DST "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "dst",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and a corresponding IDST with the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "idst",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are, theoretically, 8 types of the DST for different combinations of even/odd boundary conditions and boundary offsets "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "7"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", only the first 4 types are implemented in SciPy."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Discrete Sine Transforms"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "DST-I assumes the input is odd around n=-1 and n=N. SciPy uses the following definition of the unnormalized DST-I ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = 2\\sum_{n=0}^{N-1} x[n]  \\sin\\left( \\pi {(n+1) (k+1)}\\over{N+1}\n\\right), \\qquad 0 \\le k < N."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note also that the DST-I is only supported for input size > 1. The (unnormalized) DST-I is its own inverse, up to a factor of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "2(N+1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type I DST"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "DST-II assumes the input is odd around n=-1/2 and even around n=N. SciPy uses the following definition of the unnormalized DST-II ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = 2 \\sum_{n=0}^{N-1} x[n]  \\sin\\left( {\\pi (n+1/2)(k+1)} \\over N\n\\right), \\qquad 0 \\le k < N."
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type II DST"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "DST-III assumes the input is odd around n=-1 and even around n=N-1. SciPy uses the following definition of the unnormalized DST-III ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = (-1)^k x[N-1] + 2 \\sum_{n=0}^{N-2} x[n] \\sin \\left( {\\pi\n(n+1)(k+1/2)} \\over N \\right), \\qquad 0 \\le k < N."
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type III DST"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy uses the following definition of the unnormalized DST-IV ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm=None"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "):"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = 2 \\sum_{n=0}^{N-1} x[n] \\sin\\left({\\pi (2n+1)(2k+1) \\over 4N}\\right)\n\\qquad 0 \\le k < N,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "or, for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "norm='ortho'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "y[k] = \\sqrt{2\\over N}\\sum_{n=0}^{N-1} x[n] \\sin\\left({\\pi (2n+1)(2k+1) \\over 4N}\\right)\n\\qquad 0 \\le k < N,"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Type IV DST"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The following example shows the relation between DST and IDST for different types and normalizations."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.fft import dst, idst\n>>> x = np.array([1.0, 2.0, 1.0, -1.0, 1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The DST-II and DST-III are each other's inverses, so for an orthonormal transform we return back to the original signal."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dst(dst(x, type=2, norm='ortho'), type=3, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Doing the same under default normalization, however, we pick up an extra scaling factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2N=10"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " since the forward transform is unnormalized."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dst(dst(x, type=2), type=3)\narray([ 10.,  20.,  10., -10.,  15.])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For this reason, we should use the function "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "idst",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " using the same type for both, giving a correctly normalized result."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> idst(dst(x, type=2), type=2)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Analogous results can be seen for the DST-I, which is its own inverse up to a factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2(N-1)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dst(dst(x, type=1, norm='ortho'), type=1, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])\n>>>  # scaling factor 2*(N+1) = 12\n>>> dst(dst(x, type=1), type=1)\narray([ 12.,  24.,  12., -12.,  18.])\n>>>  # no scaling factor\n>>> idst(dst(x, type=1), type=1)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "And for the DST-IV, which is also its own inverse up to a factor of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "2N"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> dst(dst(x, type=4, norm='ortho'), type=4, norm='ortho')\narray([ 1. ,  2. ,  1. , -1. ,  1.5])\n>>>  # scaling factor 2*N = 10\n>>> dst(dst(x, type=4), type=4)\narray([ 10.,  20.,  10., -10.,  15.])\n>>>  # no scaling factor\n>>> idst(dst(x, type=4), type=4)\narray([ 1. ,  2. ,  1. , -1. ,  1.5])",
          "execution_status": null,
          "out": ""
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "DST and IDST"
        }
      ],
      "level": 2,
      "target": "tutorial_FFT_DST_and_IDST"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "SciPy provides the functions "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fht"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "ifht"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " to perform the Fast Hankel Transform (FHT) and its inverse (IFHT) on logarithmically-spaced input arrays."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The FHT is the discretized version of the continuous Hankel transform defined by "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "8"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "A(k) = \\int_{0}^{\\infty} \\! a(r) \\, J_{\\mu}(kr) \\, k \\, dr \\;,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "J_{\\mu}"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the Bessel function of order "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\mu"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Under a change of variables "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "r \\to \\log r"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "k \\to \\log k"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", this becomes"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "A(e^{\\log k})\n= \\int_{0}^{\\infty} \\! a(e^{\\log r}) \\, J_{\\mu}(e^{\\log k + \\log r})\n                                    \\, e^{\\log k + \\log r} \\, d{\\log r}"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "which is a convolution in logarithmic space. The FHT algorithm uses the FFT to perform this convolution on discrete input data."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Care must be taken to minimise numerical ringing due to the circular nature of FFT convolution. To ensure that the low-ringing condition "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "8"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " holds, the output array can be slightly shifted by an offset computed using the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fhtoffset"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Fast Hankel Transform"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "1",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Cooley, James W., and John W. Tukey, 1965, \"An algorithm for the         machine calculation of complex Fourier series,\" "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Math. Comput."
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "         19: 297-301."
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "2",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,         2007, "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Numerical Recipes: The Art of Scientific Computing"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", ch.         12-13.  Cambridge Univ. Press, Cambridge, UK."
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "3",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "\"Discrete Fourier transform\", Wikipedia,         https://en.wikipedia.org/wiki/Discrete_Fourier_transform"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "4",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "\"Discrete-time Fourier transform\", Wikipedia,         https://en.wikipedia.org/wiki/Discrete-time_Fourier_transform"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "5",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "\"Discrete cosine transform\", Wikipedia,         https://en.wikipedia.org/wiki/Discrete_cosine_transform"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "6",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "IEEE Transactions on acoustics, speech and signal processing",
                  "domain": null,
                  "role": null,
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "         vol. 28(1), pp. 27-34, "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "10.1109/TASSP.1980.1163351"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "7",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "\"Discrete sine transform\", Wikipedia,         https://en.wikipedia.org/wiki/Discrete_sine_transform"
                }
              ]
            }
          ]
        },
        {
          "__type": "Footnote",
          "__tag": 4067,
          "label": "8",
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "spectrum\", "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "MNRAS"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", 312, 257. "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "10.1046/j.1365-8711.2000.03071.x"
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "References"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}