PyTorch torch.hann_window 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.hann_windowこれは PyTorch で Hann ウィンドウを生成するために使用される関数です。Hann ウィンドウ(Hanning ウィンドウとも呼ばれます)は余弦二乗窓関数の一種で、フーリエ変換前の信号窓処理によく使用され、スペクトル漏れを低減します。

関数定義

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

使用例

例

import torch

# 長さ 512 の Hann ウィンドウを作成
window = torch.hann_window(512)
print("Hann ウィンドウ形状:", window.shape)
print("ウィンドウの最初の5個の値:", window[:5])

# 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 結果の形状:", stft_result.shape)

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張