nnAudio.librosa_functions.chroma

nnAudio.librosa_functions.chroma(sr, n_fft, n_chroma=12, tuning=0.0, ctroct=5.0, octwidth=2, norm=2, base_c=True, dtype=<class 'numpy.float32'>)

Create a chroma filter bank.

This creates a linear transformation matrix to project FFT bins onto chroma bins (i.e. pitch classes).

Parameters
  • sr (number > 0 [scalar]) – audio sampling rate

  • n_fft (int > 0 [scalar]) – number of FFT bins

  • n_chroma (int > 0 [scalar]) – number of chroma bins

  • tuning (float) – Tuning deviation from A440 in fractions of a chroma bin.

  • ctroct (float > 0 [scalar]) –

  • octwidth (float > 0 or None [scalar]) –

    ctroct and octwidth specify a dominance window: a Gaussian weighting centered on ctroct (in octs, A0 = 27.5Hz) and with a gaussian half-width of octwidth.

    Set octwidth to None to use a flat weighting.

  • norm (float > 0 or np.inf) – Normalization factor for each filter

  • base_c (bool) – If True, the filter bank will start at ‘C’. If False, the filter bank will start at ‘A’.

  • dtype (np.dtype) – The data type of the output basis. By default, uses 32-bit (single-precision) floating point.

Returns

wts – Chroma filter matrix

Return type

ndarray [shape=(n_chroma, 1 + n_fft / 2)]

See also

librosa.util.normalize, librosa.feature.chroma_stft

Notes

This function caches at level 10.

Examples

Build a simple chroma filter bank

>>> chromafb = librosa.filters.chroma(22050, 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(22050, 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(22050, 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)