In [1]:
import numpy, scipy, matplotlib.pyplot as plt, pandas, librosa

Fourier Transform

Let's download and listen to a file:

In [2]:
import urllib
urllib.urlretrieve('http://audio.musicinformationretrieval.com/c_strum.wav')

x, fs = librosa.load('c_strum.wav', sr=44100)

from IPython.display import Audio
Audio(x, rate=fs)
Out[2]:

Fourier Transform

The Fourier Transform 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:

In [5]:
X = scipy.fft(x)
X_mag = numpy.absolute(X)
plt.plot(X_mag) # magnitude spectrum
Out[5]:
[<matplotlib.lines.Line2D at 0x11326a5d0>]

Zoom in:

In [6]:
plt.plot(X_mag[:5000])
Out[6]:
[<matplotlib.lines.Line2D at 0x11329ed50>]

In Essentia, you can also use essentia.standard.Spectrum to compute a magnitude spectrum.