a b/preprocessOfApneaECG/BioSigKit/Algorithms/phasespace.m
1
function [Y,T]=phasespace(x,dim,tau)
2
%Syntax: [Y,T]=phasespace(x,dim,tau) 
3
%___________________________________ 
4
%
5
% The phase space reconstruction of a time series x with the Method Of Delays
6
% (MOD), in embedding dimension m and for time dalay tau. 
7
% 
8
% Y is the trajectory matrix in the reconstructed phase space.
9
% T is the phase space length.
10
% x is the time series. 
11
% dim is the embedding dimension.
12
% tau is the time delay.
13
%
14
%
15
% Reference:
16
% Takens F (1981): Detecting strange attractors in turbulence. Lecture notes in
17
% Mathematics, 898. Springer.
18
%
19
%
20
% Alexandros Leontitsis
21
% Department of Education
22
% University of Ioannina
23
% 45110 - Dourouti
24
% Ioannina
25
% Greece
26
%
27
% University e-mail: me00743@cc.uoi.gr
28
% Lifetime e-mail: leoaleq@yahoo.com
29
% Homepage: http://www.geocities.com/CapeCanaveral/Lab/1421
30
%
31
% 11 Mar 2001.
32
33
if nargin<1 || isempty(x)==1
34
   error('You should provide a time series.');
35
else
36
   % x must be a vector
37
   if min(size(x))>1
38
      error('Invalid time series.');
39
   end
40
   x=x(:);
41
   % N is the time series length
42
   N=length(x);
43
end
44
45
if nargin<2 || isempty(dim)==1
46
    dim=2;
47
else
48
    % dim must be scalar
49
    if sum(size(dim))>2
50
        error('dim must be scalar.');
51
    end
52
    % dim must be an integer
53
    if dim-round(dim)~=0
54
        error('dim must be an integer.');
55
    end
56
    % dim must be positive
57
    if dim<=0
58
        error('dim must be positive.');
59
    end
60
end
61
62
if nargin<3 || isempty(tau)==1
63
    tau=1;
64
else
65
    % tau must be scalar
66
    if sum(size(tau))>2
67
        error('tau must be scalar.');
68
    end
69
    % tau must be an integer
70
    if tau-round(tau)~=0
71
        error('tau must be an integer.');
72
    end
73
    % tau must be positive
74
    if tau<=0
75
        error('tau must be positive.');
76
    end
77
end
78
79
% Total points on phase space 
80
T = N - (dim-1)*tau;
81
82
% Initialize the phase space
83
Y = zeros (T,dim);
84
85
% Phase space reconstruction with MOD
86
for i = 1 : T
87
   Y(i,:) = x(i+(0:dim-1)*tau)';
88
end