stft(input: Tensor, n_fft: _int, hop_length: _int | None = ..., win_length: _int | None = ..., window: Tensor | None = ..., center: _bool = ..., pad_mode: str = ..., normalized: _bool = ..., onesided: _bool | None = ..., return_complex: _bool | None = ..., align_to_window: _bool | None = ...)Short-time Fourier transform.
Cuts input into frames of n_fft samples, hop_length apart,
multiplies each by window and returns the DFT of every frame.
Parameters
inputTensorReal or complex signal,
(time,) or (batch, time).n_fftintFrame and transform length.
hop_lengthintDistance between frame starts;
n_fft // 4 by default.win_lengthintWindow length,
<= n_fft (default n_fft); a shorter window
is zero-padded on both sides to n_fft.windowTensor1-D, of length
win_length; rectangular when omitted.centerboolPad
input by n_fft // 2 at both ends first (default), so
frame t is centred on sample t * hop_length.pad_modestrThat padding:
"reflect" (default), "constant",
"replicate" or "circular".normalizedboolScale by , the unitary transform.
onesidedboolKeep the
n_fft // 2 + 1 non-negative frequencies: the default
for a real signal and window, refused for a complex one.return_complexboolRequired for a real signal and window.
False returns the real
and imaginary parts in a trailing axis, as lucid.view_as_real.align_to_windowboolWith
center=False, start the first frame where the window
starts rather than where its zero-padded n_fft frame does.Returns
Tensor([batch,] n_freq, n_frames): n_freq is n_fft // 2 + 1
one-sided and n_fft otherwise, n_frames is
1 + (L - n_fft) // hop_length for the padded length L.
Raises
lucid._C.engine.InvalidArgumentA length out of range, or flags that contradict each other.
lucid._C.engine.ShapeMismatch, lucid._C.engine.DtypeMismatchinput is not a 1-D or 2-D floating or complex signal, or
window is not 1-D of length win_length.Notes
Differentiable in input and window. A float64 signal needs a
float64 FFT, which the engine does not have yet (LCD-458).
Examples
>>> import lucid
>>> x = lucid.randn(2, 1000)
>>> spec = lucid.stft(x, 256, window=lucid.hann_window(256), return_complex=True)
>>> spec.shape
(2, 129, 16)