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

一、获取代码方式

获取代码方式1: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

获取代码方式2: 通过紫极神光博客主页开通CSDN会员,凭支付凭证,私信博主,可获得此代码。

获取代码方式3: 完整代码已上传我的资源:【数字信号】基于matlab CEEMD数字信号分解【含Matlab源码 1383】

备注:开通CSDN会员,仅只能免费获得1份代码(有效期为开通日起,三天内有效); 订阅紫极神光博客付费专栏,可免费获得2份代码(有效期为订阅日起,三天内有效);

二、部分源代码

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
% adding noise
    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.

猜你喜欢

转载自juejin.im/post/7017681494952902670

相关文章