# MAT 201A Winter 2016
# HW 3
# Lu Liu
%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')
sr2, src2 = wavfile.read('piano.wav')
sr3, src3 = wavfile.read('tom.wav')
Fsrc = abs(fft.rfft(src, src.size)) / (src.size/2)# Normalize the frequency scale
Fsrc2 = abs(fft.rfft(src2, src2.size)) / (src2.size/2)
Fsrc3 = abs(fft.rfft(src3, src3.size)) / (src3.size/2)
plot(Fsrc)
title('Normalized frequency scale 1')
<matplotlib.text.Text at 0x1062a69d0>
plot(Fsrc2)
title('Normalized frequency scale 2')
<matplotlib.text.Text at 0x106414f10>
plot(Fsrc3)
title('Normalized frequency scale 3')
<matplotlib.text.Text at 0x10658f990>
argmax(Fsrc) * sr / src.size # the frequency of the most prominent peak
1323.3428349313294
argmax(Fsrc2) * sr2 / src2.size
78.057861328125
argmax(Fsrc3) * sr3/ src3.size
92.565431458927179