-
Notifications
You must be signed in to change notification settings - Fork 1
/
iceemdan.m
75 lines (67 loc) · 2.25 KB
/
iceemdan.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
function [modes,its]=iceemdan(x,Nstd,NR,MaxIter,SNRFlag)
%modes=iceemdan(x,Nstd,NR,MaxIter,SNRFlag)
%[modes its]=iceemdan(x,Nstd,NR,MaxIter,SNRFlag)
x=x(:)';
desvio_x=std(x);
x=x/desvio_x;
aux=zeros(size(x));
iter=zeros(NR,round(log2(length(x))+5));
white_noise = cell(1,NR);
for i=1:NR
white_noise{i}=randn(size(x));%creates the noise realizations
end
modes_white_noise = cell(1,NR);
for i=1:NR
modes_white_noise{i}=emd(white_noise{i});%calculates the modes of white gaussian noise
end
for i=1:NR %calculates the first mode
xi=x+Nstd*modes_white_noise{i}(1,:)/std(modes_white_noise{i}(1,:));
[temp, ~, it]=emd(xi,'MAXMODES',1,'MAXITERATIONS',MaxIter);
temp=temp(1,:);
aux=aux+(xi-temp)/NR;
iter(i,1)=it;
end
modes= x-aux; %saves the first mode
medias = aux;
k=1;
aux=zeros(size(x));
es_imf = min(size(emd(medias(end,:),'MAXMODES',1,'MAXITERATIONS',MaxIter)));
while es_imf>1 %calculates the rest of the modes
for i=1:NR
tamanio=size(modes_white_noise{i});
if tamanio(1)>=k+1
noise=modes_white_noise{i}(k+1,:);
if SNRFlag == 2
noise=noise/std(noise); %adjust the std of the noise
end
noise=Nstd*noise;
try
[temp,~,it]=emd(medias(end,:)+std(medias(end,:))*noise,'MAXMODES',1,'MAXITERATIONS',MaxIter);
catch
it=0;
%disp('catch 1 '); disp(num2str(k))
temp=emd(medias(end,:)+std(medias(end,:))*noise,'MAXMODES',1,'MAXITERATIONS',MaxIter);
end
temp=temp(end,:);
else
try
[temp, ~, it]=emd(medias(end,:),'MAXMODES',1,'MAXITERATIONS',MaxIter);
catch
temp=emd(medias(end,:),'MAXMODES',1,'MAXITERATIONS',MaxIter);
it=0;
%disp('catch 2 sin ruido')
end
temp=temp(end,:);
end
aux=aux+temp/NR;
iter(i,k+1)=it;
end
modes=[modes;medias(end,:)-aux];
medias = [medias;aux];
aux=zeros(size(x));
k=k+1;
es_imf = min(size(emd(medias(end,:),'MAXMODES',1,'MAXITERATIONS',MaxIter)));
end
modes = [modes;medias(end,:)];
modes=modes*desvio_x;
its=iter;