deconv — Compute one-dimensional deconvolution in MATLAB and RunMat.

deconv(b, a) performs one-dimensional polynomial long division and returns quotient q plus remainder r. Coefficients use MATLAB/RunMat polynomial ordering (highest-order term first), with support for real and complex inputs.

Syntax

Q = deconv(numerator, denominator)
[Q, R] = deconv(numerator, denominator)

Inputs

NameTypeRequiredDefaultDescription
numeratorAnyYesNumerator coefficients.
denominatorAnyYesDenominator coefficients.

Returns

NameTypeDescription
QNumericArrayQuotient polynomial coefficients.
RNumericArrayRemainder polynomial coefficients.

Returned values from deconv depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:deconv:InvalidInputNumerator/denominator input value is not supported for polynomial conversion.deconv: unsupported input type
RunMat:deconv:VectorRequiredInput is not scalar/row/column vector.deconv: inputs must be scalars, row vectors, or column vectors
RunMat:deconv:DenominatorInvalidDenominator is empty, all zero, or numerically singular at leading term.deconv: denominator is invalid

How deconv works

  • Inputs must be scalars, row vectors, or column vectors. Multi-dimensional tensors are rejected.
  • Leading zeros are ignored during division, matching MATLAB’s behaviour. The outputs include just enough coefficients to represent the resulting polynomials (with at least one element for the zero polynomial).
  • When length(b) < length(a), the quotient is zero and the remainder equals b.
  • Logical inputs are promoted to double precision prior to division (TRUE → 1.0, FALSE → 0.0).
  • Complex coefficients are handled exactly; the quotient and remainder retain complex values.
  • Empty denominators and all-zero denominators raise MATLAB-compatible errors.

Does RunMat run deconv on the GPU?

When either input resides on the GPU (gpuArray values), RunMat first checks whether the active acceleration provider exposes a dedicated deconvolution hook. The current providers (in-process and WGPU) do not yet offer this kernel, so the runtime always:

1. Gathers the device operands into host memory. 2. Performs the polynomial long division on the CPU. 3. Re-uploads real-valued results to the provider so downstream fused kernels can remain device-resident (complex outputs stay on the host until providers add complex buffer uploads).

This fallback keeps behaviour identical to MATLAB. Gather the outputs explicitly only when you need them on the host.

Examples

Recovering a factor from a polynomial product

p = conv([1 2], [1 -3 2]);   % Multiply two polynomials
[q, r] = deconv(p, [1 2])   % Divide by the first factor

Expected output:

q = [1 -3 2];
r = 0

Obtaining a non-zero remainder

[q, r] = deconv([1 4 7], [1 2])

Expected output:

q = [1 2];
r = [3]

Dividing by a longer sequence

[q, r] = deconv([3 5], [1 0 2])

Expected output:

q = 0;
r = [3 5]

Handling leading zeros explicitly

b = [0 0 1 2];
a = [0 1 1];
[q, r] = deconv(b, a)

Expected output:

q = [1];
r = [1]

Complex polynomial division

b = [1+2i 3-4i 2];
a = [1-i 2+i];
[q, r] = deconv(b, a)

Expected output:

q = [-0.5+1.5i 6-0.5i];
r = [-10.5-5i]

GPU inputs with automatic host fallback

b = gpuArray([1 3 3 1]);
a = gpuArray([1 1]);
[q, r] = deconv(b, a); % Quotient stays on the GPU when possible
r = gather(r);         % Explicitly gather the remainder if needed on the host

Using deconv with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how deconv changes the result.

Run a small deconv example, explain the result, then change one input and compare the output.

FAQ

What happens if the denominator is empty or entirely zero?

An error is raised. MATLAB requires a non-empty, non-zero denominator polynomial.

Can I pass logical or integer vectors?

Yes. They are promoted to double precision before division so the results match MATLAB exactly.

Why are leading zeros dropped from the outputs?

They do not change the represented polynomial. Dropping them keeps results compact and mirrors MATLAB’s behaviour. The zero polynomial is returned as a single zero.

Does deconv support column vectors?

Absolutely. The orientation of the numerator (b) determines the orientation of both the quotient and remainder.

How should I reconstruct the original polynomial?

conv(a, q) + r (using MATLAB’s polynomial addition rules, which pad shorter vectors on the left) recreates the original numerator.

Are FFT-based deconvolutions supported?

deconv implements exact polynomial long division. For FFT-based signal deconvolution, combine fft, elementwise division, and ifft manually.

What about numerical stability?

deconv mirrors MATLAB’s long-division semantics. For ill-conditioned problems, consider scaling the coefficients or using higher precision (e.g., symbolic toolboxes) just as you would in MATLAB.

Can I request both outputs in one statement?

Yes. [q, r] = deconv(b, a) returns both quotient and remainder; requesting only one output returns the quotient.

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · heaviside · 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

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref

Symbolic

digits · int · limit · sym · syms · vpa

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how deconv is executed, line by line, in Rust.

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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.