{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Note that this function differs from the continuous-time \"rect\" function "
            },
            {
              "__type": "FootnoteReference",
              "__tag": 4066,
              "label": "1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " by not returning 1/2 at its borders."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The Fourier transform of a continuous-time boxcar window can be expressed as"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "W(f) = \\tau\\operatorname{sinc}(\\tau f) = \\frac{\\sin(\\pi\\tau f)}{\\pi f} \\,,"
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "with "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\tau = M T"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " being the window width and "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "T"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " the sampling interval. Eq. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "eq_FFT_SamplingFourierTrafo"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "tutorial_FFT_DFT",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:fft"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section of the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "user_guide",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:index"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be used to determine the values of the discrete Fourier transform (aka FFT), i.e.,"
            }
          ]
        },
        {
          "__type": "Math",
          "__tag": 4058,
          "value": "W[l] := \\frac{1}{T\\gamma} W(l\\Delta f)\n      = \\frac{M}{\\gamma}\\operatorname{sinc}(l) \\,,\n       \\qquad \\Delta f := 1 / \\tau = 1/ (MT) \\,."
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here, "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\gamma"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the FFT normalization constant (default: "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "\\gamma=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "). "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "W[l]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is zero for nonzero integer values of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "l"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and its sidelobes decrease on the order of "
            },
            {
              "__type": "InlineMath",
              "__tag": 4057,
              "value": "O(|l|^{-1})"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For many applications, like calculating a magnitude spectrum in the example below, a normalized window is needed. Consult the "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "tutorial_SpectralAnalysis",
              "domain": null,
              "role": "ref",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section of the "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "user_guide",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "tutorial:index"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for details."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "w",
              "annotation": "ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The window, i.e., "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "w = np.ones(M)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Return a boxcar or rectangular window."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "M",
              "annotation": "int",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Number of points in the output window. If zero, an empty array is returned. An exception is thrown when it is negative."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "sym",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Whether the window is symmetric. (Has no effect for boxcar.)"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "xp",
              "annotation": "array_namespace, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Optional array namespace. Should be compatible with the array API standard, or supported by array-api-compat. Default: "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "numpy"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "device",
              "annotation": "any",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "optional device specification for output. Should match one of the supported device specification in "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "xp"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Also known as a rectangular window or Dirichlet window. This is equivalent to no window at all."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "build-install/usr/lib/python3.14/site-packages/scipy/signal/windows/_windows.py",
  "item_line": 151,
  "item_type": "function",
  "aliases": [
    "scipy.signal.windows.boxcar"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "The following example compares a 10-sample boxcar window to its corresponding rect\nfunction. The upper plot depicts the amplitudes, whereas the corresponding magnitude\nspectra are shown in the lower plot. A standard resolution spectrum and a high\nresolution one, which is zero-padded by factor 16, are shown of the boxcar window.\nThat the boxcar spectrum does not coincide everywhere with the rect function\nspectrum is due to the underlying continuous-time function of the boxcar window\nbeing a 10-term Fourier series approximation of the rect function.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom matplotlib import pyplot as plt\nfrom scipy.fft import fft, fftfreq, fftshift\nfrom scipy.signal.windows import boxcar\nN, T = 10, 1/10  # number of samples and sampling interval in seconds\nt_w = np.arange(N) * T  # sample times\nw = boxcar(N)  # boxcar window\nW = fft(w) / sum(w)  # amplitude spectrum of w\nf_W = fftfreq(N, T)  # frequencies of W in Hz\nW16 = fftshift(fft(w, n=16*N)) / sum(w)  # zero-padded amplitude spectrum\nf_W16 = fftshift(fftfreq(N*16, T))  # frequencies of W16 in Hz\nf_R = np.linspace(-((N + 2) // 2), (N + 1) // 2, 100, endpoint=True)\nR = np.sinc(f_R)\n_, (ax0, ax1) = plt.subplots(2, 1, figsize=(5, 4.5), constrained_layout=True)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.set_title(r\"Boxcar window with corresponding rect function\")\nax0.set(ylabel=\"Amplitude\", xlim=(-0.5, 1.5),\n        xlabel=rf\"Time $t$ in seconds (${N}$ samples with interval ${T=}\\,$s)\")\nax0.plot([[-.5,  0,  1], [ 0,  1, 1.5]], [[0, 1, 0], [0, 1, 0]], 'C0-',\n         alpha=0.5, label=(r\"$w_r(t) = $rect$(t-\\frac{1}{2})$\", None, None))\nax0.plot([[0, 1]], [[0.5, 0.5]], 'C0.-', alpha=0.5)  # mark border values of 1/2\nax0.plot(t_w, w, 'C1o', label=\"Boxcar window\")\nax1.set_title(r\"Magnitude Spectrum\")\nax1.set(ylabel=\"Magnitude\", xlim=(f_R[0], f_R[-1]),\n        xlabel=rf\"Frequency $f$ in hertz ($\\Delta f = {f_W[1]:g}\\,$Hz)\")\nax1.plot(f_R, abs(R), 'C0-', alpha=0.5, label=\"$W_r(f) = $sinc$(f)$\")\nax1.plot(f_W, abs(W), 'C1o', label=r\"$W_r[l] = $sinc$(l\\Delta f)$\")\nax1.plot(f_W16, abs(W16), 'C1--', alpha=0.5, label=\"zero-padded $W_r[l]$\")\nfor ax_, l_ in zip((ax0, ax1), ('lower center', 'best')):\n    ax_.legend(loc=l_)\n    ax_.grid(True)\n",
        "execution_status": "failure",
        "out": "<matplotlib.legend.Legend object at 0x7f3f5870c2f0>\n<matplotlib.legend.Legend object at 0x7f3f5870cc20>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-8b818b59ec809b8c.png"
        }
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe following plot shows a logarithmically scaled version of the magnitude\nspectrum. The x-axis has been rescaled to correspond to the FFT-bin number.\nThe dashed green line represents the approximate sidelobe height.\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom matplotlib import pyplot as plt\nf = np.arange(0, 10, 0.01)\nW_abs = abs(np.sinc(f))\nW_dB = np.where(W_abs > 0, 20*np.log10(W_abs), -1e250)\nf_Y = np.linspace(.5, f[-1], 100)\nY_dB = 20*np.log10(1 / (np.pi*f_Y))\n_, ax0 = plt.subplots(constrained_layout=True)\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.set_title(r\"Magnitude Spectrum of $w(t) = $rect$(t/\\tau)$\")\nax0.set(ylabel=r\"Magnitude $20\\,\\log_{10} |W(l)|$ in dB\", ylim=(-40, 1),\n        xlabel=r\"Relative Frequency $l=f/\\Delta f\\ $ ($\\Delta f = 1/\\tau$)\",\n        xlim=(f[0], f[-1]), yticks=[-40, -20, 0], xticks=np.arange(11))\nax0.plot(f, W_dB, label=\"$W(l) = $sinc$(l)$\")\nax0.plot(f_Y, Y_dB, 'C2--', alpha=0.5, label=r\"$1 / (\\pi l)$\")\nax0.legend()\n",
        "execution_status": "failure",
        "out": "<matplotlib.legend.Legend object at 0x7f3f5828ae40>\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax0.grid(True)\nax1 = ax0.twinx() # create right y-axis with logarithmic scaling:\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax1.set_ylabel(\"Magnitude $|W(f)|$\", rotation=-90, labelpad=15)\nax1.set(ylim=(1e-2, 10**(1/20)), yscale=\"log\")\n",
        "execution_status": "failure",
        "out": "[(0.01, 1.1220184543019633), None]\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success",
        "out": ""
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "2.0.0.dev0+git20260907.41eeb59",
          "kind": "assets",
          "path": "fig-819b8c0ee37880ab.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "M",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "sym",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "True"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "xp",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "device",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "boxcar"
  },
  "references": [
    ".. [1] \"Rectangular function\", Wikipedia,",
    "    https://en.wikipedia.org/wiki/Rectangular_function"
  ],
  "qa": "scipy.signal.windows._windows:boxcar",
  "arbitrary": [],
  "local_refs": [
    "M",
    "device",
    "sym",
    "w",
    "xp"
  ]
}