www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/toolbox/SSA/ssa_analysis.m

    function SSA=ssa_analysis(data,delay,emb_dim);
% SSA_ANALYSIS provide singular spectrum analysis 
% emb_dim - embedding dimension
% example: SSA=ssa_analysis(rand(100,1),1,20);
%
% last modified 10.02.05
%
% References: 
% [1] Golyandina N., Nekrutkin V., Zhigljavsky A.  Analysis of Time Series Structure:
%     SSA and Related Techniques. Boca Raton: Chapman & Hall/CRC. 2001. 305 p
% [2] N.E. Golyandina V.V.Nekrutkin, D.V. Stepanov Variants of the caterpillar-ssa 
%     method for analysis of multidimensional time series http://www.gistatgroup.com/gus/ 


if nargin<1
    error('Not enought input parameters')
    return
end
if nargin<3
    delay=[];
    emb_dim=[];
end

x=data;

if isempty(delay)|isempty(emb_dim)
	prompt = {'Enter delay (in sample points):','Enter embedding dimension:'};
	dlg_title = 'Input for SSA';
	num_lines= 1;
	def     = {'1','10'};
	answer  = inputdlg(prompt,dlg_title,num_lines,def);
	if isempty(answer)
        return
	end
else
    answer{1}=num2str(delay);
    answer{2}=num2str(emb_dim);
end

L=str2num(answer{2});
delay=str2num(answer{1});
N=length(x);
K=N-delay*(L-1);  %% K must be positive!!!
if K<1
    errordlg('Wrong parameters. Cancelled','error');
    return
end

X=zeros(L,K);
for i=1:L
    X(i,:)=x(1+delay*(i-1):delay*(i-1)+K)';
end

[U,S,V] = svd(X,0);
% U_i by the columns
% V_i first L columns 
SSA.singular_numbers=diag(S);
SSA.V=V(:,1:L);
SSA.U=U;
SSA.delay=delay;
SSA.emb_dim=emb_dim;
SSA.groups={};
SSA.base_data=x;
ssa_view_singular_spectrum(SSA);
% add_to_log(['SSA using: ' GSD.ssa.base_data_name '; Embedding dimension: ' num2str(L) '; Delay: ' num2str(delay)]);
% GSD_GLOBALS.en_dis.ssa=1;
% GSD_GLOBALS.en_dis.ssa_groups=0;
% gui_en_dis;