Convolution of every row in matrix.

I need to find a way to convolute rows of a matrix together into a single vector. For example: If I have a matrix A = [1,2;3,4;5,6] need a function that will produce a vector B = conv(conv(A(1,:) , A(2,:)), A(3,:))
Is there any function that could do that? If no, could someone help me write a loop to do it for me?
Thanks

Answers (1)

Andrei Bobrov
Andrei Bobrov on 30 Nov 2016
Edited: Andrei Bobrov on 30 Nov 2016
A = reshape(1:6,2,[])';
[m,n] = size(A);
B = zeros(1,m*(n-1)+1);
B(1:n) = A(1,:);
for ii = 1:size(A,1)-1
B(1:n-ii+ii*n) = conv(B(1:ii*n-ii+1),A(ii+1,:));
end

6 Comments

Calle Swedhag
Calle Swedhag on 30 Nov 2016
Edited: Calle Swedhag on 30 Nov 2016
Thank you! How about if I make my matrix A a three-column one and the number of rows are, let's say k? What changes do I have to do to your solution for it to do the same thing: convolute the rows?
Seems like a very strange thing to do. What are you after? What's the real world use of this? Are you trying to demonstrate the Central Limit Theorem or something???
And how many rows get convolved? Just 3 at a time, like your initial example showed, until you hit the bottom? Or all of them from the first row down, like k nested convolutions?
I am constructing a resonance filter for my schoolwork. The numbers in each row corresponds to a coefficient in a polynom, for example: (1 + 2z^-1 + 4z^-1). Every row symbolises a new polynom on the same form, it might be:(3 + 7z^-1 + 11z^-2). For the filter to work I need to multiply all the polynomials together. I thought of doing so by convoluding every row into one GIANT polynomial. K nested convolutions as you said, where K is the number of rows in my Kx3 matrix. Don't know if this is the smartest procedure but it was the one I came up with..
Maybe I should explain my real problem a bit more thoroughly. I have an input vector F that could be thousands of elements long. For this example lets say F is [1,2,3,4,5].
I then have a function that generates polynomial coefficients out of element k in F. The function could be
[k^2, 5*k, k+2]
for F(1) the polynomial is [1^2, 5*1, 1+1] and so on. After generating polynomial coefficients for all elements k in F, I have to multiply them all together. I thought a convolution loop might work here, but it might be a bit too complex. Remember that in this example the number of elements in F was 5, but it might as well be thousands.
Convolution is not multiplying poynomials together. What your nested convolution will produce is a gigantic Gaussian. That's what the central limit theorem guarantees. Any function(s), almost no matter what shape, if convolved more than about 5 or 6 times will look very close to a Gaussian.
I corrected my answer.

Sign in to comment.

Categories

Asked:

on 30 Nov 2016

Commented:

on 30 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!