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

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2016년 11월 30일
편집: Andrei Bobrov 2016년 11월 30일

0 개 추천

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

Calle Swedhag
Calle Swedhag 2016년 11월 30일
편집: Calle Swedhag 2016년 11월 30일
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?
Image Analyst
Image Analyst 2016년 11월 30일
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?
Calle Swedhag
Calle Swedhag 2016년 11월 30일
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..
Calle Swedhag
Calle Swedhag 2016년 11월 30일
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.
Image Analyst
Image Analyst 2016년 11월 30일
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.
Andrei Bobrov
Andrei Bobrov 2016년 11월 30일
I corrected my answer.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2016년 11월 30일

댓글:

2016년 11월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by