What does the deconv function do in MATLAB / RunMat?
deconv(b, a) performs one-dimensional polynomial long division. Given coefficient vectors b
and a, it returns a quotient q and remainder r such that
conv(a, q) + r == b
Coefficients follow MATLAB conventions: the first entry stores the highest-order term and the last entry stores the constant term. Both real and complex inputs are supported.
How does the deconv function behave in MATLAB / RunMat?
- 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 equalsb. - 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.
deconv Function GPU Execution Behaviour
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:
- Gathers the device operands into host memory.
- Performs the polynomial long division on the CPU.
- 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 of using the deconv function in MATLAB / RunMat
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 outputs:
q = [1 -3 2];
r = 0;
Obtaining a non-zero remainder
[q, r] = deconv([1 4 7], [1 2]);
Expected outputs:
q = [1 2];
r = [3];
Dividing by a longer sequence
[q, r] = deconv([3 5], [1 0 2]);
Expected outputs:
q = 0;
r = [3 5];
Handling leading zeros explicitly
b = [0 0 1 2];
a = [0 1 1];
[q, r] = deconv(b, a);
Expected outputs (leading zeros preserved only when necessary):
q = [1];
r = [1];
Complex polynomial division
b = [1+2i 3-4i 2];
a = [1-i 2+i];
[q, r] = deconv(b, a);
Expected outputs:
q = [1+0i 1-2i];
r = [0+0i];
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
Before calling gather, both outputs remain on the GPU (real-valued results are re-uploaded
automatically) and match the CPU calculation: the quotient is [1 2 1] and the remainder is 0.
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.
See Also
conv, conv2, fft, ifft, gpuArray, gather
Source & Feedback
- Full source:
crates/runmat-runtime/src/builtins/math/signal/deconv.rs - Found an issue? Open a ticket with a minimal reproduction.