Conv2 explanation for specific example

조회 수: 4 (최근 30일)
Leo
Leo 2011년 7월 26일
Hey Guys, i need some help for the conv2 implementation for given problem:
K>> conv2([1 2 3], [1 0 0], 'full')
ans =
1 2 3 0 0
Why are the zeros on the right side? Does varies with the border depending on the kernel-center?
For this example its clear:
K>> conv2([1 2 3], [1 0 1], 'full')
ans =
1 2 4 2 3
Thanks for your help, Leo

답변 (4개)

Jan
Jan 2011년 7월 26일
Because you have vectors, your example is equivalent to:
conv([1, 2, 3], [1, 0, 0])
The algorithm of CONV is described exhaustively in: doc conv
E.g. the last element of the result is "w(2*n-1) = u(n)*v(n)", which is 0 in your example. Perhaps your are searchng for the 'same' or 'valid' shapes?
  댓글 수: 2
the cyclist
the cyclist 2011년 7월 26일
I noticed with a bit of amusement that conv() calls conv2().
Jan
Jan 2011년 7월 26일
Indeed?
In Matlab 6.5 it called FILTER after reordering the inputs: CONV(A, B) equals CONV(B, A), but FILTER(B, 1, A) is faster, if length(A) < length(B).
I think I should read through all of the toolbox functions again...

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


the cyclist
the cyclist 2011년 7월 26일
Isn't the convolution calculation essentially doing what I have written below? Does that make it clearer where the zeros come from?
a = [1 2 3]
b = [1 0 0]
conv_a_b = b(1)*[a 0 0] + b(2)*[0 a 0] + b(3) * [0 0 a]

Leo
Leo 2011년 7월 26일
thank you for your really quick responses! @Jan: yeah, i read conv2, but there is no information about how MATLAB set the paddings. In my work I have to apply a shift_kernel on a matrix to center the kernel, and the shif-kernel could be a matrix too. @cyclist: not really.. should 'a' replaced by [1 2 3] -> b(1) * [1 2 3 0 0] + ... ?
best, leo
  댓글 수: 1
the cyclist
the cyclist 2011년 7월 26일
In response to what you said to Jan: There is no "padding". MATLAB is treating the trailing zeros in "b" exactly how it would treat them if they were non-zero, and giving you the result.
In response of what you said to me: Yes. What I typed is functional code, using the "a" that you defined.

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


Leo
Leo 2011년 8월 2일
Hey guys,
thanks for your answers. I had an error in reasoning. I forgot that the kernel should be mirrored.
Best!

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by