librosa.feature.inverse.logfrequency_to_stft#
- librosa.feature.inverse.logfrequency_to_stft(L, *, sr=22050, n_fft=2048, power=2.0, n_bins=None, bins_per_octave=12, fmin=None, tuning=0.0, filter_window='triangle', norm='slaney', **kwargs)[source]#
Approximate STFT magnitude from a logarithmic frequency spectrogram.
- Parameters:
- Lnp.ndarray [shape=(…, n_bins, t), non-negative]
The spectrogram as produced by feature.logfrequency_spectrogram
- srnumber > 0 [scalar]
Sampling rate of the underlying signal.
- n_fftint > 0 [scalar]
Length of the FFT frame of the resulting STFT; the output has
1 + n_fft // 2frequency bins.- powerfloat > 0 [scalar]
Exponent for the magnitude spectrogram.
- n_binsint > 0 [scalar, optional]
Number of logarithmic frequency bands. If None, defaults to
L.shape[-2].- bins_per_octaveint > 0 [scalar], default=12
Number of filter bands per octave.
- fminfloat > 0, str, or None, optional
Lowest frequency (in Hz) or note name in SPN format (e.g. ‘C1’). Defaults to note_to_hz(‘C1’) (~32.7 Hz).
- tuningfloat, default=0.0
Tuning deviation from A440 in fractional bins.
- filter_windowstr or callable, default=’triangle’
Filter shape for the log-frequency basis.
- norm{None, ‘slaney’, or number}, default=’slaney’
Normalization applied to each filter row.
- **kwargsadditional keyword arguments
Additional keyword arguments for
librosa.filters.logfrequency.
- Returns:
- Snp.ndarray [shape=(…, 1 + n_fft // 2, t), non-negative]
An approximate linear magnitude spectrogram.
- Raises:
- ParameterError
If
n_binsis provided and does not matchL.shape[-2].
See also
Examples
>>> y, sr = librosa.loadx("trumpet") >>> S = librosa.util.abs2(librosa.stft(y)) >>> log_spec = librosa.feature.logfrequency_spectrogram( ... S=S, sr=sr, bins_per_octave=24, fmin="C1" ... ) >>> S_inv = librosa.feature.inverse.logfrequency_to_stft( ... log_spec, sr=sr, bins_per_octave=24, fmin="C1" ... )
Compare the results visually:
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots(nrows=3, sharex=True, sharey=True) >>> img = librosa.display.specshow( ... S, vscale="dBFS[power]", top_db=None, y_axis="log", x_axis="time", ax=ax[0] ... ) >>> ax[0].set(title="Original STFT") >>> ax[0].label_outer() >>> librosa.display.specshow( ... S_inv, ... vscale="dBFS[power]", ... top_db=None, ... y_axis="log", ... x_axis="time", ... ax=ax[1], ... ) >>> ax[1].set(title="Reconstructed STFT") >>> ax[1].label_outer() >>> librosa.display.specshow( ... S_inv - S, ... vscale=f"dB[power,{S.max()}]", ... top_db=None, ... vmax=0, ... y_axis="log", ... x_axis="time", ... ax=ax[2], ... ) >>> ax[2].set(title="Residual error (dB)") >>> librosa.display.colorbar_db(img, ax=ax)