torch.hann_window — PyTorch 2.7 documentation (original) (raw)

torch.hann_window(window_length, periodic=True, *, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

Hann window function.

w[n]=12 [1−cos⁡(2πnN−1)]=sin⁡2(πnN−1),w[n] = \frac{1}{2}\ \left[1 - \cos \left( \frac{2 \pi n}{N - 1} \right)\right] = \sin^2 \left( \frac{\pi n}{N - 1} \right),

where NN is the full window size.

The input window_length is a positive integer controlling the returned window size. periodic flag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions liketorch.stft(). Therefore, if periodic is true, the NN in above formula is in fact window_length+1\text{window\_length} + 1. Also, we always havetorch.hann_window(L, periodic=True) equal totorch.hann_window(L + 1, periodic=False)[:-1]).

Note

If window_length =1=1, the returned window contains a single value 1.

Parameters

Keyword Arguments

Returns

A 1-D tensor of size (window_length,)(\text{window\_length},) containing the window

Return type

Tensor