(phixonline)-->
with javascript_semantics
function deconv(sequence g, f)
integer lf = length(f), lg = length(g), lh = lg-lf+1
sequence h = repeat(0,lh)
for n=1 to lh do
atom e = g[n]
for i=max(n-lf,0) to n-2 do
e -= h[i+1] * f[n-i]
end for
h[n] = e/f[1]
end for
return h
end function
function conv(sequence f, h)
integer lf = length(f), lh = length(h), lg = lf+lh-1
sequence g = repeat(0,lg)
for i=1 to lh do
for j=1 to lf do
integer k = i+j-1
g[k] += f[j] * h[i]
end for
end for
return g
end function
constant h = {-8,-9,-3,-1,-6,7},
f = {-3,-6,-1,8,-6,3,-1,-9,-9,3,-2,5,2,-2,-7,-1},
g = {24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7}
procedure test(string desc, eq, sequence r, e)
printf(1,"%s (%ssame as %s): %V\n",{desc,iff(r==e?"":"**NOT** "),eq,r})
end procedure
test(" conv(h,f)","g", conv(h,f),g)
test("deconv(g,f)","h",deconv(g,f),h)
test("deconv(g,h)","f",deconv(g,h),f)