What is the scipy.fft.fft2 function in Python?
Overview
Fourier transform is a method of transferring signals from the time domain into frequency. It is mostly used to identify the components of a signal.
The scipy.fft.fft2 function is provided by the Scientific Python (SciPy) library to perform Fourier transform on 2D signals.
Syntax
The basic syntax of this function is as follows:
# Import fft package from scipy libraryimport scipy.fft# Perform fft2 on the input signal to get 2D Fourier Transformfft = scipy.fft.fft2(signal)
Explanation
The scipy.fft.fft2 function performs Fast Fourier Transform (FFT), which is designed as a computationally efficient version of Fourier transform. FFT improves speed by decreasing the number of calculations needed to analyze a waveform.
The complete syntax of the scipy.fft.fft2 function is:
scipy.fft.fft2(x, s=None, axes=(- 2, - 1), norm=None,overwrite_x=False, workers=None, *, plan=None)
Parameter values
x: This is the input array that contains real or complex values of the signal.s: This is the sequence of ints that represents the shape of the output. The default value of this parameter is the shape of specified axes. This is an optional parameter value.axes: This is the sequence of integers that point to the axes over which to compute the FFT. The default axes are the last two. This is an optional parameter value.norm: Normalization to apply to the signal. {default = “backward”, “ortho”, “forward”}. This is an optional parameter value.overwrite_x: This is a boolean value that decides whether to perform FFT in-place or not. The default value of this parameter isfalse. This is an optional parameter value.workers: This is the integer value that represents the maximum number of workers allowed for parallel computing. This is an optional parameter value.
Return value
This function returns out, which is a complex array that contains the transformation of the input array around the specified axes.
Example
An interesting example of this function is to compute the FFT of the 2D extension of a sinusoidal wave called sinusoidal grating.
Explanation
A sinusoidal grating can be viewed as a grayscale image in which the values change according to the sine function. The figure on the left shows a horizontal grating in which the grayscale along the x-axis varies according to the amplitude of the sine wave. The figure on the right shows the corresponding Fourier transform identifying the presence of a signal.
Given below is a Jupyter notebook for gaining hands-on experience with creating combinations of gratings and computing their Fourier transform using the scipy.fft.fft2 function.