close all
nr=1000; % nr of samples
a=-0.9; h=1;
w=randn(nr,1);
y = filter(1,[1 a],w);
figure(1); plot(y,'linewidth',1.4)
set(gca,'fontsize',18,'fontweight','b')
title('AR process realisation')
[C,tau] = xcorr(y,50,'unbiased');
figure(2); plot(tau,C,'linewidth',1.4);
hold on; set(gca,'fontsize',18,'fontweight','b')
plot(tau,1/(1-a^2)*(-a).^abs(tau),'r--','linewidth',1.4);
legend('xcorr estimate', 'theoretical')
title('Covariance function')
figure(3); nrpoints=512;
[Pxx,f]=pwelch(y,[],[],nrpoints,1/h);
loglog(f,Pxx,'linewidth',1.4); hold on;
loglog(f,1./(1+a^2+2*a*cos(2*pi*f)),'r--','linewidth',1.4)
legend('pwelch estimate', 'theoretical')