ifft - Inverse fast Fourier transform - MATLAB (original) (raw)
Inverse fast Fourier transform
Syntax
Description
X = ifft([Y](#bvizm5c-1-Y))
computes the inverse discrete Fourier transform of Y
using a fast Fourier transform algorithm. X
is the same size as Y
.
- If
Y
is a vector, thenifft(Y)
returns the inverse transform of the vector. - If
Y
is a matrix, thenifft(Y)
returns the inverse transform of each column of the matrix. - If
Y
is a multidimensional array, thenifft(Y)
treats the values along the first dimension whose size does not equal 1 as vectors and returns the inverse transform of each vector.
X = ifft([Y](#bvizm5c-1-Y),[n](#bvizm5c-1-n))
returns the n
-point inverse Fourier transform ofY
by padding Y
with trailing zeros to length n
.
X = ifft([Y](#bvizm5c-1-Y),[n](#bvizm5c-1-n),[dim](#bvizm5c-1-dim))
returns the inverse Fourier transform along the dimension dim
. For example, if Y
is a matrix, thenifft(Y,n,2)
returns the n
-point inverse transform of each row.
X = ifft(___,[symflag](#bvizm5c-1-symflag))
specifies the symmetry of Y
in addition to any of the input argument combinations in previous syntaxes. For example,ifft(Y,'symmetric')
treats Y
as conjugate symmetric.
Examples
The Fourier transform and its inverse convert between data sampled in time and space and data sampled in frequency.
Create a vector and compute its Fourier transform.
X = [1 2 3 4 5]; Y = fft(X)
Y = 1×5 complex
15.0000 + 0.0000i -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i
Compute the inverse transform of Y
, which is the same as the original vector X
.
Find the inverse Fourier transform of the single-sided spectrum that is the Fourier transform of a real signal.
Load the single-sided spectrum in the frequency domain. Show the sampling frequency and the sampling period of this spectrum.
Plot the complex magnitude of the single-sided spectrum.
L1 = length(Y1); f = Fs/(2L1-1)(0:L1-1); plot(f,abs(Y1)) xlabel("f (Hz)") ylabel("|Y1(f)|")
The discrete Fourier transform of a time-domain signal has a periodic nature, where the first half of its spectrum is in positive frequencies and the second half is in negative frequencies, with the first element reserved for the zero frequency. For real signals, the discrete Fourier transform in the frequency domain is a two-sided spectrum, where the spectrum in the positive frequencies is the complex conjugate of the spectrum in the negative frequencies with half the peak amplitudes of the real signal in the time domain. To find the inverse Fourier transform of a single-sided spectrum, convert the single-sided spectrum to a two-sided spectrum.
Y2 = [Y1(1) Y1(2:end)/2 fliplr(conj(Y1(2:end)))/2];
Find the inverse Fourier transform of the two-sided spectrum to recover the real signal in the time domain.
Plot the signal.
t = (0:length(X)-1)*T; plot(t,X) xlabel("t (seconds)") ylabel("X(t)")
The ifft
function allows you to control the size of the transform.
Create a random 3-by-5 matrix and compute the 8-point inverse Fourier transform of each row. Each row of the result has length 8.
Y = rand(3,5); n = 8; X = ifft(Y,n,2); size(X)
For nearly conjugate symmetric vectors, you can compute the inverse Fourier transform faster by specifying the 'symmetric'
option, which also ensures that the output is real. Nearly conjugate symmetric data can arise when computations introduce round-off error.
Create a vector Y
that is nearly conjugate symmetric and compute its inverse Fourier transform. Then, compute the inverse transform specifying the 'symmetric'
option, which eliminates the nearly 0 imaginary parts.
Y = [1 2:4+eps(4) 4:-1:2]
X = 1×7
2.7143 -0.7213 -0.0440 -0.0919 -0.0919 -0.0440 -0.7213
Xsym = ifft(Y,'symmetric')
Xsym = 1×7
2.7143 -0.7213 -0.0440 -0.0919 -0.0919 -0.0440 -0.7213
Input Arguments
Input array, specified as a vector, a matrix, or a multidimensional array. If Y
is of type single
, thenifft
natively computes in single precision, andX
is also of type single
. Otherwise, X
is returned as typedouble
.
Data Types: double
| single
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
Complex Number Support: Yes
Inverse transform length, specified as []
or a nonnegative integer scalar. Padding Y
with zeros by specifying a transform length larger than the length of Y
can improve the performance of ifft
. The length is typically specified as a power of 2 or a product of small prime numbers. Ifn
is less than the length of the signal, thenifft
ignores the remaining signal values past then
th entry and returns the truncated result. Ifn
is 0, then ifft
returns an empty matrix.
Data Types: double
| single
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
Dimension to operate along, specified as a positive integer scalar. By default, dim
is the first array dimension whose size does not equal 1. For example, consider a matrix Y
.
ifft(Y,[],1)
returns the inverse Fourier transform of each column.ifft(Y,[],2)
returns the inverse Fourier transform of each row.
Data Types: double
| single
| int8
| int16
| int32
| uint8
| uint16
| uint32
| logical
Symmetry type, specified as 'nonsymmetric'
or'symmetric'
. When Y
is not exactly conjugate symmetric due to round-off error,ifft(Y,'symmetric')
treats Y
as if it were conjugate symmetric by ignoring the second half of its elements (that are in the negative frequency spectrum). For more information on conjugate symmetry, see Algorithms.
More About
Y = fft(X)
and X = ifft(Y)
implement the Fourier transform and inverse Fourier transform, respectively. ForX
and Y
of length n
, these transforms are defined as follows:
where
is one of n roots of unity.
Algorithms
- The
ifft
function tests whether the vectors inY
are conjugate symmetric. If the vectors inY
are conjugate symmetric, then the inverse transform computation is faster and the output is real.
A function g(a) is conjugate symmetric if g(a)=g*(−a). However, the fast Fourier transform of a time-domain signal has one half of its spectrum in positive frequencies and the other half in negative frequencies, with the first element reserved for the zero frequency. For this reason, a vectorv
is conjugate symmetric whenv(2:end)
is equal toconj(v(end:-1:2))
.
Extended Capabilities
Usage notes and limitations:
- Unless
symflag
is'symmetric'
, the output is always complex even if all imaginary parts are zero. - Code generation uses the symmetric algorithm only when the option
symmetric
is specified. - For input argument
Y
:- If you do not specify a dimension, the code generator operates along the first dimension of the input array that is variable size or whose size does not equal 1. If this dimension is variable size at code generation time and is 1 at run time, a run-time error can occur. To avoid this error, specify the dimension.
- If used, the
dim
argument must be a constant at code generation time. - 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).
Usage notes and limitations:
- Unless
symflag
is'symmetric'
, the output is always complex even if all imaginary parts are zero. - Code generation uses the symmetric algorithm only when the option
symmetric
is specified. - For input argument
Y
:- If you do not specify a dimension, the code generator operates along the first dimension of the input array that is variable size or whose size does not equal 1. If this dimension is variable size at code generation time and is 1 at run time, a run-time error can occur. To avoid this error, specify the dimension.
- If used, the
dim
argument must be a constant at code generation time.
The ifft
function supports GPU array input with these usage notes and limitations:
- Unless
symflag
is'symmetric'
, the output is always complex even if all imaginary parts are zero.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Version History
Introduced before R2006a