www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ComputeCorrelationBetweenTwoSignalsExample.m

    %% Compute Correlation Between Two Signals
%%
% *Note*: This example runs only in R2016b or later. If you are using an
% earlier release, replace each call to the function with the equivalent
% |step| syntax. For example, myObject(x) becomes step(myObject,x).

%%
hcorr = dsp.Crosscorrelator;
t = [0:0.001:1];
x1 = sin(2*pi*2*t)+0.05*sin(2*pi*50*t);
x2 = sin(2*pi*2*t);
y = hcorr(x1,x2); %computes cross-correlation of x1 and x2
figure,plot(t,x1,'b',t, x2, 'g');
legend('Input signal 1',' Input signal 2')
figure, plot(y); title('Correlated output')