librosa.core.istft¶
- librosa.core.istft(stft_matrix, hop_length=None, win_length=None, window=None, center=True, dtype=<class 'numpy.float32'>)¶
Inverse short-time Fourier transform (ISTFT).
Converts a complex-valued spectrogram stft_matrix to time-series y by minimizing the mean squared error between stft_matrix and STFT of y as described in [R21].
In general, window function, hop length and other parameters should be same as in stft, which mostly leads to perfect reconstruction of a signal from unmodified stft_matrix.
[R21] 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: stft_matrix : np.ndarray [shape=(1 + n_fft/2, t)]
STFT matrix from stft
hop_length : int > 0 [scalar]
Number of frames between STFT columns. If unspecified, defaults to win_length / 4.
win_length : int <= n_fft = 2 * (stft_matrix.shape[0] - 1)
When reconstructing the time series, each frame is windowed and each sample is normalized by the sum of squared window according to the window function (see below).
If unspecified, defaults to n_fft.
window : None, function, np.ndarray [shape=(n_fft,)]
- None (default): use an asymmetric Hann window
- a window function, such as scipy.signal.hanning
- a user-specified window vector of length n_fft
center : boolean
- If True, D is assumed to have centered frames.
- If False, D is assumed to have left-aligned frames.
dtype : numeric type
Real numeric type for y. Default is 32-bit float.
Returns: y : np.ndarray [shape=(n,)]
time domain signal reconstructed from stft_matrix
Raises: ParameterError
If window is supplied as a vector of length n_fft
See also
- stft
- Short-time Fourier Transform
Examples
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> D = librosa.stft(y) >>> y_hat = librosa.istft(D) >>> y_hat array([ -4.812e-06, -4.267e-06, ..., 6.271e-06, 2.827e-07], dtype=float32)