Rate this Page

torch.hann_window#

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

Hann window function.

w[n]=12 [1cos(2πnN1)]=sin2(πnN1),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),

whereNN is the full window size.

The inputwindow_length is a positive integer controlling thereturned window size.periodic flag determines whether the returnedwindow trims off the last duplicate value from the symmetric window and isready to be used as a periodic window with functions liketorch.stft(). Therefore, ifperiodic is true, theNN inabove formula is in factwindow_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

Ifwindow_length=1=1, the returned window contains a single value 1.

Parameters
  • window_length (int) – the size of returned window

  • periodic (bool,optional) – If True, returns a window to be used as periodicfunction. If False, return a symmetric window.

Keyword Arguments
  • dtype (torch.dtype, optional) – the desired data type of returned tensor.Default: ifNone, uses a global default (seetorch.set_default_dtype()). Only floating point types are supported.

  • layout (torch.layout, optional) – the desired layout of returned window tensor. Onlytorch.strided (dense layout) is supported.

  • device (torch.device, optional) – the desired device of returned tensor.Default: ifNone, uses the current device for the default tensor type(seetorch.set_default_device()).device will be the CPUfor CPU tensor types and the current CUDA device for CUDA tensor types.

  • requires_grad (bool,optional) – If autograd should record operations on thereturned tensor. Default:False.

Returns

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

Return type

Tensor