|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
function [s,delt_s,s_cor]=C_CMethod(data)
%this function calculate time delay and embedding demension with C-C
% 该函数用C-C算法来计算延迟时间和嵌入维数
%Method,which proved by H.S.Kim
%skyhawk&flyinghawk
% %****************调试程序段****************************
% clear all;
% data=load('f:/sunpot/year sunpot number.txt');
% %************************************************
N=length(data); % 数据向量长度
max_d=20; %the maximum value of the time delay 时间延迟的最大值
sigma=std(data);%calcute standard deviation s_d 计算标准偏差s_d
for t=1:max_d
t
s_t=0;
delt_s_s=0;
for m=2:5
s_t1=0;
for j=1:4
r=sigma*j/2;
data_d=disjoint(data,N,t); %将时间序列分解成t个不相交的时间序列
[ll,N_d]=size(data_d);
s_t3=0;
for i=1:t
i
Y=data_d(i,:);
C_1(i)=correlation_integral(Y,N_d,r); %计算C(1,N_d,r,t)
X=reconstitution(Y,N_d,m,t); %相空间重构
N_r=N_d-(m-1)*t;
C_I(i)=correlation_integral(X,N_r,r); %计算C(m,N_r,r,t)
s_t3=s_t3+(C_I(i)-C_1(i)^m); %对t个不相关的时间序列求和
end
s_t2(j)=s_t3/t;
s_t1=s_t1+s_t2(j); %对rj求和
end
delt_s_m(m)=max(s_t2)-min(s_t2); %求delt S(m,t)
delt_s_s=delt_s_s+delt_s_m(m); %delt S(m,t)对m求和
s_t0(m)=s_t1;
s_t=s_t+s_t0(m); %S对m求和
end
s(t)=s_t/16;
delt_s(t)=delt_s_s/4;
s_cor(t)=delt_s(t)+abs(s(t));
end
fid=fopen('result.txt','w');
fprintf(fid,'%f %f %f %f/n',t,s(t),delt_s(t),s_cor(t));
fclose(fid);
t=1:max_d;
plot(t,s,t,delt_s,'.',t,s_cor,'*')
function C_I=correlation_integral(X,M,r)
%the function is used to calculate correlation integral
%C_I:the value of the correlation integral
%X:the reconstituted state space,M is a m*M matrix
%m:the embedding demention
%M:M is the number of embedded points in m-dimensional sapce
%r:the radius of the Heaviside function,sigma/2<r<2sigma
%calculate the sum of all the values of Heaviside
%skyhawk
sum_H=0;
for i=1:M
% fprintf('%d/%d\n',i,M);
for j=i+1:M
d=norm((X(:,i)-X(:,j)),inf);%calculat the distances of each two points in matris M with sup-norm
sita=heaviside(r,d);%calculate the value of the heaviside function
sum_H=sum_H+sita;
end
end
C_I=2*sum_H/(M*(M-1));%the value of correlation integral
function data_d=disjoint(data,N,t)
%the function is used to subdivid the time series into t disjoint time
%series.
%data:the time series
%N:the length of the time series
%t:the index lag
%skyhawk
for i=1:t
for j=1:(N/t)
data_d(i,j)=data(i+(j-1)*t);
end
end
function sita=heaviside(r,d)
%the function is used to calculate the value of the Heaviside function
%sita:the value of the Heaviside function
%r:the radius in the Heaviside function,sigma/2<r<2sigma
%d:the distance of two points
%skyhawk
if (r-d)<0
sita=0;
else sita=1;
end
function X=reconstitution(data,N,m,tau)
%该函数用来重构相空间
% m为嵌入空间维数
% tau为时间延迟
% data为输入时间序列
% N为时间序列长度
% X为输出,是m*n维矩阵
M=N-(m-1)*tau;%相空间中点的个数
for j=1:M %相空间重构
for i=1:m
X(i,j)=data((i-1)*tau+j);
end
end
这是我用到的程序,在此感谢oct和无水!
我输入一组数据,共700个!还有我另外输了论坛上的一组数据(共14个),出现的错误是一样的!如下:
??? Output argument "X" (and maybe others) not assigned during call to "C:\Program Files\MATLAB71\work\reconstitution.m (reconstitution)".
Error in ==> reconstitution at 9
M=N-(m-1)*tau;%相空间中点的个数
Error in ==> C_CMethod at 31
X=reconstitution(Y,N_d,m,t); %相空间重构
700个数据时候,电脑运算后i=1, i=2一直到i=14
是不是tau就是14?
请高手们帮我解决? |
|