In [152]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
#import librosa
import os
import sys
import hdf5_getters
import numpy as np
from dtw import dtw
from numpy.linalg import norm
matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)
In [153]:
def norm2(x, y):
return norm(x - y, ord=2)
def get_song_info(h5):
print '%s - %s | (%s) | %s bpm' % (hdf5_getters.get_artist_name(h5), hdf5_getters.get_title(h5), hdf5_getters.get_year(h5), hdf5_getters.get_tempo(h5))
In [154]:
h5list = []
folder = './data/B/F/R/'
for f in os.listdir(folder):
h5list.append(hdf5_getters.open_h5_file_read(folder+f))
get_song_info(h5list[-1])
In [155]:
x = hdf5_getters.get_segments_pitches(h5list[0])
y = hdf5_getters.get_segments_pitches(h5list[-4])
get_song_info(h5list[0])
get_song_info(h5list[-4])
In [156]:
dist, cost, path = dtw(x, y, dist=norm2)
print 'Minimum distance:', dist
In [157]:
# plt.imshow(x.T, aspect='auto', origin='lower', cmap='spectral')
plt.pcolor(x.T, cmap=plt.cm.jet, alpha=0.8)
plt.xlim((-0.5, x.shape[0]+0.5))
plt.ylim((-0.5, x.shape[1]+0.5))
plt.colorbar()
Out[157]:
In [158]:
#plt.imshow(y.T, aspect='auto', origin='lower', cmap='spectral')
plt.pcolor(y.T, cmap=plt.cm.jet, alpha=0.8)
plt.xlim((-0.5, y.shape[0]+0.5))
plt.ylim((-0.5, y.shape[1]+0.5))
plt.colorbar()
Out[158]:
In [159]:
plt.pcolor(cost.T, cmap=plt.cm.gray, alpha=0.8)
plt.plot(path[0], path[1], 'w')
plt.xlim((-0.5, cost.shape[0]+0.5))
plt.ylim((-0.5, cost.shape[1]+0.5))
plt.colorbar()
Out[159]: