Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.9.1.
librosa.filters.cq_to_chroma¶
- librosa.filters.cq_to_chroma(n_input, bins_per_octave=12, n_chroma=12, fmin=None, window=None, base_c=True, dtype=<class 'numpy.float32'>)[source]¶
Convert a Constant-Q basis to Chroma.
- Parameters
- n_inputint > 0 [scalar]
Number of input components (CQT bins)
- bins_per_octaveint > 0 [scalar]
How many bins per octave in the CQT
- n_chromaint > 0 [scalar]
Number of output bins (per octave) in the chroma
- fminNone or float > 0
Center frequency of the first constant-Q channel. Default: ‘C1’ ~= 32.7 Hz
- windowNone or np.ndarray
If provided, the cq_to_chroma filter bank will be convolved with window.
- base_cbool
If True, the first chroma bin will start at ‘C’ If False, the first chroma bin will start at ‘A’
- dtypenp.dtype
The data type of the output basis. By default, uses 32-bit (single-precision) floating point.
- Returns
- cq_to_chromanp.ndarray [shape=(n_chroma, n_input)]
Transformation matrix: Chroma = np.dot(cq_to_chroma, CQT)
- Raises
- ParameterError
If n_input is not an integer multiple of n_chroma
Notes
This function caches at level 10.
Examples
Get a CQT, and wrap bins to chroma
>>> y, sr = librosa.load(librosa.util.example_audio_file()) >>> CQT = np.abs(librosa.cqt(y, sr=sr)) >>> chroma_map = librosa.filters.cq_to_chroma(CQT.shape[0]) >>> chromagram = chroma_map.dot(CQT) >>> # Max-normalize each time step >>> chromagram = librosa.util.normalize(chromagram, axis=0)
>>> import matplotlib.pyplot as plt >>> plt.subplot(3, 1, 1) >>> librosa.display.specshow(librosa.amplitude_to_db(CQT, ... ref=np.max), ... y_axis='cqt_note') >>> plt.title('CQT Power') >>> plt.colorbar() >>> plt.subplot(3, 1, 2) >>> librosa.display.specshow(chromagram, y_axis='chroma') >>> plt.title('Chroma (wrapped CQT)') >>> plt.colorbar() >>> plt.subplot(3, 1, 3) >>> chroma = librosa.feature.chroma_stft(y=y, sr=sr) >>> librosa.display.specshow(chroma, y_axis='chroma', x_axis='time') >>> plt.title('librosa.feature.chroma_stft') >>> plt.colorbar() >>> plt.tight_layout() >>> plt.show()