% Listing 10.2 of the book for Figure 10.4
% "Principles of System Identification: Theory and Practice"

% Arun K. Tangirala
% April 02, 2015
% Freely distributed under no warranty

%% Generate the sine wave
k1 = (0:200)';
xk1 = cos(2*pi*0.05*k1);
% Plot the signal
figure; stem(k1(1:41),xk1(1:41))
% Compute the ACVF and plot it
[xk_acf,lags] = xcorr(xk1,40,'biased');
figure; stem(lags(L1+1:end),xk_acf(L1+1:end))

%% Generate the exponentially decaying signal
k2 = (0:200)'; alpha = -0.05;
xk2 = exp(alpha*k2);
% Plot the signal
figure; stem(k2(1:100),xk2(1:100))
% Compute the ACVF and plot it
[xk_acf,lags] = xcorr(xk2,40);
figure; stem(lags(L2+1:end),xk_acf(L2+1:end))