I'm looking for an elegant way to compute the "product" of a discrete convolution, instead of the sum.
Here is the formula of a discrete convolution:
In this case we can use: conv(x,y)
Now I would like to implement those operations
Of course I can use a loop, but I'm looking for a trick in order to linearize this operation.
EXAMPLE:
f = [2 4 3 9 7 1]
g = [3 2 1]
dist = length(g)-1;
for ii = 1:length(f)-dist
x(ii) = prod(f(ii:ii+dist).*g)
end
x =
144 648 1134 378
Another solution partly inspired by Dev-iL answer to relatively the same question
or
since
exp(sum(log(x))) = prod(x)
But here instead of one vector we have two vectors
f
andg
.The desired formula can be reformulated as:
Timing in octave:
Result: