Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

fft2
scipy
communitycreator
python

# What is the scipy.fft.fft2 function in Python?

Namra Ijlal

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

### 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 library
import scipy.fft
# Perform fft2 on the input signal to get 2D Fourier Transform
fft = scipy.fft.fft2(signal)
Basic syntax of the "scipy.fft.fft2" function

### 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)
Complete syntax of the "scipy.fft.fft2" function

### 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 is false. 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.

Sinusoidal grating and its Fourier transform

### 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.

RELATED TAGS

fft2
scipy
communitycreator
python

CONTRIBUTOR

Namra Ijlal

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 