fn

general_cosine

Tensor
general_cosine(M: int, a: list[float] | tuple[float, ...], sym: bool = True, dtype: DTypeLike = None, device: DeviceLike = None)
source

Generic weighted sum of cosines.

Builds a window of the form kak(1)kcos(2πkn/(N1))\sum_k a_k (-1)^k \cos(2\pi k n / (N - 1)), the parent family from which Hann, Hamming, Blackman, Nuttall, and the flat-top window all derive. Allows custom coefficient designs for bespoke side-lobe characteristics.

Parameters

Mint
Number of samples in the output window; must be >= 0.
alist of float or tuple of float
Coefficients a0,a1,a_0, a_1, \ldots. The kk-th coefficient multiplies (1)kcos(2πkn/(N1))(-1)^k \cos(2\pi k n / (N - 1)).
symbool= True
Symmetric (True, default) or periodic (False) variant.
dtypeDTypeLike= None
Desired dtype of the output tensor.
deviceDeviceLike= None
Target device for the output tensor.

Returns

Tensor

1-D tensor of length M.

Notes

Sample formula:

w[n]=k=0K1(1)kakcos ⁣(2πknN1),0n<N.w[n] = \sum_{k=0}^{K-1} (-1)^k a_k \cos\!\left( \frac{2\pi k n}{N - 1} \right), \qquad 0 \le n < N.

Common special cases:

  • Hann: [0.5, 0.5].
  • Hamming: [0.54, 0.46].
  • Blackman: [0.42, 0.50, 0.08].
  • Nuttall: [0.3635819, 0.4891775, 0.1365995, 0.0106411].

Examples

>>> from lucid.signal.windows import general_cosine
>>> general_cosine(5, [0.5, 0.5])
Tensor([0.0000, 0.5000, 1.0000, 0.5000, 0.0000])