TensorPlay
API reference
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-08

tensorplay.signal.windows API

Functions 11

#

bartlett

functionFull reference ↗
tensorplay.signal.windows.bartlett(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the Bartlett window.

The samples form a triangle:

wn=1−∣2nM−1−1∣={2nM−1if 0≤n≤M−122−2nM−1if M−12<n<Mw_n = 1 - \left| \frac{2n}{M - 1} - 1 \right| = \begin{cases} \frac{2n}{M - 1} & \text{if } 0 \leq n \leq \frac{M - 1}{2} \\ 2 - \frac{2n}{M - 1} & \text{if } \frac{M - 1}{2} < n < M \\ \end{cases}

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Bartlett window.
>>> tensorplay.signal.windows.bartlett(10)
tensor([0., 0.2222, 0.4444, 0.6667, 0.8889, 0.8889, 0.6667, 0.4444, 0.2222, 0.])

>>> # Periodic Bartlett window.
>>> tensorplay.signal.windows.bartlett(10, sym=False)
tensor([0., 0.2, 0.4, 0.6, 0.8, 1., 0.8, 0.6, 0.4, 0.2])
#

blackman

functionFull reference ↗
tensorplay.signal.windows.blackman(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the Blackman window.

The samples are

wn=0.42−0.5cos⁡(2πnM−1)+0.08cos⁡(4πnM−1)w_n = 0.42 - 0.5 \cos \left( \frac{2 \pi n}{M - 1} \right) + 0.08 \cos \left( \frac{4 \pi n}{M - 1} \right)

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Blackman window.
>>> tensorplay.signal.windows.blackman(5)
tensor([-0., 0.34, 1., 0.34, -0.])

>>> # Periodic Blackman window.
>>> tensorplay.signal.windows.blackman(5, sym=False)
tensor([-0., 0.2008, 0.8492, 0.8492, 0.2008])
#

cosine

functionFull reference ↗
tensorplay.signal.windows.cosine(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes a window with a simple cosine waveform, also known as the sine window.

The samples follow

wn=sin⁡(π(n+0.5)M)w_n = \sin\left(\frac{\pi (n + 0.5)}{M}\right)

The 0.5 in the numerator shifts the sample positions by half a step, so the window starts and ends at non-zero values (for a symmetric window the first and last samples equal sin(pi / (2M))).

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric cosine window.
>>> tensorplay.signal.windows.cosine(10)
tensor([0.1564, 0.454, 0.7071, 0.891, 0.9877, 0.9877, 0.891, 0.7071, 0.454, 0.1564])

>>> # Periodic cosine window.
>>> tensorplay.signal.windows.cosine(10, sym=False)
tensor([0.1423, 0.4154, 0.6549, 0.8413, 0.9595, 1., 0.9595, 0.8413, 0.6549, 0.4154])
#

exponential

functionFull reference ↗
tensorplay.signal.windows.exponential(M: int, *, center: float | None = None, tau: float = 1.0, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes a window with an exponentially decaying waveform, also known as the Poisson window.

The samples decay exponentially with the distance from the window center:

wn=exp⁡(−∣n−c∣τ)w_n = \exp{\left(-\frac{|n - c|}{\tau}\right)}

where c is the center of the window.

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • center (float, optional) – location of the window center. Default: M / 2 if sym is False, else (M - 1) / 2.

  • tau (float, optional) – decay parameter, conceptually a percentage in (0, 100]. With tau = 100 the window degenerates to a constant. Default: 1.0.

  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric exponential window of length 10 with decay 1.0.
>>> # The center is (M - 1) / 2 with M = 10.
>>> tensorplay.signal.windows.exponential(10)
tensor([0.0111, 0.0302, 0.0821, 0.2231, 0.6065, 0.6065, 0.2231, 0.0821, 0.0302, 0.0111])

>>> # Periodic exponential window of length 10 with decay 0.5.
>>> tensorplay.signal.windows.exponential(10, sym=False, tau=0.5)
tensor([0., 0.0003, 0.0025, 0.0183, 0.1353, 1., 0.1353, 0.0183, 0.0025, 0.0003])
#

gaussian

functionFull reference ↗
tensorplay.signal.windows.gaussian(M: int, *, std: float = 1.0, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes a window with a Gaussian waveform.

The samples follow a Gaussian bump centered in the window:

wn=exp⁡(−(n2σ)2)w_n = \exp{\left(-\left(\frac{n}{2\sigma}\right)^2\right)}

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • std (float, optional) – standard deviation of the Gaussian; it controls how narrow or wide the window is. Default: 1.0.

  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Gaussian window of length 10 with std 1.0.
>>> tensorplay.signal.windows.gaussian(10)
tensor([0., 0.0022, 0.0439, 0.3247, 0.8825, 0.8825, 0.3247, 0.0439, 0.0022, 0.])

>>> # Periodic Gaussian window of length 10 with std 0.9.
>>> tensorplay.signal.windows.gaussian(10, sym=False, std=0.9)
tensor([0., 0.0001, 0.0039, 0.0847, 0.5394, 1., 0.5394, 0.0847, 0.0039, 0.0001])
#

general_cosine

functionFull reference ↗
tensorplay.signal.windows.general_cosine(M, *, a: Iterable, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the general cosine window, a weighted sum of cosines whose frequencies are integer multiples of the fundamental.

The samples are

wn=∑i=0M−1(−1)iaicos⁡(2πinM−1)w_n = \sum^{M-1}_{i=0} (-1)^i a_i \cos{ \left( \frac{2 \pi i n}{M - 1}\right)}

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • a (Iterable) – coefficient of each cosine term.

  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric general cosine window with 3 coefficients.
>>> tensorplay.signal.windows.general_cosine(10, a=[0.46, 0.23, 0.31], sym=True)
tensor([0.54, 0.3376, 0.1288, 0.42, 0.9136, 0.9136, 0.42, 0.1288, 0.3376, 0.54])

>>> # Periodic general cosine window with 2 coefficients.
>>> tensorplay.signal.windows.general_cosine(10, a=[0.5, 1 - 0.5], sym=False)
tensor([0., 0.0955, 0.3455, 0.6545, 0.9045, 1., 0.9045, 0.6545, 0.3455, 0.0955])
#

general_hamming

functionFull reference ↗
tensorplay.signal.windows.general_hamming(M, *, alpha: float = 0.54, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the general Hamming window, the two-term member of the general cosine family.

The samples are

wn=α−(1−α)cos⁡(2πnM−1)w_n = \alpha - (1 - \alpha) \cos{ \left( \frac{2 \pi n}{M-1} \right)}

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • alpha (float, optional) – the window coefficient. Default: 0.54.

  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Hamming window via the general Hamming builder.
>>> tensorplay.signal.windows.general_hamming(10, sym=True)
tensor([0.08, 0.1876, 0.4601, 0.77, 0.9723, 0.9723, 0.77, 0.4601, 0.1876, 0.08])

>>> # Periodic Hann window via the general Hamming builder.
>>> tensorplay.signal.windows.general_hamming(10, alpha=0.5, sym=False)
tensor([0., 0.0955, 0.3455, 0.6545, 0.9045, 1., 0.9045, 0.6545, 0.3455, 0.0955])
#

hamming

functionFull reference ↗
tensorplay.signal.windows.hamming(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the Hamming window.

The samples are

wn=α−β cos⁡(2πnM−1)w_n = \alpha - \beta\ \cos \left( \frac{2 \pi n}{M - 1} \right)

with α=0.54\alpha = 0.54 and β=0.46\beta = 0.46.

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Hamming window.
>>> tensorplay.signal.windows.hamming(10)
tensor([0.08, 0.1876, 0.4601, 0.77, 0.9723, 0.9723, 0.77, 0.4601, 0.1876, 0.08])

>>> # Periodic Hamming window.
>>> tensorplay.signal.windows.hamming(10, sym=False)
tensor([0.08, 0.1679, 0.3979, 0.6821, 0.9121, 1., 0.9121, 0.6821, 0.3979, 0.1679])
#

hann

functionFull reference ↗
tensorplay.signal.windows.hann(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the Hann window.

The samples are

wn=12 [1−cos⁡(2πnM−1)]=sin⁡2(πnM−1)w_n = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{M - 1} \right)\right] = \sin^2 \left( \frac{\pi n}{M - 1} \right)

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Hann window.
>>> tensorplay.signal.windows.hann(10)
tensor([0., 0.117, 0.4132, 0.75, 0.9698, 0.9698, 0.75, 0.4132, 0.117, 0.])

>>> # Periodic Hann window.
>>> tensorplay.signal.windows.hann(10, sym=False)
tensor([0., 0.0955, 0.3455, 0.6545, 0.9045, 1., 0.9045, 0.6545, 0.3455, 0.0955])
#

kaiser

functionFull reference ↗
tensorplay.signal.windows.kaiser(M: int, *, beta: float = 12.0, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the Kaiser window.

The samples are

wn=I0(β1−(n−N/2N/2)2)/I0(β)w_n = I_0 \left( \beta \sqrt{1 - \left( {\frac{n - N/2}{N/2}} \right) ^2 } \right) / I_0( \beta )

where I0I_0 is the modified Bessel function of the first kind of order zero, evaluated with tensorplay.i0(), and N=M−1N = M - 1 for a symmetric window, otherwise N=MN = M.

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • beta (float, optional) – shape parameter of the window. Must be non-negative. Default: 12.0

  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

Examples:

>>> # Symmetric Kaiser window of length 5 with shape parameter 12.0.
>>> tensorplay.signal.windows.kaiser(5)
tensor([0.0001, 0.2157, 1., 0.2157, 0.0001])

>>> # Periodic Kaiser window of length 5 with shape parameter 0.9.
>>> tensorplay.signal.windows.kaiser(5, sym=False, beta=0.9)
tensor([0.8244, 0.9348, 0.9926, 0.9926, 0.9348])
#

nuttall

functionFull reference ↗
tensorplay.signal.windows.nuttall(M: int, *, sym: bool = True, dtype: dtype | None = None, layout: Layout = tensorplay.strided, device: device | None = None, requires_grad: bool = False) → Tensor[source]

Computes the minimum 4-term Blackman-Harris window described by Nuttall.

The window is a general cosine sum with the Nuttall coefficients a0=0.3635819a_0 = 0.3635819, a1=0.4891775a_1 = 0.4891775, a2=0.1365995a_2 = 0.1365995, a3=0.0106411a_3 = 0.0106411:

wn=a0−a1cos⁡(zn)+a2cos⁡(2zn)−a3cos⁡(3zn)w_n = a_0 - a_1 \cos{(z_n)} + a_2 \cos{(2z_n)} - a_3 \cos{(3z_n)}

where zn=2πnM−1z_n = \frac{2 \pi n}{M - 1} for a symmetric window and zn=2πnMz_n = \frac{2 \pi n}{M} for a periodic one.

The window is scaled so that its largest value is 1. The value 1 itself does not occur when M is even and sym is True.

Parameters:

M (int) – number of points of the returned window.

Keyword Arguments:
  • sym (bool, optional) – if False, returns a periodic window, which is the usual choice for spectral analysis. If True, returns a symmetric window, which is the usual choice for filter design. Default: True.

  • dtype (tensorplay.dtype, optional) – the desired data type of the returned tensor. Default: if None, uses the global default (see tensorplay.set_default_dtype()).

  • layout (tensorplay.Layout, optional) – the desired layout of the returned tensor. Default: tensorplay.strided.

  • device (tensorplay.device, optional) – the desired device of the returned tensor. Default: if None, uses the current default tensor device (see tensorplay.set_default_device()).

  • requires_grad (bool, optional) – whether autograd should record operations on the returned tensor. Default: False.

References:

- A. Nuttall, "Some windows with very good sidelobe behavior,"
  IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 29, no. 1, pp. 84-91,
  Feb 1981. https://doi.org/10.1109/TASSP.1981.1163506

- Heinzel G. et al., "Spectrum and spectral density estimation by the Discrete Fourier transform (DFT),
  including a comprehensive list of window functions and some new flat-top windows",
  February 15, 2002 https://holometer.fnal.gov/GH_FFT.pdf

Examples:

>>> # Symmetric Nuttall window.
>>> tensorplay.signal.windows.nuttall(5)
tensor([0.0004, 0.227, 1., 0.227, 0.0004])

>>> # Periodic Nuttall window.
>>> tensorplay.signal.windows.nuttall(5, sym=False)
tensor([0.0004, 0.1105, 0.7983, 0.7983, 0.1105])

On this page

Ask DeepWiki