clear; clf; n=[0:1:100]; n2=[0:1:99]; x=cos(0.425*pi*n)+cos(0.615*pi*n)+0.1*(rand(1)-0.5); y2=[x(1:1:100)]; Y=fft(y2,100); k=[0:1:50]; w=2*pi*k/100; subplot(2,1,1); stem(n2,y2); title('signal x(n), 0 <= n <= 99'); xlabel('n'); pause magY=abs(Y(1:1:51)); plot(w/pi,magY); title('FFT magnitude'); xlabel('frequency in pi units') % obtaining AR PSDE of a time series % x = input sequence % N/2 = number of frequencies % p = order of AR model N=100; p=12; x=detrend(x); p=input('enter order for AR. p = '); A=lpc(x,p); [h,w]=freqz(1,A,N); y=abs(h); subplot(2,1,2); T=num2str(p) myarg=['AR PSDE magnitude with p=',T] plot (w/pi,y); title(myarg); xlabel('frequency in pi units')