PyTorch torch.istft 函数
torch.istft 是 PyTorch 中用于短时傅里叶逆变换(Inverse Short-Time Fourier Transform)的函数。它将频域表示转换回时域信号,与 torch.stft 配合使用进行信号处理。
函数定义
torch.istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=True, length=None, return_complex=False)
使用示例
实例
import torch
# 先进行STFT然后进行ISTFT
x = torch.randn(1, 16000)
window = torch.hann_window(512)
# 短时傅里叶变换
stft_result = torch.stft(x, n_fft=512, hop_length=160, win_length=512, window=window)
# 短时傅里叶逆变换
reconstructed = torch.istft(stft_result, n_fft=512, hop_length=160, win_length=512, window=window, length=16000)
print("重建信号形状:", reconstructed.shape)
# 先进行STFT然后进行ISTFT
x = torch.randn(1, 16000)
window = torch.hann_window(512)
# 短时傅里叶变换
stft_result = torch.stft(x, n_fft=512, hop_length=160, win_length=512, window=window)
# 短时傅里叶逆变换
reconstructed = torch.istft(stft_result, n_fft=512, hop_length=160, win_length=512, window=window, length=16000)
print("重建信号形状:", reconstructed.shape)

Pytorch torch 参考手册