I want to plot the auto correlation function for 15 numbers without using the inbuilt function. My series is P=[ 47,64,23,71,38,64,55,41,59,48,71,35,57,40,58 ] and the plot should be autocorrelation function vs lags.
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sharda
le 1 Jan 2015
Réponse apportée : jaya priya bharathy
le 20 Déc 2019
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.
0 commentaires
Réponse acceptée
Shoaibur Rahman
le 1 Jan 2015
Modifié(e) : Shoaibur Rahman
le 1 Jan 2015
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)
Plus de réponses (1)
jaya priya bharathy
le 20 Déc 2019
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
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!