ifft2 — Compute two-dimensional inverse Fourier transforms in MATLAB and RunMat.
ifft2(X) computes the two-dimensional inverse discrete Fourier transform of X. Documented integer data through 32 bits enters the double transform domain; host int64 and uint64 data and shorthand size forms are exactness-checked RunMat extensions.
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 |
RunMat:ifft2:ProviderIntegrity | The provider returns ownership, shape, or physical metadata inconsistent with the request. | ifft2: provider integrity 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 or zero size controls and scalar/two-element SIZE shorthand are independently gated RunMat extensions.
- Provider results must be fresh, correctly shaped, complex, physically precise, and owned by the input provider; only an unsupported hook falls back through exact host storage.
GPU memory and residency
RunMat resolves execution through the provider that owns the input handle. Valid nonsymmetric floating results remain resident. Symmetric output and explicit unsupported-hook fallback may download internally; RunMat restores the result only when the owner can physically preserve its class, otherwise it returns the correctly typed host value.
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 input handle's owning provider exposes ifft_dim and returns valid fresh results. An explicit unsupported-hook response falls back through an exact owner download; provider failures or malformed results are not silently gathered away.
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 · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8
Trigonometry
acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Optim
coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
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.