ifft2 — Compute two-dimensional inverse Fourier transforms in MATLAB and RunMat.
ifft2(X) computes the two-dimensional inverse discrete Fourier transform of X. Size-argument behavior and transform ordering follow MATLAB semantics.
Syntax
Y = ifft2(X)
Y = ifft2(X, SIZE)
Y = ifft2(X, M, N)
Y = ifft2(X, symflag)
Y = ifft2(X, SIZE, symflag)
Y = ifft2(X, M, N, symflag)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Input spectrum or signal. |
SIZE | NumericArray | No | [] | Scalar N or two-element [M N] size vector. |
M | NumericScalar | No | [] | Output row count for transform. |
N | NumericScalar | No | [] | Output column count for transform. |
symflag | StringScalar | No | "nonsymmetric" | Symmetry flag: "symmetric" or "nonsymmetric". |
Returns
| Name | Type | Description |
|---|---|---|
Y | NumericArray | 2-D inverse FFT output. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:ifft2:ArgCount | More than four input arguments are supplied. | ifft2: invalid argument count |
RunMat:ifft2:InvalidLength | Length/size arguments are invalid. | ifft2: invalid transform length argument |
RunMat:ifft2:InvalidSizeVector | Single SIZE argument is invalid. | ifft2: invalid size vector argument |
RunMat:ifft2:InvalidSymflag | Symmetry flag is invalid or appears in an invalid position. | ifft2: invalid symmetry flag usage |
RunMat:ifft2:InvalidInput | Input cannot be converted to supported numeric/complex domain. | ifft2: invalid input |
RunMat:ifft2:Internal | IFFT2 execution or tensor shaping fails. | ifft2: internal error |
How ifft2 works
ifft2(X)transforms along the first two dimensions whose sizes exceed one.ifft2(X, M, N)zero-pads or truncates the spectrum toMrows andNcolumns before the inverse.ifft2(X, SIZE)accepts a scalar or two-element vector describing the transform lengths.ifft2(..., 'symmetric')discards tiny imaginary parts and returns a real matrix when the spectrum is conjugate-symmetric.'nonsymmetric'keeps the complex result.- Higher-dimensional inputs are processed slice-by-slice across trailing dimensions.
- Empty sizes and zero padding mirror MATLAB behaviour, producing empty outputs when any requested length is zero.
GPU memory and residency
You usually do not need to call gpuArray manually. RunMat’s native acceleration layer keeps intermediate tensors on the GPU whenever the provider implements ifft_dim. If the provider lacks that hook (or detects an unsupported length), RunMat gathers the input once, executes the inverse transform on the CPU with rustfft, and returns a MATLAB-compatible result automatically.
Examples
Reconstructing an image patch from its 2-D spectrum
F = [10 -2 0 -2;
-4 0 0 0];
x = ifft2(F)Expected output:
x =
1.0000 2.0000
3.0000 4.0000Zero-padding before the inverse transform
F = fft2([1 0; 0 1], 4, 4);
spatial = ifft2(F, 4, 4)Supplying transform lengths with a size vector
Y = fft2(rand(3,4));
X = ifft2(Y, [5 2]); % pad rows to 5, truncate columns to 2Forcing a real-valued result with 'symmetric'
F = fft2([1 2; 3 4]);
realImage = ifft2(F, 'symmetric')Running ifft2 on gpuArray inputs
G = gpuArray(fft2(peaks(64)));
spatial = ifft2(G);
result = gather(spatial)Recovering each slice of a volume
spectra = fft2(rand(16, 16, 10));
volume = ifft2(spectra)Using ifft2 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how ifft2 changes the result.
Run a small ifft2 example, explain the result, then change one input and compare the output.
FAQ
Is ifft2(X) equivalent to ifft(ifft(X, [], 1), [], 2)?⌄
Yes. RunMat literally performs two sequential 1-D inverse transforms so the behaviour matches MATLAB exactly.
How do zero-length sizes behave?⌄
Passing 0 for either transform length produces an output with zero elements along that dimension, just like MATLAB.
Can I mix [] with explicit sizes (e.g., ifft2(X, [], 64))?⌄
Yes. [] leaves that dimension unchanged while the other argument controls padding or truncation.
What does the 'symmetric' flag do?⌄
It tells RunMat to coerce the result to real values, assuming the spectrum is conjugate-symmetric. Imaginary parts are dropped.
What happens when the input is real-valued?⌄
RunMat promotes the data to complex with zero imaginary parts before applying the inverse. The output can still be coerced to real with 'symmetric'.
Will ifft2 run on the GPU automatically?⌄
Yes when the active provider exposes ifft_dim. Otherwise the runtime gathers to the host and evaluates the inverse using rustfft.
Does ifft2 normalise the result?⌄
Yes. The builtin divides by the product of the transform lengths so that ifft2(fft2(X)) reproduces X.
Can I pass gpuArray size vectors or symmetry flags?⌄
No. Length arguments must be host scalars or vectors, and the symmetry flag must be a host string, mirroring MATLAB’s restrictions.
How are higher-dimensional arrays handled?⌄
Transformations are applied to every 2-D slice defined by the first two dimensions; trailing dimensions are preserved unchanged.
Does 'nonsymmetric' change the result?⌄
It simply states the default behaviour (return complex outputs) but is accepted for MATLAB compatibility.
Related Math functions
Elementwise
abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times
Trigonometry
acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh
Reduction
all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var
Structure
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how ifft2 is executed, line by line, in Rust.
- View the source for ifft2 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.