import urllib
filename = 'c_strum.wav'
urllib.urlretrieve('http://audio.musicinformationretrieval.com/c_strum.wav', filename=filename)
x, sr = librosa.load(filename)

print(x.shape)
print(sr)

"""
Explanation: &larr; Back to Index
Fourier Transform
Let's download an audio file:
End of explanation
"""


ipd.Audio(x, rate=sr)

"""
Explanation: Listen to the audio file:
End of explanation
"""


X = scipy.fft(x)
X_mag = numpy.absolute(X)
f = numpy.linspace(0, sr, len(X_mag)) # frequency variable

"""
Explanation: Fourier Transform
The Fourier Transform (Wikipedia) is one of the most fundamental operations in applied mathematics and signal processing.
It transforms our time-domain signal into the frequency domain. Whereas the time domain expresses our signal as a sequence of samples, the frequency domain expresses our signal as a superposition of sinusoids of varying magnitudes, frequencies, and phase offsets.
To compute a Fourier transform in NumPy or SciPy, use scipy.fft:
End of explanation
"""


plt.figure(figsize=(13, 5))
plt.plot(f, X_mag) # magnitude spectrum
plt.xlabel('Frequency (Hz)')

"""
Explanation: Plot the spectrum:
End of explanation
"""


plt.figure(figsize=(13, 5))
plt.plot(f[:5000], X_mag[:5000])
plt.xlabel('Frequency (Hz)')

"""
Explanation: Zoom in:
End of explanation
"""


