% Example of CCF calculation to identify signal from noise
% David Pan, for EE 385

clear all;
noise = 3*randn(1, 1001); % noise
theta = random('Uniform', 0, 2*pi); 
t = 0: 0.001 : 1; % sampling index
x = cos(100*pi*t + theta);  % random signal

y = x + noise;
[t1, Ry] = corb(y, y, 1000) ; % autocorrelation

xd = cos(100*pi*t);  % determinisitc signal for detection
[t2, Rxy] = corb(xd, y, 1000) ; % crosscorrelation
subplot(3, 1, 1); 
plot(t,y);
xlabel('TIME'); ylabel('Y');
subplot(3, 1, 2); 
plot(t1,Ry);
xlabel('LAG'); ylabel('R_Y');
subplot(3, 1, 3); 
plot(t2,Rxy);
xlabel('LAG'); ylabel('R_{XY}');