istft(input: Tensor, n_fft: _int, hop_length: _int | None = ..., win_length: _int | None = ..., window: Tensor | None = ..., center: _bool = ..., normalized: _bool = ..., onesided: _bool | None = ..., length: _int | None = ..., return_complex: _bool = ...)Inverse short-time Fourier transform.
Inverts every frame of a spectrum stft produced, multiplies it by
window again, overlap-adds the frames and divides by the
overlap-added squared window, so istft(stft(x)) returns x for
any window that satisfies the non-zero overlap-add (NOLA) condition.
Parameters
inputTensorComplex spectrum,
(n_freq, n_frames) or
(batch, n_freq, n_frames).n_fftintFrame length the spectrum was computed with.
hop_lengthintFrame distance,
<= win_length; n_fft // 4 by default.win_lengthintWindow length,
<= n_fft; n_fft by default.windowTensorThe forward transform's window; rectangular when omitted.
centerboolWhether
input came from a centred (default) or normalised
stft; centring's padding is trimmed again.normalizedboolWhether
input came from a centred (default) or normalised
stft; centring's padding is trimmed again.onesidedboolWhether
input holds only the non-negative frequencies; when
omitted, unless it has n_fft bins.lengthintOutput length: trims the signal, or pads it with zeros (with a
warning) past what the frames cover.
return_complexboolReturn a complex signal, from a two-sided spectrum.
False
(default) returns a real one, reading the spectrum as Hermitian.Returns
Tensor([batch,] length); without length, the frames' span
n_fft + hop_length * (n_frames - 1), less 2 * (n_fft // 2)
when center.
Raises
lucid._C.engine.InvalidArgumentA length out of range, an empty spectrum or output, a window that
fails NOLA, or
return_complex against onesided or the window.lucid._C.engine.ShapeMismatch, lucid._C.engine.DtypeMismatchinput is not a complex spectrum of the right rank and bin count,
or window has the wrong shape.Notes
With the inverse transform of frame , hop :
Differentiable in input and window. The NOLA check reads one
value back to the host, as the reference does.
Examples
>>> import lucid
>>> x = lucid.randn(1000)
>>> w = lucid.hann_window(256)
>>> spec = lucid.stft(x, 256, window=w, return_complex=True)
>>> y = lucid.istft(spec, 256, window=w, length=1000)
>>> bool(lucid.allclose(x, y, atol=1e-5))
True