- 积分
- 16
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2013-12-8
- 最后登录
- 1970-1-1
|
发表于 2018-4-30 20:02:29
|
显示全部楼层
% This is an example of scaling EOFs
% Start by constructing a simple data set
norm = input('If you want to normalize input data, type 1, otherwise 0: ')
xnoise=0.5
xnoise = input('Set the noise level: 0.5 is low 2.0 is high: ')
N=100
M=20
per=12.
yes='yes';
no='no '
ans='no '
if norm == 1
ans=yes;
end
% In MATLAB the second index is the row index, which goes across the columns and
% gives the row data.
for i=1:N
for j=1:M
x(j,i)=5.0*(j/M)*(sin(2*pi*(j-1)/(M-1))*sin(2*pi*i/per)+xnoise*randn(1));
end
end
xm=x;
% remove mean and possible standard deviation from data time series
for j=1:M
xbar=mean(x(j,:));
if norm == 1
sdev=std(x(j,:));
else
sdev=1;
end
for i=1:N
xm(j,i)=x(j,i)/sdev-xbar;
end
end
% calculate covariance matrix
C=xm*xm'/N;
%C
% Do eigenanalysis
[E,D]=eig(C);
E
%calculate autocorrelation
for j=1:M
alpha(j,:)=auto(xm(j,:),1);
end
alpha
% the temporal autocorrelation is different for each spatial grid point,
% a problem. Let's kluge this by using the mean of the mean and the maximum
% autocorrelation. We'll take the absolute value before averaging, so that
% random negative correlations can't cancel out positive ones. This is
% conservative.
ralph=(mean(abs(alpha(:,2)))+max(alpha(:,2)))/2.
tau=-1.0/log(ralph)
Nstar=N/(2*tau)
factor=sqrt(2./Nstar)
% Plot Eigenvalues
L=diag(D,0);
LE=L*factor
for j=1:M
ind(j)=M-j+1;
end
errorbar(ind,L,LE)
title(['Eigenvalue Spectrum: Norm= ' ans])
xlabel('index')
pause
% Plot eigenvectors
plot(E(:,M-2:M))
MP=M+1
axis([0 MP -0.60 0.60])
%set(gca,'DataAspectRatio',[1 22 1])
title(['First Three Eigenvectors: Norm= ' ans])
xlabel('Structure dimension')
pause
% Project eigenvectors onto original data to get PCs
Z=E'*x;
plot(Z(M-2:M,:)')
title(['First Three Principle Components: Norm= ' ans])
xlabel('Sampling dimension')
pause
%Normalize principle components time series
ZM=Z;
for i=1:N
for j=1:M
zbar=mean(Z(j,:));
sdev=std(Z(j,:));
ZM(j,i)=Z(j,i)/sdev-xbar;
end
end
% remove mean from original, unnormalized data time series
for i=1:N
for j=1:M
xbar=mean(x(j,:));
xm(j,i)=x(j,i)-xbar;
end
end
% Project data onto normalized PC time series
EM=xm*ZM'/N;
%plot first three dimensional eigenvector regressions
plot(EM(:,M-2:M))
xmax=max(abs(EM(:,M)))*1.2;
axis([0 MP -xmax xmax])
title(['Regressions of First Three Normalized PCs on Unnormalized Data: Norm= ' ans])
xlabel('Structure dimension')
pause
|
|