-
Notifications
You must be signed in to change notification settings - Fork 2
/
sig_to_imf.m
109 lines (96 loc) · 3.79 KB
/
sig_to_imf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
% Function name....: sig_to_imf
% Date.............: December 13, 2002
% Author...........: Adriano de Oliveira Andrade
% Description......:
% sig_to_imf decomposes an input time-series x into its intrinsic mode functions.
% Parameters.......:
% x .....-> input time-series (row vector)
% mse .....-> mean squared error
% interpMethod .....-> if 0 then splines are used otherwise
% pchip is employed
% Return...........:
% i_m_fs.....-> intrinsic mode functions(matrix: each
% row is an IMF, where the first row is the first imf
% and so on ...
% r..........-> this is the residue
% Remarks..........:
% The number of imfs generated is dependent on the mse. It is important
% to observe that a very small value for the mse can produce functions
% that are not really imfs but a simple trend that will hardly contribute
% to the final spectrum of the original signal.
% Revision.........:
% 1st: April/2003
% For compilation: mcc -x sig_to_imf (MatLab compiler should be available)
% Example........:
% [i_m_fs,r]= sig_to_imf(x,1e-5,1);
function [i_m_fs,r]= sig_to_imf(x,mse,interpMethod)
%initializing variables
t=length(x);
imf_old=zeros(1,t);
i_m_fs=[];%each line of this array is one imf
r=x; %r:residue
k=0; %iteration counter
m_s_e = mse + 1;%mse: mean squared error
%Displaying the chosen interpolation method
if(interpMethod==0),
disp('Interpolation method: splines');
else
disp('Interpolation method: pchip');
end;
%Before starting the sifting process is important to verify whether the input signal
% is or not an IMF
disp('Verifying whether the input signal is an IMF or not');
disp(' .......... ');
disp(' ');
[i_m_f,is_imf]= imf_est(x,0,interpMethod,1);
if is_imf>0,
i_m_fs = i_m_f;
return;
else
disp(' The input signal is not an IMF and its first IMF has been estimated. ');
imf_old = i_m_f;
i_m_fs = i_m_f; %updating outuput vector
k = k+1; %updating counter
end;
%Starting the sifting process
while (m_s_e>mse)&(k<=9),
k = k+1;%counter
fprintf(1,'\nEstimating IMF: %d\n',k);
r=r-imf_old;
[i_m_f,is_imf]= imf_est(r,-1,interpMethod,k);%estimating imf
if (isempty(i_m_f)),
disp('A trend was detected');%there is not maximum or minimum local
break;
% return;
end%if
%updating the i_m_fs array
i_m_fs = [i_m_fs; i_m_f];
%Estimating the mean squared error between two consecutives imfs
if (k>1),
m_s_e=0;
for i=1:t,
m_s_e=m_s_e + (imf_old(i)-i_m_f(i))^2;
end %for
end%if
m_s_e=m_s_e/t;
fprintf(1,'\nmse: %d\n',m_s_e);
%updating old imf
imf_old=i_m_f;
end%while
%Estimating the index of orthogonality
auxImfs = [i_m_fs;r];
numberOfIMFs = min(size(auxImfs));
T = max(size(auxImfs));
sqrX = x.^2;
Index = find(sqrX==0);
sqrX(Index)=1e-80;%very small value
IO=0;%index of orthogonality
for j=1:numberOfIMFs,
sumk=0;
for k=1:numberOfIMFs,
sumk = sumk + sum(auxImfs(j,:).*auxImfs(k,:));
sumk = sumk./sum(sqrX);
end%for
IO = IO + sumk;
end%for
fprintf(1,'\nOverall index of orthogonality: %f\n',IO);