# Bug detected in deconvolution operation deconv()

**URL:** <https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546>\
**Category:** Signal and Image Processing\
**Tags:** bug, dsp\
**Created:** [November 3, 2020, 6:22pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546 "2020-11-03T18:22:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [November 3, 2020, 6:22pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546/1 "2020-11-03T18:22:25Z")

</div>

The `DSP` package contains some routines very vital and basic to Fourier analysis. However the simple deconvultion operation is not working. Consider the following simple code

```julia
using DSP;
a = zeros( Float64, 5); a[3]=10;
b = zeros( Float64, 5); b[3]=0.1;
c = conv(a,b);
d = deconv(c,a); display(d');

```

Thus a, b represent the Fourier basis of simple Fourier functions and the coefficients are inverses of each other. The vector c is thus all zeros with one 1. Deconvoluting against c however doesnt give b. It gives the error :

```julia
ERROR: ArgumentError: filter vector a[1] must be nonzero
Stacktrace:
 [1] filt!(::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\iamsu\.julia\packages\DSP\RUXAo\src\dspbase.jl:34
 [2] deconv(::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\iamsu\.julia\packages\DSP\RUXAo\src\dspbase.jl:18
 [3] top-level scope at none:0

```

Since the mathematics is simple and correct, this reveals a bug in the routine.

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [November 4, 2020, 12:30pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546/2 "2020-11-04T12:30:48Z")

</div>

I can’t comment on the bug or the maths, but I’d recommend posting this as an issue on [https://github.com/JuliaDSP/DSP.jl/issues](https://github.com/JuliaDSP/DSP.jl/issues) directly.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 4, 2020, 7:42pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546/3 "2020-11-04T19:42:17Z")

</div>

Indeed, the `deconv` function does not produce polynomial division, as advertised, if the denominator has its first coefficient = 0. The function `divrem` produces a correct result in dividing **c** by **a** :

```julia
using Polynomials, DSP
a = [0, 0, 10.0, 0, 0]
b = [0, 0, 0.1, 0, 0]
c = conv(a,b)
A = Polynomial(a)
C = Polynomial(c)
D, r = divrem(C,A);
d = coeffs(D)

```

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [November 10, 2020, 9:34pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546/4 "2020-11-10T21:34:06Z")

</div>

Thats a nice fix. I am doing it explicitly while using the Shannon-Nyquist sampling frequency.

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [November 10, 2020, 9:34pm UTC](https://discourse.julialang.org/t/bug-detected-in-deconvolution-operation-deconv/49546/5 "2020-11-10T21:34:17Z")

</div>

Thanks, I will try to.
