function allmode=emd(Y)
%用于经验模态分解,Y为要分解的数据,allmode为分解出来的模态IMF
xsize=length(Y);
dd=1:1:xsize;
Ystd=std(Y);
Y=Y/Ystd;
TNM=7;% 分7段
TNM2=TNM+2;
for kk=1:1:TNM2,
for ii=1:1:xsize,
allmode(ii,kk)=0.0;
end
end
%part3 EMD分层
for iii=1:1:NE,
for i=1:xsize,
temp=0;
X1(i)=Y(i)+temp;
end
for jj=1:1:xsize,
mode(jj,1) = Y(jj);
end
xorigin = X1;
xend = xorigin;
%IMF循环
nmode = 1;
while nmode <= TNM,
xstart = xend;
iter = 1;
while iter<=10-3,
[spmax, spmin, flag]=extrema(xstart);
upper= spline(spmax(:,1),spmax(:,2),dd); %极大值
lower= spline(spmin(:,1),spmin(:,2),dd); %极小值
mean_ul = (upper + lower)/2;%中间值
xstart = xstart - mean_ul;%提取剩余项
iter = iter +1;
end
xend = xend - xstart;
nmode=nmode+1;
for jj=1:1:xsize,
mode(jj,nmode) = xstart(jj);
end
end
for jj=1:1:xsize,
mode(jj,nmode+1)=xend(jj);
end
allmode=allmode+mode;
end
allmode=allmode*Ystd;