import numpy, scipy, matplotlib.pyplot as plt, sklearn, stanford_mir
%matplotlib inline
Load a file:
x, fs = librosa.load('prelude_cmaj_10s.wav')
Compute its chromagram:
X = librosa.feature.chromagram(x, sr=fs)
print X.shape
Display the chromagram:
librosa.display.specshow(X, sr=fs, y_axis='chroma')
Display a single chroma vector:
plt.stem(X[:,0])
Create a PCA model object.
model = sklearn.decomposition.PCA(n_components=11, whiten=True)
Apply PCA to the chromagram:
Y = model.fit_transform(X)
print Y.shape
Display all of the principal components:
plt.imshow(Y, interpolation='nearest', origin='lower')
Plot one of the principal components:
plt.stem(Y[:,5])