%pylab inline
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
%matplotlib inline
Populating the interactive namespace from numpy and matplotlib
sr, src = wavfile.read('glockenspiel.wav')
type(src[0])
numpy.int16
src = src[:].astype(double) #change the data type from int to float
type(src[0])
numpy.float64
lags, a, lines, line = acorr(src, maxlags = size(src) / 2); # autocorrelation
plot(a[0:200])
[<matplotlib.lines.Line2D at 0x10ea70e10>]
argmax(a[50:100])+50
75
argmax(a[100:125])+100
108
interval1= 108-75
freq1=44100/interval1
print(freq1)
1336.36363636
sr2, src2 = wavfile.read('piano.wav')
src2 = src2[:].astype(double)
lags, b, lines, line = acorr(src2, maxlags = size(src2) / 2);
plot(b[0:2000])
[<matplotlib.lines.Line2D at 0x111203090>]
argmax(b[0:600])
497
argmax(b[600:1200])+600
1064
interval2= 1064-497
freq2=44100/interval2
print(freq2)
77.7777777778
sr3, src3 = wavfile.read('tom.wav')
src3 = src3[:].astype(double)
size(src3)
38590
lags, c, lines, line = acorr(src3, maxlags = size(src3) / 2);
#xlim(0,2000)
plot(c[0:1000])
[<matplotlib.lines.Line2D at 0x10e7c0210>]
argmax(c[0:400])
252
argmax(c[400:800])+400
704
interval3=704-252
freq3=44100/interval3
print(freq3)
97.5663716814