フィルターのクリア

I want to plot the auto correlation function for 15 numbers without using the inbuilt function. My series is P=[ 47,64,23,7​1,38,64,55​,41,59,48,​71,35,57,4​0,58 ] and the plot should be autocorrelation function vs lags.

12 ビュー (過去 30 日間)
I want to plot the auto correlation function for 15 numbers without using the inbuilt function. My code is as follows:
P=[ 47,64,23,71,38,64,55,41,59,48]; %%,71,35,57,40,58 ];
N=length(P);
Q=P(1:N);
R=P(1:N);
N1=length(Q);
N2=length(R);
u=mean(P);
sum= ((Q-u)*(R-u).');
covar0=sum/N1;
for k=1:N-1 %%k is no. of lags and its max value can be 14 here
Q1=P(1:N-k); %%Splitting the series into 2 series separated by lag k
R1=P(1+k:N);
N1_1=length(Q1);
N2_1=length(R1);
sum1= ((Q1-u)*(R1-u).');
covark=sum1/N;
acf=covark/covar0;
acf;
end
But after execution of the loop,I am getting acf value only for last value of k, which rather should have been an array for values of k=1 to 14. I am new to matlab. Plz help me resolve the code.

採用された回答

Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 1 日
編集済み: Shoaibur Rahman 2015 年 1 月 1 日
Replace acf=covark/covar0 ; by acf(k)=covark/covar0;
Also no need to use acf after that line.
After the end of for loop, use:
plot(1:N-1,acf)

その他の回答 (1 件)

jaya priya bharathy
jaya priya bharathy 2019 年 12 月 20 日
how can the above code can be changed so that i would be alble to get the lag at 0.5 and 0 at the end?please explain me.
thank you

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by