필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by