fn

cosine

Tensor
cosine(M: int, sym: bool = True, dtype: DTypeLike = None, device: DeviceLike = None)
source

Cosine (half-sine) window.

Produces a single arch of a sine curve over the window length, sometimes called the "sine" or "half-cosine" window. It is a smoother taper than the triangular window with comparable main-lobe width but significantly lower side lobes.

Parameters

Mint
Number of samples in the output window; must be >= 0.
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 containing the window samples.

Notes

Sample formula:

w[n]=sin ⁣(π(n+1/2)N),0n<N.w[n] = \sin\!\left( \frac{\pi (n + 1/2)}{N} \right), \qquad 0 \le n < N.

Peak side-lobe attenuation is 23dB\approx -23\, \text{dB} and the main-lobe width is 4π/N4\pi/N. Sometimes used as the square root of the Hann window for analysis/synthesis pairs.

Examples

>>> from lucid.signal.windows import cosine
>>> cosine(4)
Tensor([0.3827, 0.9239, 0.9239, 0.3827])