Assume that we have two simple sequences with different lengths:
x = rand(3,1);
y = rand(2,1);
I calculated the cross correlation between them and plot it such below:
r_1 = xcorr(x,(y));
tx = 1:length(x);
ty = 1:length(y);
tr = ceil(-(length(x)+length(y)-1)/2) : floor((length(x)+length(y)-1)/2);
subplot(2,2,1); stem(tr,r_1); title('XC');
I wanted to calculate the cross correlation using convolution and show that it's result is equal to the result when using xcorr(). But when I implemented it like this:
r_2 = conv(x,fliplr(y));
tx = 1:length(x);
ty = 1:length(y);
tr = ceil(-(length(x)+length(y)-1)/2) : floor((length(x)+length(y)-1)/2);
subplot(2,2,1); stem(tr,r_2); title('XC');
the length of r_1 and r_2 are different and I got this error:
Error using stem (line 43) X must be same length as Y.
Thanks for your helps.