Owen Campbell
MAT 240E
Homework 6
rcParams['figure.figsize'] = (16, 4) #wide graphs by default
from essentia.streaming import *
filenames = []
filenames.append("media/01 Everlasting Light.wav")
filenames.append("media/02 The Wilhelm Scream.wav")
filenames.append("media/1-01 Central Texas.wav")
Spectral Centroid
I'm going to look at the self-similarity matrix of non-overlapping spectral centroid measurements
src = MonoLoader(filename = filenames[0])
fc = FrameCutter(frameSize = 2048, hopSize = 2048) #avoiding overlap
pool = essentia.Pool()
w = Windowing()
spec = Spectrum()
centroid = Centroid()
src.audio >> fc.signal
fc.frame >> w.frame >> spec.frame
spec.spectrum >> centroid.array
centroid.centroid >> (pool, 'lowlevel.centroid')
essentia.reset(src)
src.configure(filename = filenames[0])
essentia.run(src)
ssm = []
centroids = pool['lowlevel.centroid']
for centroid_i in centroids:
for centroid_j in centroids:
cc = abs(centroid_i - centroid_j)
ssm.append(cc)
score = (len(ssm) - sum(ssm)) / len(ssm)
ssm = array(ssm).reshape(len(centroids), len(centroids))
imshow(ssm, cmap=cm.gray_r, interpolation='nearest')
colorbar()
title('The Black Keys - Everlasting Light\nSelf-Similarity Score: {}'.format(score))
<matplotlib.text.Text at 0x10ad73050>
essentia.reset(src)
pool.clear()
src.configure(filename = filenames[1])
essentia.run(src)
ssm = []
centroids = pool['lowlevel.centroid']
for centroid_i in centroids:
for centroid_j in centroids:
cc = abs(centroid_i - centroid_j)
ssm.append(cc)
score = (len(ssm) - sum(ssm)) / len(ssm)
ssm = array(ssm).reshape(len(centroids), len(centroids))
imshow(ssm, interpolation='nearest', cmap=cm.gray_r)
colorbar()
title('James Blake - The Wilhelm Scream\nSpectral Centroid Self-Similarity Score: {}'.format(score))
<matplotlib.text.Text at 0x10c063bd0>
essentia.reset(src)
pool.clear()
src.configure(filename = filenames[2])
essentia.run(src)
ssm = []
centroids = pool['lowlevel.centroid']
for centroid_i in centroids:
for centroid_j in centroids:
cc = abs(centroid_i - centroid_j)
ssm.append(cc)
score = (len(ssm) - sum(ssm)) / len(ssm)
ssm = array(ssm).reshape(len(centroids), len(centroids))
imshow(ssm, interpolation='nearest', cmap=cm.gray_r)
colorbar()
title('The Dead Texan - Central Texas\nSelf-Similarity Score: {}'.format(score))
<matplotlib.text.Text at 0x10c0ccd90>
OK so now I'm actually measuring a distance. It's clear that, at least with this window size, there is little change in the spectral centroid in general. The patterns may indicate some measure of...'relative homogeneity' (?) in the sense that unbroken regions, that is, those without frequently spaces dark lines, may have more static frequency content.
Since the centroid measurments range from 0-1, perhaps a way to measure the overall self-similarity with a single number would be to divide the sum of the SSM by the size of the matrix. Since 0s represent high similarity, the sum will first be subtracted from the size of the array (equivalent to 1-distance). The intuition here being that if the entire SSM was composed of 1s, that would be maximum possible similarity and would have a score of 1.