Rate this Page

torch.istft#

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 ofstft().

Warning

From version 2.1, a warning will be provided if awindow isnot 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 oflength) and it should return theleast squares estimation of the original signal. The algorithm will check using the NOLA condition (nonzero overlap).

Important consideration in the parameterswindow andcenter so that the envelopecreated by the summation of all the windows is never zero at certain point in time. Specifically,t=w2[nt×hop_length]=0\sum_{t=-\infty}^{\infty} |w|^2[n-t\times hop\_length] \cancel{=} 0.

Sincestft() 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 ifcenter is Falsesince the signal isn’t padded). Iflength is given in the arguments and is longer than expected,istft will pad zeros to the end of the returned signal.

Ifcenter isTrue, 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 becalculated without additional information.

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

Then_fft,hop_length,win_length are all the same which prevents the calculationof right padding. These additional values could be zeros or a reflection of the signal so providinglength could be useful. Iflength isNone 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
  • input (Tensor) –

    The input tensor. Expected to be in the format ofstft(),output. That is a complex tensor of shape(B?, N, T) where

    • B? is an optional batch dimension

    • N is the number of frequency samples,(n_fft // 2) + 1for onesided input, or otherwisen_fft.

    • T is the number of frames,1 + length // hop_length for centered stft,or1 + (length - n_fft) // hop_length otherwise.

    Changed in version 2.0:Real datatype inputs are no longer supported. Input must now have acomplex datatype, as returned bystft(...,return_complex=True).

  • n_fft (int) – Size of Fourier transform

  • hop_length (Optional[int]) – The distance between neighboring sliding window frames.(Default:n_fft//4)

  • win_length (Optional[int]) – The size of window frame and STFT filter. (Default:n_fft)

  • window (Optional[torch.Tensor]) – The optional window function.Shape must be 1d and<= n_fft(Default:torch.ones(win_length))

  • center (bool) – Whetherinput was padded on both sides so that thett-th frame iscentered at timet×hop_lengtht \times \text{hop\_length}.(Default:True)

  • normalized (bool) – Whether the STFT was normalized. (Default:False)

  • onesided (Optional[bool]) – Whether the STFT was onesided.(Default:True ifn_fft != fft_size in the input size)

  • length (Optional[int]) – The amount to trim the signal by (i.e. theoriginal signal length). Defaults to(T - 1) * hop_length forcentered stft, orn_fft + (T - 1) * hop_length otherwise, whereTis the number of input frames.

  • return_complex (Optional[bool]) – Whether the output should be complex, or if the input should beassumed to derive from a real signal and window.Note that this is incompatible withonesided=True.(Default:False)

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