%% Compute Correlation Between Two Signals
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes  step(obj,x).
% Compute the cross-correlation between two sinusoidal signals using the dsp.Crosscorrelator object. Perform the computation in the time domain, which is the object's default setting.

xcorr = 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 = xcorr(x1,x2);
figure
plot(t,x1,'b',t,x2,'g')
xlabel('Time')
ylabel('Signal Amplitude')
legend('Input signal 1','Input signal 2')

%
% Plot the correlated output.

figure, 
plot(y)
title('Correlated output')

% Copyright 2012 The MathWorks, Inc.