## MAT 201A Winter 2016
## HW 5
## Mark Hirsch
%pylab inline
from __future__ import print_function
from __future__ import division
import wave
from IPython.display import Audio
from scipy.io import wavfile
import glob
import IPython.display
Populating the interactive namespace from numpy and matplotlib
sr = 44100
f = 100.0
cc_lags = 0.001*sr # 1 ms max lag
##load first sound file
sr, x = wavfile.read('glockenspiel.wav')
plot(x)
[<matplotlib.lines.Line2D at 0x111c76cd0>]
lags,c,line,b = acorr(x, normed=False, maxlags=cc_lags);
argmax(c[-45:-5])
9
peakLag = lags[argmax(c[-45:-5])]
##get the period (per sample)
Ps = sr/f
peakFreq = peakLag/Ps
peakFreq
-0.079591836734693874
##divided by sampling rate (44100) = Period in seconds
y = peakFreq/sr
y
-1.804803554074691e-06
##compute freq
freq = 1/y
freq
-554076.92307692312