corr_conv.m

来自「calculate the correlation and convolutio」· M 代码 · 共 23 行

M
23
字号
%Compare the calculations of convolution and correlation of two arrays..

x = [1 2 4 -2 3 -6];
y = [-1 2 4 -3 5];
xy_corr = xcorr(x,y);
y = -y;
y = fliplr(y);
xy_conv = conv(x,y);
lth = max(length(xy_corr),length(xy_conv));

if 1,
%     stem(1:lth+1,xy_corr,1:lth+1,xy_conv);
    legend('Correlation','Convolution')
    title('Comparation')
% %       stem(1:lth,xy_corr)
      stem(1:lth,xy_corr,'bo--')
      hold on
      stem(1:lth-1,xy_conv,'rx')
%       hold on
%       stem(xy_conv,'kx')
end

    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?