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
X- Type
Any- Required
- Yes
- Description
- Input spectrum or signal.
SIZE- Type
NumericArray- Required
- No
- Default
[]- Description
- Scalar N or two-element [M N] size vector.
M- Type
NumericScalar- Required
- No
- Default
[]- Description
- Output row count for transform.
N- Type
NumericScalar- Required
- No
- Default
[]- Description
- Output column count for transform.
symflag- Type
StringScalar- Required
- No
- Default
"nonsymmetric"- Description
- Symmetry flag: "symmetric" or "nonsymmetric".
Returns
Y- Type
NumericArray- Description
- 2-D inverse FFT output.
Errors
RunMat:ifft2:ArgCount- When
- More than four input arguments are supplied.
- Message
ifft2: invalid argument count
RunMat:ifft2:InvalidLength- When
- Length/size arguments are invalid.
- Message
ifft2: invalid transform length argument
RunMat:ifft2:InvalidSizeVector- When
- Single SIZE argument is invalid.
- Message
ifft2: invalid size vector argument
Provider and fusion contract
The provider hook advertises f32 and f64 floating precision with MATLAB-style input shape semantics; integer and logical behavior follows the separate documented conversion or exact-reordering rules.
This operation is a fusion boundary, not an elementwise or reduction kernel. No fused FFT kernel is advertised, and provider launch details remain internal.
Behavior
ifft2(X) transforms along the first two dimensions whose sizes exceed one.
ifft2(X, M, N) zero-pads or truncates the spectrum to M rows and N columns 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 execution
Uses the input handle's owning provider for two validated ifft_dim passes. Only an explicit unsupported-hook response selects exact host fallback; malformed, aliased, or wrong-owner results are terminal and safely released.
GPU 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
X = [1 2; 3 4];
F = fft2(X);
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 · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · 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
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.