librosa.filters.pitch_to_chroma#
- librosa.filters.pitch_to_chroma(n_input, *, bins_per_octave=12, n_chroma=12, fmin=None, window=None, base='C', dtype=<class 'numpy.float32'>)[source]#
Construct a linear transformation matrix to map pitch/Constant-Q bins onto chroma bins.
- Parameters:
- n_inputint > 0 [scalar]
Number of input components (pitch or CQT bins)
- bins_per_octaveint > 0 [scalar], default=12
How many bins per octave in the input representation.
- n_chromaint > 0 [scalar], default=12
Number of output bins (per octave) in the chroma.
- fminNone, float > 0, or str, optional
Center frequency of the first constant-Q / pitch channel (in Hz) or note name in SPN format (e.g. ‘C1’). Default: note_to_hz(‘C1’) (~32.7 Hz).
- windowNone or np.ndarray, optional
If provided, the filter bank will be convolved with
window.- basestr or int, default=’C’
The base note name (e.g. ‘C’, ‘A’, ‘F#’) or integer pitch class (0 to 11) for the first chroma bin.
- dtypenp.dtype, default=np.float32
The data type of the output basis matrix.
- Returns:
- pitch_to_chromanp.ndarray [shape=(n_chroma, n_input)]
Transformation matrix:
Chroma = pitch_to_chroma.dot(X)
- Raises:
- ParameterError
If
n_inputis not an integer multiple ofn_chroma. Ifbaseis invalid.
See also
pitchlogfrequencychromacq_to_chroma
Notes
This function caches at level 10.
Examples
Get a CQT, and wrap bins to chroma
>>> y, sr = librosa.loadx("trumpet") >>> CQT = np.abs(librosa.cqt(y, sr=sr)) >>> chroma_map = librosa.filters.pitch_to_chroma(CQT.shape[0]) >>> chromagram = chroma_map.dot(CQT) >>> chromagram = librosa.util.normalize(chromagram, axis=0)
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> img = librosa.display.specshow(chroma_map, x_axis="cqt_note", ax=ax) >>> ax.set(ylabel="Chroma", title="Pitch-to-chroma mapping") >>> fig.colorbar(img, ax=ax)