fn

hann

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

Hann (raised-cosine) window.

The Hann window is a single full cycle of a raised cosine. Its side-lobes roll off at 18dB/octave-18\,\text{dB/octave}, the fastest asymptotic decay among the simple cosine-sum windows, which makes it a popular default for STFT analysis when temporal localisation matters more than peak side-lobe suppression.

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 (special case of general_hamming with α=0.5\alpha = 0.5):

w[n]=12(1cos ⁣(2πnN1)),0n<N.w[n] = \tfrac{1}{2}\left( 1 - \cos\!\left(\frac{2\pi n}{N - 1}\right)\right), \qquad 0 \le n < N.

Main-lobe width 8π/N8\pi/N, peak side-lobe attenuation 31.5dB-31.5\,\text{dB}. Vanishes at both endpoints.

Examples

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