%ECOMMS Spring 00 Class Demo
%S. Mandayam, ECE Dept., Rowan University

%To illustrate the autocorrelation function

close all; clear;

%Defining time-domain signals
w=zeros(1000,1);
w1=w;w1(400:600)=1;
w2=w;w2(200:800)=1.01;
w3=w;w3(100:900)=1.02;
t=1:length(w);
figure(1);
plot(t,w1,t,w2,t,w3);
legend ('w_1(t)','w_2(t)','w_3(t)');
axis([0 1000 -1 2]);
title('Time domain signals');
xlabel('time, t in seconds');

pause;

%Computing autocorrelation functions
r1=xcorr(w1);
r2=xcorr(w2);
r3=xcorr(w3);
tau=1:length(r1);
figure(2);
plot(tau,r1,tau,r2,tau,r3);
legend ('R_1(\tau)','R_2(\tau)','R_3(\tau)');
title('Autocorrelation Functions');
xlabel('time delay, \tau in seconds');

