PyTorch torch.stft function
PyTorch torch reference manual
torch.stft is a function in PyTorch used for the Short-Time Fourier Transform. It converts a time-domain signal into a frequency-domain representation and is commonly used in audio processing and signal analysis.
Function definition
torch.stft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, return_complex=None)
Usage examples
Example
import
torch
Create a sample signal
x
=
torch.
randn
(
1
,
16000
)
Short-Time Fourier Transform
n_fft: number of FFT points, hop_length: frame shift
result
=
torch.
stft
(
x
,
n_fft
=
512
,
hop_length
=
160
,
win_length
=
512
,
window
=
torch.
hann_window
(
512
)
)
(
"STFT result shape:"
,
result.
shape
)