Reputation: 339
I read Matlab documentation about convolution and i have found this :
u = [-1 2 3 -2 0 1 2]; v = [2 4 -1 1]; w = conv(u,v,'same')
And the answer is
w = 15 5 -9 7 6 7 -1
Do you know how was w calculated? I know how you calculate the normal convolution product, but what about this?
Thank you for you help in advance !
Upvotes: 0
Views: 2870
Reputation: 11
Actually the above answer is almost correct, except for the misplaced u and v in the last line of the code. That is:
w = w_full(floor(length(v)/2) + (1:length(u))); % 'same' like convolution
After all, the length of the output is the same as the length of u, not v.
Upvotes: 1
Reputation: 11
Apparently your question is how to determine the limits of the convolution when shape is set to 'same'. From the 'full' shape convolution provided by Matlab, 'same' subvector can be calculated as follows:
u = [-1 2 3 -2 0 1 2];
v = [2 4 -1 1];
w = conv(u,v,'same');
w_full = conv(u,v,'full'); % full size (zero-padded) convolution
w = w_full(floor(length(u)/2) + (1:length(v))); % 'same' like convolution
Upvotes: 0