-
Notifications
You must be signed in to change notification settings - Fork 15
/
eemd3.m
106 lines (80 loc) · 2.33 KB
/
eemd3.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
function [modes, O, P, Q] = eemd3(img, goal, ens, nos_wn)
% this code is the interface function of the 3D EEMD.
% mex and parfor supported.
% written by Neil Po-Nan Li @ Inst. of Physics, Academia Sinica, Taiwan
% v1. 2014/03/17
%%
sz = size(img);
n1 = sz(1);
n2 = sz(2);
n3 = sz(3);
std_img = std( img(:) );
img = img ./ std_img; % normalize data
%% 3-D EEMD dim#1
data = img;
O = zeros(n1, n2, n3, goal+1);
disp('========== dimension #1 ==========');
tic;
% time_pre = 0;
% count = 0;
parfor w = 1:n3
disp(['Solving layer ' num2str(w) '/' num2str(n3) ]);
for u = 1:n1
% solve and store
row_modes = eemd( data(u,:,w), goal, ens, nos_wn);
row_modes( isnan(row_modes) ) = 0;
O(u,:,w,:) = permute(row_modes, [4 2 3 1]);
end
end
toc
%% 3-D EEMD dim#2
P = zeros(n1, n2, n3, goal+1, goal+1);
disp('========== dimenstion #2 ==========');
tic;% time_pre = toc;
for m = 1:(goal+1)
disp(['Solving mode ' num2str(m) '/' num2str(goal+1) ]);
parfor w = 1:n3
for v = 1:n2
% solve and store
col_modes = eemd( O(:,v,w,m).', goal, ens, nos_wn);
col_modes( isnan(col_modes) ) = 0;
P(:,v,w,m,:) = permute(col_modes, [2 5 4 3 1]);
end
end
end
toc
clear O;
%% 3-D EEMD dim#3
Q = zeros(n1, n2, n3, goal+1, goal+1, goal+1);
disp('========== dimenstion #3 ==========');
tic;% time_pre = toc;
for m1 = 1:(goal+1)
Qtmp = zeros(n1, n2, n3, goal+1, goal+1);
Ptmp = P(:,:,:,:,m1);
for m2 = 1:(goal+1)
disp(['Solving mode ' num2str(m2) '/' num2str(goal+1)...
' in mode ' num2str(m1) '/' num2str(goal+1)]);
parfor v = 1:n2
for u = 1:n1
% solve and store
stk = permute( Ptmp(u,v,:,m2), [1 3 2 4]);
stk_modes = eemd(stk, goal, ens, nos_wn);
stk_modes( isnan(stk_modes) ) = 0;
Qtmp(u,v,:,m2,:) = permute(stk_modes, [5 4 2 3 1]);
end
end
end
Q(:,:,:,:,m1,:) = permute( Qtmp, [1 2 3 4 6 5]);
end
toc
clear P;
%% Combine modes
R = zeros(n1, n2, n3, goal+1);
for m = (goal+1):-1:1
R(:,:,:,m) = sum( sum( sum( Q(:,:,:,m:end,m:end,m:end), 4), 5), 6);
if m < (goal+1)
R(:,:,:,m) = R(:,:,:,m) - sum( R(:,:,:,(m+1):end), 4);
end
end
clear Q;
modes = R .* std_img; % unnormalize data