% Autocorrelation Program... TLD 01
% This program creates a simulated data set by superimposing a
% random signal with a sine wave
% It then animates the data sets and their predicted crosscorrelation results
% There are functions in matlab that will do this for you too!
n = 1024;
t = 1:n;
%a random data set with mean removed (for fun)
noisey1 =2.0*rand(1,n);
noisey = noisey1 - mean(noisey1);
% here is the sine and its addtion to the random stuff
data = 0.5*sin(0.1*t);
total = noisey + data;
M = moviein(50);
for j = 1:50;
dt = 1*(j-1);
subplot(2,1,1);
plot(t,total,'o', dt + t(1:n-dt),total(1:n-dt),'x');
subplot(2,1,2);
autocor = sum(total(1:n-dt).*total(dt:n-1))/sum(total(1:n).*total(1:n));
plot(t,0,dt,autocor,'x');
axis([0 200 -1 1]);
M(:,j) = getframe;
end;
movie(M);