%pylab inline
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
#input files
Samplerate, gloc = wavfile.read(("glockenspiel.wav"))
Samplerate, piano= wavfile.read(("piano.wav"))
Samplerate, tom= wavfile.read(("tom.wav"))
#perform dft from fourier analysis
X=(abs(fft.rfft(gloc)))
Y=(abs(fft.rfft(piano)))
Z=(abs(fft.rfft(tom)))
#gives index of the highest area
argmax((X))
1158
plot(X)
xlim(0,8000)
title("Gloc")
xlabel("bin")
ylabel("magnitude")
<matplotlib.text.Text at 0xd7c5570>
#divide by total bin numbers
#len is length
#plus 1 for exact nyquist
ans1=(argmax(X)/len(X))*(Samplerate/2+1)
print(ans1, "Hz")
1323.33426617 Hz
#gives index of the highest area
argmax(Y)
58
plot (Y)
xlim(0,1000)
title("Piano")
xlabel("bin")
ylabel("magnitude")
<matplotlib.text.Text at 0xcda37b0>
#divide by total bin numbers
#len is length
#plus 1 for exact nyquist
ans2=(argmax(Y)/len(Y))*(Samplerate/2+1)
print(ans2, "Hz")
78.0566371681 Hz
#gives index of the highest area
argmax(Z)
81
plot(Z)
xlim(0,1000)
title("Tom")
xlabel("bin")
ylabel("magnitude")
<matplotlib.text.Text at 0xced33f0>
#divide by total bin numbers
#len is length
#plus 1 for exact nyquist
ans3=(argmax(Z)/len(Z))*(Samplerate/2+1)
print(ans3, "Hz")
92.5648320896 Hz
print ("X", ans1, "Hz")
print("Y", ans2, "Hz")
print("Z", ans3,"Hz")
#these are the Hz values of the gloc(X), piano(Y), and tom(Z)
X 1323.33426617 Hz Y 78.0566371681 Hz Z 92.5648320896 Hz