let us consider following code
clear all;
B=xlsread('data_generations1','A1','g8:g301');
n=length(B);
L =input('Give the size of the interval: ' );% Number of columns in the Data matrix
m=n-L+1;%number of rows in the Data matrix
X = zeros(m,L);
for i=1:m
X(i,:)=B(i:i+L-1);
end;
S=X*X';
[U,autoval]=eig(S);
[d,i]=sort(-diag(autoval));
d=-d;
U=U(:,i);sev=sum(d);
plot((d./sev)*100),hold on,plot((d./sev)*100,'rx');
title('Singular Spectrum');xlabel('Eigenvalue Number');ylabel('Eigenvalue (% Norm of trajectory matrix retained)')
V=(X')*U;
rc=U*V';
% Step 3: Grouping
I=input('Choose the agrupation of components to reconstruct the series in the form I=[i1,i2:ik,...,iL] ')
Vt=V';
rca=U(:,I)*Vt(I,:);
% Step 4: Reconstruction
y=zeros(n,1);
Lp=min(L,m);
Kp=max(L,m);
for k=0:Lp-2
for m1=1:k+1;
y(k+1)=y(k+1)+(1/(k+1))*rca(m1,k-m1+2);
end
end
for k=Lp-1:Kp-1
for m1=1:Lp;
y(k+1)=y(k+1)+(1/(Lp))*rca(m1,k-m1+2);
end
end
for k=Kp:n
for m1=k-Kp+2:n-Kp+1;
y(k+1)=y(k+1)+(1/(n-k))*rca(m1,k-m1+2);
end
end
figure;subplot(2,1,1);hold on;xlabel('Data poit');ylabel('Original and reconstructed series')
plot(x1);grid on;plot(y,'r')
r=x1-y;
subplot(2,1,2);plot(r,'g');xlabel('Data poit');ylabel('Residual series');grid on
vr=(sum(d(I))/sev)*100;
The fragment of code was used from this site:
http://www.mathworks.com/matlabcentral/fileexchange/8115-singular-spectrum-analysis-smoother/content/ssa.m
When I am running this code averaging
Give the size of the interval: 15
Choose the agrupation of components to reconstruct the series in the form I=[i1,i2:ik,...,iL] 4
I =
4
Attempted to access rca(1,16); index out of bounds because size(rca)=[280,15].
Error in averaging (line 37)
y(k+1)=y(k+1)+(1/(Lp))*rca(m1,k-m1+2);
What is problem in my code? Please help me.