# 【数字信号】基于matlab CEEMD数字信号分解【含Matlab源码 1383】

·  阅读 702

## 二、部分源代码

``````clc;clear;close all
t=1/1000:1/1000:1;
x=sin(20*pi*t)+sin(40*pi*t)+2*sin(60*pi*t);
imf=ceemd(x,0.02,50,2);
%----------------IMF显示----------------
figure(1);
imfn=imf';
n=size(imfn,1);
subplot(n,1,1);
plot(t,x);%原始信号
ylabel('原始信号','fontsize',12,'fontname','华文中宋');
for n1=1:n-1
subplot(n,1,n1+1);
plot(t,imfn(n1,:));%IMF分量
ylabel(['IMF' int2str(n1)]);
end

figure(2);
imfn=imf';
n=size(imfn,1);
subplot(n,1,1);
[f,z]=COMPUTE_FFT(t,x);
plot(f(1:50),z(1:50));%原始信号
ylabel('原始信号','fontsize',12,'fontname','华文中宋');
for n1=1:n-1
subplot(n,1,n1+1);
[f,z]=COMPUTE_FFT(t,imfn(n1,:));

plot(f(1:50),z(1:50));%IMF分量
ylabel(['IMF' int2str(n1)]);
end

ylabel('RES');

xlabel('时间\itt/s','fontsize',12,'fontname','华文中宋');
% Y: Inputted data;
% Nstd: ratio of the standard deviation of the added noise and that of Y;
% NE: Ensemble member being used
% TNM: total number of modes (not including the trend)
%
function allmode=ceemd(Y,Nstd,NE,TNM)
% find data length
xsize=length(Y);
dd=1:1:xsize;
% Nornaliz data
Ystd=std(Y);
Y=Y/Ystd;
% Initialize saved data
TNM2=TNM+2;
for kk=1:1:TNM2,
for ii=1:1:xsize,
allmode(ii,kk)=0.0;
end
end

for iii=1:1:NE
for i=1:xsize,
temp=randn(1,1)*Nstd;
X1(i)=Y(i)+temp;
X2(i)=Y(i)-temp;
end

% sifting X1
xorigin = X1;
xend = xorigin;
% save the initial data into the first column
for jj=1:1:xsize
mode(jj,1) = xorigin(jj);
end
nmode = 1;
while nmode <= TNM,
xstart = xend;
iter = 1;
while iter<=5,
[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;
% save a mode
for jj=1:1:xsize,
mode(jj,nmode) = xstart(jj);
end
end
% save the trend
for jj=1:1:xsize,
mode(jj,nmode+1)=xend(jj);
end
% add mode to the sum of modes from earlier ensemble members
%     1,size(allmode),2,size(mode)
allmode=allmode+mode;

%%%=============================================================
% sifting X2
xorigin = X2;
xend = xorigin;
% save the initial data into the first column
for jj=1:1:xsize,
mode(jj,1) = xorigin(jj);
end
nmode = 1;
while nmode <= TNM,
xstart = xend;
iter = 1;
while iter<=5,
[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;
% save a mode
for jj=1:1:xsize,
mode(jj,nmode) = xstart(jj);
end
end
% save the trend
for jj=1:1:xsize,
mode(jj,nmode+1)=xend(jj);
end
% add mode to the sum of modes from earlier ensemble members

allmode=allmode+mode;
%fprintf('-');
end
% ensemble average
allmode=allmode/NE/2;
% Rescale mode to origional unit.
allmode=allmode*Ystd;

## 四、matlab版本及参考文献

1 matlab版本 2014a

2 参考文献 [1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社，2015. [2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社，2020. [3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社，2018.