%pylab inline
rcParams['figure.figsize'] = (10, 4) #wide graphs by default
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
Populating the interactive namespace from numpy and matplotlib
#audio file1 glockenspiel
sr1, in_audio1 = wavfile.read('hw4/glockenspiel.wav')
plot(in_audio1)
print(in_audio1.max(), in_audio1.min(), sr1)
in_audio1.dtype
in_audio1astype
3819 -3629 44100
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-4-4333d882ba14> in <module>() 4 print(in_audio1.max(), in_audio1.min(), sr1) 5 in_audio1.dtype ----> 6 in_audio1astype NameError: name 'in_audio1astype' is not defined
#audio file2 piano
sr2, in_audio2 = wavfile.read('hw4/piano.wav')
plot(in_audio2)
print(in_audio2.max(), in_audio2.min(), sr2)
in_audio2.dtype
3423 -2683 44100
dtype('int16')
#audio file3 tom
sr3, in_audio3 = wavfile.read('hw4/tom.wav')
plot(in_audio3)
print(in_audio3.max(), in_audio3.min(), sr3)
in_audio3.dtype
9560 -12668 44100
dtype('int16')
in_audio1.shape
(38590,)
in_audio2.shape
(32768,)
in_audio3.shape
(38590,)
#autocorrelation function in each clip (audio1)
lags1, c1, lines1, line1 = acorr(in_audio1[:].astype(double), maxlags= 38589);
#autocorrelation function in each clip (audio2)
lags2, c2, lines2, line2 = acorr(in_audio2[:].astype(double), maxlags= 32767);
#autocorrelation function in each clip (audio3)
lags3, c3, lines3, line3 = acorr(in_audio3[:].astype(double), maxlags= 38589);
# the index of the most prominent peak in each clip's autocorrelation function (audio1)
cc_index1 = lags1[argmax(c1)]
print(cc_index1)
plot(lags1, c1)
vlines(cc_index1, 0.5, 1.09, color='r', lw=2)
text(cc_index1 + 1, 1.05, 'CC peak', color='r')
grid()
0
# the index of the most prominent peak in each clip's autocorrelation function (audio2)
cc_index2 = lags2[argmax(c2)]
print(cc_index2)
plot(lags2, c2)
vlines(cc_index2, 0.5, 1.09, color='r', lw=2)
text(cc_index2 + 1, 1.05, 'CC peak', color='r')
grid()
0
# the index of the most prominent peak in each clip's autocorrelation function (audio3)
cc_index3 = lags3[argmax(c3)]
print(cc_index3)
plot(lags3, c3)
vlines(cc_index3, 0.5, 1.09, color='r', lw=2)
text(cc_index3 + 1, 1.05, 'CC peak', color='r')
grid()
0
# compute the periods corresponding to each peak (Audio1)
sr1 = 44100
f1 = 38589.0
Ps1 = sr1/f1
Ps1
1.1428127186503927
# compute the periods corresponding to each peak (Audio2)
sr2 = 44100
f2 = 32767.0
Ps2 = sr2/f2
Ps2
1.3458662678914761
# compute the periods corresponding to each peak (Audio3)
sr3 = 44100
f3 = 38589.0
Ps3 = sr3/f3
Ps3
1.1428127186503927