?? periodogram estimate.m
字號:
%************原題**************************%
%Generate 100 samples of a zero-mean white noise sequence with variance , by using a uniform random number generator.
%a Compute the autocorrelation of for .
%b Compute the periodogram estimate and plot it.
%c Generate 10 different realizations of , and compute the corresponding sample autocorrelation sequences , and . Compute the average autocorrelation sequence as and the corresponding periodogram for .
%d Compute and plot the average periodogram using the Bartlett method.
%e Comment on the results in parts (a) through (d).
w=normrnd(0,1/12^0.5,[1,100]);
%***********a****************%
r=xcorr(w,w)';
for i=1:16
rxx(i)=r(100-i);
end
wr=fft(rxx);
for i=1:16
zr(i)=conj(wr(i))*wr(i);
end
tr=1:1:16;
plot(tr,zr,':')
title('直接法得到的周期圖');
%************b***************%
wf=fft(w);
for i=1:100
zav(i)=conj(wf(i))*wf(i);
end
zav=zav/100;
t=1:1:100;
figure
plot(t,zav,':')
title('間接法得到的周期圖');
%************c****************%
for i=1:10
A(i,:)=normrnd(0,1/12^0.5,[1,100]);
end %產(chǎn)生10條樣本序列
for i=1:10
a(i,:)=normrnd(0,1/12^0.5,[1,100]);
ra=xcorr(a(i,:),a(i,:))';
for j=1:16
raa(i,j)=ra(100-j);
end
end %分別計算10條樣本序列的自相關存在raa數(shù)組中
for i=1:10
sum=zeros(1,16);
sum=sum+raa(i,:);
end
rav=sum/10; %計算平均相關函數(shù)
ravf=fft(rav);
for i=1:16 %取模
ravv(i)=(conj(ravf(1,i))*ravf(1,i))^0.5;
end
tt=1:1:16;
figure
plot(tt,ravv)
title('先求平均的間接法');
%*************d*****************%
%分成5塊
for i=1:5
for j=1:20
ww5(i,j)=w((i-1)*20+j);
end
end %分塊
for i=1:5
d5=fft(ww5(i,:));
for j=1:20
each5(i,j)=conj(d5(1,j))*d5(1,j);
end
end %分別計算每塊的周期圖
sumeach5=zeros(1,20);
for i=1:5
sumeach5=sumeach5+each5(i,:);
end
sumave5=sumeach5/20; %平均周期圖
td5=1:1:20;
figure
plot(td5,sumave5)
title('平均周期圖法,5塊');
%分成10塊
for i=1:10
for j=1:10
ww10(i,j)=w((i-1)*10+j);
end
end %分塊
for i=1:10
d10=fft(ww10(i,:));
for j=1:10
each10(i,j)=conj(d10(1,j))*d10(1,j);
end
end %分別計算每塊的周期圖
sumeach10=zeros(1,10);
for i=1:10
sumeach10=sumeach10+each10(i,:);
end
sumave10=sumeach10/10; %平均周期圖
td10=1:1:10;
figure
plot(td10,sumave10)
title('平均周期圖法,10塊');
%分成20塊
for i=1:20
for j=1:5
ww20(i,j)=w((i-1)*5+j);
end
end %分塊
for i=1:20
d20=fft(ww20(i,:));
for j=1:5
each20(i,j)=conj(d20(1,j))*d20(1,j);
end
end %分別計算每塊的周期圖
sumeach20=zeros(1,5);
for i=1:20
sumeach20=sumeach20+each20(i,:);
end
sumave20=sumeach20/5; %平均周期圖
td20=1:1:5;
figure
plot(td20,sumave20)
title('平均周期圖法,20塊');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -