PyTorch torch.stft Function
Pytorch torch Reference Manual
torch.stftIt is a function in PyTorch used for Short-Time Fourier Transform. It converts time-domain signals into frequency-domain representations, commonly used in the fields of 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 Example
Example
import torch
# Create example 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))
print("STFT result shape:", result.shape)
# Output: STFT result shape: torch.Size([1, 257, 101, 2])
# Create example 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))
print("STFT result shape:", result.shape)
# Output: STFT result shape: torch.Size([1, 257, 101, 2])
Other Extensions