# fft2

2-D fast Fourier transform

## Description

`Y = fft2(`

returns
the two-dimensional
Fourier transform of a matrix using a fast Fourier transform
algorithm, which is equivalent to computing `X`

)`fft(fft(X).').'`

.
If `X`

is a multidimensional array, then `fft2`

takes
the 2-D transform of each dimension higher than 2. The output `Y`

is
the same size as `X`

.

## Examples

### 2-D Transform

The 2-D Fourier transform is useful for processing 2-D signals and other 2-D data such as images.

Create and plot 2-D data with repeated blocks.

P = peaks(20); X = repmat(P,[5 10]); imagesc(X)

Compute the 2-D Fourier transform of the data. Shift the zero-frequency component to the center of the output, and plot the resulting 100-by-200 matrix, which is the same size as `X`

.

Y = fft2(X); imagesc(abs(fftshift(Y)))

Pad `X`

with zeros to compute a 128-by-256 transform.

Y = fft2(X,2^nextpow2(100),2^nextpow2(200)); imagesc(abs(fftshift(Y)));

## Input Arguments

`X`

— Input array

matrix | multidimensional array

Input array, specified as a matrix or a multidimensional array.
If `X`

is of type `single`

, then `fft2`

natively
computes in single precision, and `Y`

is also of
type `single`

. Otherwise, `Y`

is
returned as type `double`

.

**Data Types: **`double`

| `single`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `logical`

**Complex Number Support: **Yes

`m`

— Number of transform rows

positive integer scalar

Number of transform rows, specified as a positive integer scalar.

**Data Types: **`double`

| `single`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `logical`

`n`

— Number of transform columns

positive integer scalar

Number of transform columns, specified as a positive integer scalar.

**Data Types: **`double`

| `single`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

| `logical`

## More About

### 2-D Fourier Transform

This formula defines the discrete Fourier transform *Y* of
an *m*-by-*n* matrix *X*:

$${Y}_{p+1,q+1}={\displaystyle \sum _{j=0}^{m-1}{\displaystyle \sum _{k=0}^{n-1}{\omega}_{m}^{jp}{\omega}_{n}^{kq}{X}_{j+1,k+1}}}$$

*ω _{m}* and

*ω*are complex roots of unity:

_{n}$$\begin{array}{l}{\omega}_{m}={e}^{-2\pi i/m}\\ {\omega}_{n}={e}^{-2\pi i/n}\end{array}$$

*i* is the imaginary unit. *p* and *j* are
indices that run from 0 to *m*–1, and *q* and *k* are
indices that run from 0 to *n*–1. This formula
shifts the indices for *X* and *Y* by
1 to reflect matrix indices in MATLAB^{®}.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using MATLAB® Coder™.

Usage notes and limitations:

For MEX output, MATLAB Coder™ uses the library that MATLAB uses for FFT algorithms. For standalone C/C++ code, by default, the code generator produces code for FFT algorithms instead of producing FFT library calls. To generate calls to a specific installed FFTW library, provide an FFT library callback class. For more information about an FFT library callback class, see

`coder.fftw.StandaloneFFTW3Interface`

(MATLAB Coder).For simulation of a MATLAB Function block, the simulation software uses the library that MATLAB uses for FFT algorithms. For C/C++ code generation, by default, the code generator produces code for FFT algorithms instead of producing FFT library calls. To generate calls to a specific installed FFTW library, provide an FFT library callback class. For more information about an FFT library callback class, see

`coder.fftw.StandaloneFFTW3Interface`

(MATLAB Coder).Using the Code Replacement Library (CRL), you can generate optimized code that runs on ARM

^{®}Cortex^{®}-A processors with Neon extension. To generate this optimized code, you must install the Embedded Coder^{®}Support Package for ARM Cortex-A Processors (Embedded Coder Support Package for ARM Cortex-A Processors). The generated code for ARM Cortex-A uses the Ne10 library. For more information, see Ne10 Conditions for MATLAB Functions to Support ARM Cortex-A Processors (Embedded Coder Support Package for ARM Cortex-A Processors).Using the Code Replacement Library (CRL), you can generate optimized code that runs on ARM Cortex-M processors. To generate this optimized code, you must install the Embedded Coder Support Package for ARM Cortex-M Processors (Embedded Coder Support Package for ARM Cortex-M Processors). The generated code for ARM Cortex-M uses the CMSIS library. For more information, see CMSIS Conditions for MATLAB Functions to Support ARM Cortex-M Processors (Embedded Coder Support Package for ARM Cortex-M Processors).

### GPU Code Generation

Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

### Thread-Based Environment

Run code in the background using MATLAB® `backgroundPool`

or accelerate code with Parallel Computing Toolbox™ `ThreadPool`

.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

### GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

Usage notes and limitations:

The output

`Y`

is always complex even if all the imaginary parts are zero.

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

### Distributed Arrays

Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.

This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).

## Version History

**Introduced before R2006a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)