librosa.feature.logfrequency_spectrogram#
- librosa.feature.logfrequency_spectrogram(*, y=None, sr=22050, S=None, n_fft=2048, hop_length=512, win_length=None, window='hann', center=True, pad_mode='constant', power=2.0, n_bins=None, bins_per_octave=12, fmin=None, tuning=0.0, filter_window='triangle', norm='slaney', **kwargs)[source]#
Compute a logarithmic frequency spectrogram.
Applies a logarithmic filterbank (
librosa.filters.logfrequency) to a Short-Time Fourier Transform (STFT) power or magnitude spectrogram.- Parameters:
- ynp.ndarray [shape=(…, n)]
Audio time-series. Multi-channel is supported.
- srnumber > 0 [scalar]
Sampling rate of
y.- Snp.ndarray [shape=(…, d, t)]
Pre-computed spectrogram.
- n_fftint > 0 [scalar]
Length of the FFT window.
- hop_lengthint > 0 [scalar]
Number of samples between successive frames.
- win_lengthint <= n_fft [scalar]
Window length for the STFT.
- windowstr, tuple, number, function, or np.ndarray [shape=(n_fft,)]
Window specification for the STFT.
- centerbool
If True, the input signal is padded so that frame
tis centered att * hop_length.- pad_modestr
Padding mode for the STFT.
- powerfloat > 0 [scalar]
Exponent for the magnitude spectrogram: e.g., 1 for energy, 2 for power, etc.
- n_binsint > 0 [scalar, optional]
Number of logarithmic frequency bands to generate. If None, automatically spans up to the Nyquist frequency.
- bins_per_octaveint > 0 [scalar], default=12
Number of filter bands per octave. Common choices:
12: Semitone resolution.
24: Quarter-tone resolution (as used in SuperFlux and madmom).
- 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 or None, default=0.0
Tuning deviation from A440 in fractional bins. If None, tuning is automatically estimated from the spectrogram.
- filter_windowstr or callable, default=’triangle’
Filter shape for the log-frequency basis. Choices include ‘triangle’, ‘boxcar’, ‘hann’, ‘gaussian’.
- norm{None, ‘slaney’, or number}, default=’slaney’
Normalization applied to each filter row.
- **kwargsadditional keyword arguments
Additional keyword arguments to
librosa.filters.logfrequency.
- Returns:
- logfspectrogramnp.ndarray [shape=(…, n_bins, t)]
Logarithmic frequency spectrogram.
Examples
Compute a 24-band-per-octave logarithmic spectrogram:
>>> y, sr = librosa.loadx("trumpet") >>> S_log = librosa.feature.logfrequency_spectrogram( ... y=y, sr=sr, bins_per_octave=24, fmin="C1" ... ) >>> S_log.shape (202, 230)
Display the log-frequency spectrogram:
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> S_dB = librosa.power_to_db(S_log, ref=np.max) >>> img = librosa.display.specshow( ... S_dB, ... x_axis="time", ... y_axis="logfreq_hz", ... sr=sr, ... bins_per_octave=24, ... fmin="C1", ... ax=ax, ... ) >>> librosa.display.colorbar_db(img) >>> ax.set(title="Log-frequency spectrogram")