istft

paddle.signal. istft ( x: Tensor, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: Tensor | None = None, center: bool = True, normalized: bool = False, onesided: bool = True, length: int | None = None, return_complex: bool = False, name: str | None = None ) Tensor [source]

Inverse short-time Fourier transform (ISTFT).

Reconstruct time-domain signal from the giving complex input and window tensor when nonzero overlap-add (NOLA) condition is met:

t=window2[nt×H]  0, for all n

Where: - t: The t-th input window. - N: Value of n_fft. - H: Value of hop_length.

Result of istft expected to be the inverse of paddle.signal.stft, but it is not guaranteed to reconstruct a exactly realizable time-domain signal from a STFT complex tensor which has been modified (via masking or otherwise). Therefore, istft gives the [Griffin-Lim optimal estimate] (optimal in a least-squares sense) for the corresponding signal.

Parameters
  • x (Tensor) – The input data which is a 2-dimensional or 3-dimensional complex Tensor with shape […, n_fft, num_frames].

  • n_fft (int) – The size of Fourier transform.

  • hop_length (int|None, optional) – Number of steps to advance between adjacent windows from time-domain signal and 0 < hop_length < win_length. Default: None ( treated as equal to n_fft//4)

  • win_length (int|None, optional) – The size of window. Default: None (treated as equal to n_fft)

  • window (Tensor|None, optional) – A 1-dimensional tensor of size win_length. It will be center padded to length n_fft if win_length < n_fft. It should be a real-valued tensor if return_complex is False. Default: None`(treated as a rectangle window with value equal to 1 of size `win_length).

  • center (bool, optional) – It means that whether the time-domain signal has been center padded. Default: True.

  • normalized (bool, optional) – Control whether to scale the output by 1/sqrt(nfft). Default: False

  • onesided (bool, optional) – It means that whether the input STFT tensor is a half of the conjugate symmetry STFT tensor transformed from a real-valued signal and istft will return a real-valued tensor when it is set to True. Default: True.

  • length (int|None, optional) – Specify the length of time-domain signal. Default: `None`( treated as the whole length of signal).

  • return_complex (bool, optional) – It means that whether the time-domain signal is real-valued. If return_complex is set to True, onesided should be set to False cause the output is complex.

  • name (str|None, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

A tensor of least squares estimation of the reconstructed signal(s) with shape […, seq_length]

Examples

>>> import numpy as np
>>> import paddle
>>> from paddle.signal import stft, istft

>>> paddle.seed(0)

>>> # STFT
>>> x = paddle.randn([8, 48000], dtype=paddle.float64)
>>> y = stft(x, n_fft=512)
>>> print(y.shape)
[8, 257, 376]

>>> # ISTFT
>>> x_ = istft(y, n_fft=512)
>>> print(x_.shape)
[8, 48000]

>>> np.allclose(x, x_)
True