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.
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.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. 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. auto correlation, for loop MATLAB Answers — New Questions