fft2 - 2-D fast Fourier transform - MATLAB (original) (raw)
2-D fast Fourier transform
Syntax
Description
Y = fft2([X](#bvhck3f-X))
returns the two-dimensional Fourier transform of a matrix X
using a fast Fourier transform algorithm, which is equivalent to computingfft(fft(X).').'
.
When X
is a multidimensional array, fft2
computes the 2-D Fourier transform on the first two dimensions of each subarray ofX
that can be treated as a 2-D matrix for dimensions higher than 2. For example, if X
is anm
-by-n
-by-1
-by-2
array, then Y(:,:,1,1) = fft2(X(:,:,1,1))
and Y(:,:,1,2) = fft2(X(:,:,1,2))
. The output Y
is the same size as X
.
Y = fft2([X](#bvhck3f-X),[m](#bvhck3f-m),[n](#bvhck3f-n))
truncates X
or pads X
with trailing zeros to form an m
-by-n
matrix before computing the transform. If X
is a matrix, then Y
is anm
-by-n
matrix. If X
is a multidimensional array, then fft2
shapes the first two dimensions of X
according to m
andn
.
Examples
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
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
Number of transform rows, specified as a positive integer scalar.
Data Types: double
| single
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
Number of transform columns, specified as a positive integer scalar.
Data Types: double
| single
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
More About
This formula defines the discrete Fourier transform Y of an _m_-by-n matrix X:
ωm and ωn are complex roots of unity:
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
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). 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).
- 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). 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).
The fft2
function supports GPU array input with these 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).
Version History
Introduced before R2006a