Table of Contents
Shortcuts

# 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]=1 2 [1−cos⁡(2 π n N−1)]=sin⁡2(π n N−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), w[n]=2 1​ [1−cos(N−1 2 πn​)]=sin 2(N−1 πn​),

  where N N N 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 like `torch.stft()`. Therefore, if `periodic` is true, the N N N in above formula is in fact window_length+1\text{window\_length} + 1 window_length+1. Also, we always have `torch.hann_window(L, periodic=True)` equal to `torch.hann_window(L + 1, periodic=False)[:-1])`.

  Note

  If `window_length` =1=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 periodic function. If False, return a symmetric window.

  Keyword Arguments:

    - dtype (`torch.dtype`, optional) – the desired data type of returned tensor. Default: if `None`, uses a global default (see `torch.set_default_tensor_type()`). Only floating point types are supported.

    - layout (`torch.layout`, optional) – the desired layout of returned window tensor. Only `torch.strided` (dense layout) is supported.

    - device (`torch.device`, optional) – the desired device of returned tensor. Default: if `None`, uses the current device for the default tensor type (see `torch.set_default_tensor_type()`). `device` will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

    - requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: `False`.

  Returns:

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

  Return type:

    Tensor

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.