In [1]:
import numpy, scipy, matplotlib.pyplot as plt, librosa, IPython.display, sklearn
plt.rcParams['figure.figsize'] = (14,5)
For classification, we're going to be using new features in our arsenal: spectral moments (centroid, bandwidth, skewness, kurtosis) and other spectral statistics.
Moments is a term used in physics and statistics. There are raw moments and central moments.
You are probably already familiar with two examples of moments: mean and variance. The first raw moment is known as the mean. The second central moment is known as the variance.
In [2]:
x, fs = librosa.load('simple_loop.wav')
IPython.display.Audio(x, rate=fs)
Out[2]:
In [3]:
spectral_centroids = librosa.feature.spectral_centroid(x, sr=fs)
plt.plot(spectral_centroids[0])
Out[3]:
In [4]:
spectral_bandwidth = librosa.feature.spectral_bandwidth(x, sr=fs)
plt.plot(spectral_bandwidth[0])
Out[4]:
In [5]:
spectral_contrast = librosa.feature.spectral_contrast(x, sr=fs)
# For visualization, scale each feature dimension to have zero mean and unit variance
spectral_contrast = sklearn.preprocessing.scale(spectral_contrast, axis=1)
librosa.display.specshow(spectral_contrast, x_axis='time')
Out[5]:
In [6]:
spectral_rolloff = librosa.feature.spectral_rolloff(x, sr=fs)
plt.plot(spectral_rolloff[0])
Out[6]: