<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 &larr; Back to Index
Fourier Transform
Let's download an audio file
Step1:  Listen to the audio file
Step2:  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
Step3:  Plot the spectrum
Step4:  Zoom in
<ASSISTANT_TASK:>
Python Code:
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
<END_TASK>