torch.istft — PyTorch 2.7 documentation (original) (raw)

torch.istft(input, n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) → Tensor:

Inverse short time Fourier Transform. This is expected to be the inverse of stft().

Warning

From version 2.1, a warning will be provided if a window is not specified. In a future release, this attribute will be required. Please provide the same window used in the stft call.

It has the same parameters (+ additional optional parameter of length) and it should return the least squares estimation of the original signal. The algorithm will check using the NOLA condition ( nonzero overlap).

Important consideration in the parameters window and center so that the envelope created by the summation of all the windows is never zero at certain point in time. Specifically,∑t=−∞∞∣w∣2[n−t×hop_length]=0\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0.

Since stft() discards elements at the end of the signal if they do not fit in a frame,istft may return a shorter signal than the original signal (can occur if center is False since the signal isn’t padded). If length is given in the arguments and is longer than expected,istft will pad zeros to the end of the returned signal.

If center is True, then there will be padding e.g. 'constant', 'reflect', etc. Left padding can be trimmed off exactly because they can be calculated but right padding cannot be calculated without additional information.

Example: Suppose the last window is:[17, 18, 0, 0, 0] vs [18, 0, 0, 0, 0]

The n_fft, hop_length, win_length are all the same which prevents the calculation of right padding. These additional values could be zeros or a reflection of the signal so providinglength could be useful. If length is None then padding will be aggressively removed (some loss of signal).

[1] D. W. Griffin and J. S. Lim, “Signal estimation from modified short-time Fourier transform,” IEEE Trans. ASSP, vol.32, no.2, pp.236-243, Apr. 1984.

Parameters

Returns

Least squares estimation of the original signal of shape (B?, length) where

B? is an optional batch dimension from the input tensor.

Return type

Tensor