# import all the library needed
%pylab inline
from __future__ import print_function
from __future__ import division
from scipy.io import wavfile
from IPython.display import Audio
Populating the interactive namespace from numpy and matplotlib
# Load the audio file
sr, signal = wavfile.read('piano.wav')
Audio(signal,rate=44100)
# Plot the time domain graphic
plot(signal)
[<matplotlib.lines.Line2D at 0x1046bed90>]
argmax(abs(fft.rfft(signal[1:])))
58
# Plot the magnitude around the argmax
plot(abs(fft.rfft(signal)))
xlim(0,100)
(0, 100)
# Get the result
sr/size(signal)*argmax(abs(fft.rfft(signal[1:])))
78.057861328125
From the result above, we can know the frequecy of the peak in the magnitude spectrum of the "Piano.wav" is 78.1 Hz.
# Load the audio file
sr, signal = wavfile.read('tom.wav')
Audio(signal,rate=44100)
# Compute the frequency of the magnitude spectrum peak
sr/size(signal)*argmax(abs(fft.rfft(signal[1:])))
92.56543145892718
From the result above, we can know the frequecy of the peak in the magnitude spectrum of the "Tom.wav" is 92.6 Hz.
# Load the audio file
sr, signal = wavfile.read('glockenspiel.wav')
Audio(signal,rate=44100)
# Compute the frequency of the magnitude spectrum peak
sr/size(signal)*argmax(abs(fft.rfft(signal[1:])))
1323.3428349313294
From the result above, we can know the frequecy of the peak in the magnitude spectrum of the "glockenspiel.wav" is 1323.3428349313294 Hz.