Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.hann_window function

PyTorch torch.hann_window function


PyTorch torch reference manual PyTorch torch reference manual

torch.hann_window A function in PyTorch for generating a Hann window. The Hann window (also called the Hanning window) is a squared cosine window function often used to window signals before a Fourier transform to reduce spectral leakage.

Function definition

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


Usage examples

Example

import

torch

Create a Hann window of length 512

window

=

torch.

hann_window

(

512

)

print

(

"Hann window shape:"

,

window.

shape

)

print

(

"First 5 values of the window:"

,

window

[

:

5

]

)

Use in STFT

x

=

torch.

randn

(

1

,

16000

)

stft_result

=

torch.

stft

(

x.

squeeze

(

)

,

n_fft

=

512

,

hop_length

=

160

,

win_length

=

512

,

window

=

window

)

print

(

"STFT result shape:"

,

stft_result.

shape

)


PyTorch torch reference manual PyTorch torch reference manual