librosa.filters.chroma¶
- librosa.filters.chroma(*, sr, n_fft, n_chroma=12, tuning=0.0, ctroct=5.0, octwidth=2, norm=2, base_c=True, dtype=<class 'numpy.float32'>)[source]¶
Create a chroma filter bank.
This creates a linear transformation matrix to project FFT bins onto chroma bins (i.e. pitch classes).
- Parameters
- srnumber > 0 [scalar]
audio sampling rate
- n_fftint > 0 [scalar]
number of FFT bins
- n_chromaint > 0 [scalar]
number of chroma bins
- tuningfloat
Tuning deviation from A440 in fractions of a chroma bin.
- ctroctfloat > 0 [scalar]
- octwidthfloat > 0 or None [scalar]
ctroct
andoctwidth
specify a dominance window: a Gaussian weighting centered onctroct
(in octs, A0 = 27.5Hz) and with a gaussian half-width ofoctwidth
.Set
octwidth
to None to use a flat weighting.- normfloat > 0 or np.inf
Normalization factor for each filter
- base_cbool
If True, the filter bank will start at ‘C’. If False, the filter bank will start at ‘A’.
- dtypenp.dtype
The data type of the output basis. By default, uses 32-bit (single-precision) floating point.
- Returns
- wtsndarray [shape=(n_chroma, 1 + n_fft / 2)]
Chroma filter matrix
Notes
This function caches at level 10.
Examples
Build a simple chroma filter bank
>>> chromafb = librosa.filters.chroma(sr=22050, n_fft=4096) array([[ 1.689e-05, 3.024e-04, ..., 4.639e-17, 5.327e-17], [ 1.716e-05, 2.652e-04, ..., 2.674e-25, 3.176e-25], ..., [ 1.578e-05, 3.619e-04, ..., 8.577e-06, 9.205e-06], [ 1.643e-05, 3.355e-04, ..., 1.474e-10, 1.636e-10]])
Use quarter-tones instead of semitones
>>> librosa.filters.chroma(sr=22050, n_fft=4096, n_chroma=24) array([[ 1.194e-05, 2.138e-04, ..., 6.297e-64, 1.115e-63], [ 1.206e-05, 2.009e-04, ..., 1.546e-79, 2.929e-79], ..., [ 1.162e-05, 2.372e-04, ..., 6.417e-38, 9.923e-38], [ 1.180e-05, 2.260e-04, ..., 4.697e-50, 7.772e-50]])
Equally weight all octaves
>>> librosa.filters.chroma(sr=22050, n_fft=4096, octwidth=None) array([[ 3.036e-01, 2.604e-01, ..., 2.445e-16, 2.809e-16], [ 3.084e-01, 2.283e-01, ..., 1.409e-24, 1.675e-24], ..., [ 2.836e-01, 3.116e-01, ..., 4.520e-05, 4.854e-05], [ 2.953e-01, 2.888e-01, ..., 7.768e-10, 8.629e-10]])
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> img = librosa.display.specshow(chromafb, x_axis='linear', ax=ax) >>> ax.set(ylabel='Chroma filter', title='Chroma filter bank') >>> fig.colorbar(img, ax=ax)