TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-08

tensorplay.signal.windows.general_cosine

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])

On this page

Ask DeepWiki