I have noticed a shift of -1 when doing convolution in MatLab (R2011b) using the conv function and I don't understand why. I am using the 'same' option to the convolution function because my signal and the function I am convolving with are the same N pixels in length and I want my result to also be N pixels.
This shift only happens when I have my value of N as even number.
I wrote this short script to illustrate the problem. It convolves a rectangle pulse with an impulse response, so I dont expect any shift in my result.
%% Set up rectangle pulse
N = 21;
signal = zeros(N, 1);
% Designate some pixels in the signal as 1's to make rectangle pulse
signal(9:11) = 1;
%% Set up impulse for convolution
impulse = zeros(N, 1);
impulse(round(N/2)) = 1;
%% Convolution
convolutionResult = conv(signal, impulse, 'same');
%% Plot Results - not shown
When N is odd the result looks OK, i.e. the rectangle pulse has values of 1 at pixels 9, 10 and 11, as expected, the same as before convolution.

But if N is odd, then the rectangle pulse has values of 1 at pixels 8, 9 and 10, so a shift of -1 which I don't get. Thanks in advance.

Does anybody understand why this happens?