I have a matlab code
filter = 1;
F = conv2(double([1 2 1]),double([1 2 1]'))/16;
for i=1:some_integer
filter = conv2(double(filter),double(F));
end
In the code F = conv2(double([1 2 1]),double([1 2 1]'))/16;
equals
a 3 x 3 matrix {{0.0625, 0.125, 0.0625}, {0.125, 0.25, 0.125}, {0.0625, 0.125, 0.0625}}
filter
changes the value in the first iteration from 1
to F
and then in successive iteration the result (convolution matrix) gets larger and larger.
I am having trouble doing this convolution in Mathematica despite having looked at the documentation. Any idea how one might do such a convolution?
My attempt below to compute F
before the loop looks incorrect somehow.
F = Flatten[(ListConvolve[{{0, 0, 0}, {1, 2, 1}, {0, 0, 0}},
{{1, 2, 1}, {1, 2, 1}, {1, 2, 1}}, {-1, 1}, g, Plus, List]/16.0 ), 2]
because the same formulation for ListConvolve
as shown above does not work for filter
inside the loop.
conv2
defined in MATLAB? $\endgroup$F
(testing using octave) appears to be identical toTranspose[Outer[Times, {1,2,1}, {1,2,1}]]
(theTranspose
is there for generality, but the result is symmetric in this case). Assumingfilter
is not a higher-order tensor by the end, however,Outer
is not the same thing asconv2
. $\endgroup$