Deconvolution/1D: Difference between revisions

Content added Content deleted
(→‎{{header|Java}}: fixed error in deconv method where input parameters were reversed; changed array types from double[] to int[]; updated output; removed "untested" banner.)
m ({{out}})
Line 6: Line 6:
:<math> G(n) = \sum_{m=-\infty}^{\infty} F(m) H(n-m) </math>
:<math> G(n) = \sum_{m=-\infty}^{\infty} F(m) H(n-m) </math>


for all integers <math>\mathit{n}</math>. Assume <math>F(n)</math> can be non-zero only for <math>0</math> &le; <math>\mathit{n}</math> &le; <math>|\mathit{F}|</math>, where <math>|\mathit{F}|</math> is the "length" of <math>\mathit{F}</math>, and similarly for <math>\mathit{G}</math> and <math>\mathit{H}</math>, so that the functions can be modeled as finite sequences by identifying <math>f_0, f_1, f_2, \dots</math> with <math>F(0), F(1), F(2), \dots</math>, etc. Then for example, values of <math>|\mathit{F}| = 6</math> and <math>|\mathit{H}| = 5</math> would determine the following value of <math>\mathit{g}</math> by definition.
for all integers <math>\mathit{n}</math>. Assume <math>F(n)</math> can be non-zero only for <math>0</math> &le; <math>\mathit{n}</math> &le; <math>|\mathit{F}|</math>, where <math>|\mathit{F}|</math> is the "length" of <math>\mathit{F}</math>, and similarly for <math>\mathit{G}</math> and <math>\mathit{H}</math>, so that the functions can be modeled as finite sequences by identifying <math>f_0, f_1, f_2, \dots</math> with <math>F(0), F(1), F(2), \dots</math>, etc.
Then for example, values of <math>|\mathit{F}| = 6</math> and <math>|\mathit{H}| = 5</math> would determine the following value of <math>\mathit{g}</math> by definition.


:<math>
:<math>
Line 120: Line 121:
NEXT
NEXT
= LEFT$(LEFT$(a$))</lang>
= LEFT$(LEFT$(a$))</lang>
{{out}}
'''Output:'''
<pre>
<pre>
deconv(g,f) = -8, -9, -3, -1, -6, 7
deconv(g,f) = -8, -9, -3, -1, -6, 7
Line 219: Line 220:
for (int i = 0; i < lh; i++) printf(" %g", h2[i]);
for (int i = 0; i < lh; i++) printf(" %g", h2[i]);
printf("\n");
printf("\n");
}</lang>
}</lang>Output<lang>f[] data is : -3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1
{{out}}<pre>f[] data is : -3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1
deconv(g, h): -3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1
deconv(g, h): -3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1
h[] data is : -8 -9 -3 -1 -6 7
h[] data is : -8 -9 -3 -1 -6 7
deconv(g, f): -8 -9 -3 -1 -6 7</lang>
deconv(g, f): -8 -9 -3 -1 -6 7</pre>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 424: Line 426:
return h
return h
}</lang>
}</lang>
{{out}}
Output:
<pre>
<pre>
[-8 -9 -3 -1 -6 7]
[-8 -9 -3 -1 -6 7]
Line 431: Line 433:
[-3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1]
[-3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1]
</pre>
</pre>

{{trans|C}}
{{trans|C}}
<lang go>package main
<lang go>package main
Line 585: Line 588:
}
}
}</lang>
}</lang>
{{out}}
Output:
<pre>
<pre>
h = [-8, -9, -3, -1, -6, 7]
h = [-8, -9, -3, -1, -6, 7]
Line 634: Line 637:
deconv[f,g]
deconv[f,g]
</pre>
</pre>
{{out}}
Gives the output:
<pre>{-8, -9, -3, -1, -6, 7}</pre>
<pre>{-8, -9, -3, -1, -6, 7}</pre>


=={{header|MATLAB}}==
=={{header|MATLAB}}==
The deconvolution function is built-in to MATLAB as the "deconv(a,b)" function, where "a" and "b" are vectors storing the convolved function values and the values of one of the deconvoluted vectors of "a". To test that this operates according to the task spec we can test the criteria above:
The deconvolution function is built-in to MATLAB as the "deconv(a,b)" function, where "a" and "b" are vectors storing the convolved function values and the values of one of the deconvoluted vectors of "a".
To test that this operates according to the task spec we can test the criteria above:
<lang MATLAB>>> h = [-8,-9,-3,-1,-6,7];
<lang MATLAB>>> h = [-8,-9,-3,-1,-6,7];
>> g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7];
>> g = [24,75,71,-34,3,22,-45,23,245,25,52,25,-67,-96,96,31,55,36,29,-43,-7];
Line 741: Line 745:
.say for ~@f, ~deconvolve(@g, @h),'';</lang>
.say for ~@f, ~deconvolve(@g, @h),'';</lang>


{{out}}
Output:
<pre>
<pre>
24 75 71 -34 3 22 -45 23 245 25 52 25 -67 -96 96 31 55 36 29 -43 -7
24 75 71 -34 3 22 -45 23 245 25 52 25 -67 -96 96 31 55 36 29 -43 -7
Line 907: Line 911:
(deconvolve g h)
(deconvolve g h)
</lang>
</lang>
{{out}}
Output:
<lang racket>
<lang racket>
#<array '#(6 1) #[-8 -9 -3 -1 -6 7]>
#<array '#(6 1) #[-8 -9 -3 -1 -6 7]>
Line 1,036: Line 1,040:
pp "deconv(g,h) = f" [1D deconvolve $g $h]
pp "deconv(g,h) = f" [1D deconvolve $g $h]
pp " conv(f,h) = g" [1D convolve $f $h]</lang>
pp " conv(f,h) = g" [1D convolve $f $h]</lang>
{{out}}
Output:
<pre>
<pre>
deconv(g,f) = h = [-8,-9,-3,-1,-6,7]
deconv(g,f) = h = [-8,-9,-3,-1,-6,7]
Line 1,071: Line 1,075:
'f': deconv(g,h)>
'f': deconv(g,h)>
</lang>
</lang>
{{out}}
output:
<pre>
<pre>
<
<