SciPy FFT

scipy.fftpack provides fft function to calculate Discrete Fourier Transform on an array. In this tutorial, we shall learn the syntax and the usage of fft function with SciPy FFT Examples.

Syntax

y = scipy.fftpack.fft(x, n=None, axis=-1, overwrite_x=False)
Parameter  Required/ Optional  [datatype] Description
x Required [array] Array on which FFT has to be calculated.
n Optional [int] Length of the Fourier transform. If n < x.shape[axis], x is truncated. If n > x.shape[axis], x is zero-padded. The default results in n = x.shape[axis].
axis Optional [int] Axis along which the fft’s are computed; the default is over the last axis (i.e., axis=-1).
overwrite_x Optional [boolean] If True, the contents of x can be destroyed; the default is False.
y [Returned value] [complex ndarray] Discrete Fourier Transform of x.

Values provided for the optional arguments are default values.

Example 1 SciPy FFT

scipy-example.py

# import numpy
import numpy as np

# import fft
from scipy.fftpack import fft

# numpy array
x = np.array([1.0, 2.0, 1.0, 2.0, -1.0])
print("x            : ",x)

# apply fft function on array
y = fft(x)
print("fft(x)       : ",y)

Output

x            :  [ 1.  2.  1.  2. -1.]
fft(x)       :  [ 5.00000000+0.j         -1.11803399-2.2653843j   1.11803399-2.71441227j
  1.11803399+2.71441227j -1.11803399+2.2653843j ]