Caution
You're reading the documentation for a development version. For the latest released version, please have a look at 0.9.1.
librosa.feature.tonnetz¶
- librosa.feature.tonnetz(*, y=None, sr=22050, chroma=None, **kwargs)[source]¶
Computes the tonal centroid features (tonnetz)
This representation uses the method of 1 to project chroma features onto a 6-dimensional basis representing the perfect fifth, minor third, and major third each as two-dimensional coordinates.
- 1
Harte, C., Sandler, M., & Gasser, M. (2006). “Detecting Harmonic Change in Musical Audio.” In Proceedings of the 1st ACM Workshop on Audio and Music Computing Multimedia (pp. 21-26). Santa Barbara, CA, USA: ACM Press. doi:10.1145/1178723.1178727.
- Parameters
- ynp.ndarray [shape=(…, n,)] or None
Audio time series. Multi-channel is supported.
- srnumber > 0 [scalar]
sampling rate of
y
- chromanp.ndarray [shape=(n_chroma, t)] or None
Normalized energy for each chroma bin at each frame.
If None, a cqt chromagram is performed.
- **kwargs
Additional keyword arguments to
chroma_cqt
, ifchroma
is not pre-computed.
- Returns
- tonnetznp.ndarray [shape(…, 6, t)]
Tonal centroid features for each frame.
- Tonnetz dimensions:
0: Fifth x-axis
1: Fifth y-axis
2: Minor x-axis
3: Minor y-axis
4: Major x-axis
5: Major y-axis
See also
chroma_cqt
Compute a chromagram from a constant-Q transform.
chroma_stft
Compute a chromagram from an STFT spectrogram or waveform.
Examples
Compute tonnetz features from the harmonic component of a song
>>> y, sr = librosa.load(librosa.ex('nutcracker'), duration=10, offset=10) >>> y = librosa.effects.harmonic(y) >>> tonnetz = librosa.feature.tonnetz(y=y, sr=sr) >>> tonnetz array([[ 0.007, -0.026, ..., 0.055, 0.056], [-0.01 , -0.009, ..., -0.012, -0.017], ..., [ 0.006, -0.021, ..., -0.012, -0.01 ], [-0.009, 0.031, ..., -0.05 , -0.037]])
Compare the tonnetz features to
chroma_cqt
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots(nrows=2, sharex=True) >>> img1 = librosa.display.specshow(tonnetz, ... y_axis='tonnetz', x_axis='time', ax=ax[0]) >>> ax[0].set(title='Tonal Centroids (Tonnetz)') >>> ax[0].label_outer() >>> img2 = librosa.display.specshow(librosa.feature.chroma_cqt(y=y, sr=sr), ... y_axis='chroma', x_axis='time', ax=ax[1]) >>> ax[1].set(title='Chroma') >>> fig.colorbar(img1, ax=[ax[0]]) >>> fig.colorbar(img2, ax=[ax[1]])