发布时间:2023-01-02 20:30
LMD经验模态分解matlab程序
LMD经验模态分解matlab程序——原味的
曾经也用滑动平均写过LMD,其实滑动平均的EMD才是原汁原味的居于均值分解。
分享给有需要的人,程序写的不好,只是希望提供一种思路。如果谁写了更完美LMD程序,别忘了发我一份,快毕业了,一直没有把LMD写完美,对于我来说始终是个遗憾。来分完美的LMD让我也品尝下,我也无憾了~
代码下载地址:/source/3102096
此处没有提供测试代码,如需要可以点这里:点我
源代码如下:
%原始lmd算法,效果很不好,不知道程序哪里写错function[PF,A,SI]=lmd(m)c=m;k=0wucha1=0.001;n_l=nengliang(m);while 1????k=k+1;????a=1;????h=c;????[pf,a,si]=zhaochun(a,h,wucha1);????c=c-pf;????PF(k,:)=pf;????A(k,:)=a;????SI(k,:)=si;????c_pos=pos(c);????n_c=nengliang(c);????n_pf=nengliang(pf);????if length(c_pos)<3 || n_c
function pos=pos(y)%功能:找序列极值点位置坐标
%y:输入序列%pos:极值点的序列位置坐标m = length(y);d = diff(y);
n = length(d);d1 = d(1:n-1);d2 = d(2:n);indmin = find(d1.*d2<0 & d1<0)+1;indmax = find(d1.*d2<0 & d1>0)+1;
if any(d==0)???imax = [];??imin = [];???bad = (d==0);??dd = diff([0 bad 0]);??debs = find(dd == 1);??fins = find(dd == -1);??if debs(1) == 1????if length(debs) > 1??????debs = debs(2:end);??????fins = fins(2:end);????else??????debs = [];??????fins = [];????end??end??if length(debs) > 0????if fins(end) == m??????if length(debs) > 1????????debs = debs(1:(end-1));????????fins = fins(1:(end-1));
??????else????????debs = [];????????fins = [];??????end?????????end??end??lc = length(debs);??if lc > 0????for k = 1:lc??????if d(debs(k)-1) > 0????????if d(fins(k)) < 0??????????imax = [imax round((fins(k)+debs(k))/2)];????????end??????else????????if d(fins(k)) > 0??????????imin = [imin round((fins(k)+debs(k))/2)];????????end??????end????end??end???if length(imax) > 0????indmax = sort([indmax imax]);??end
??if length(imin) > 0????indmin = sort([indmin imin]);??end?end?
minmax=cat(2,indmin,indmax);pos=sort(minmax);end%----------zhaochun.mfunction [pf,a,si]=zhaochun(a,h,wucha1)chun_num=0;while 1chun_num=chun_num+1t=1:length(h);h_pos=position(h);%极值点位置序列tpoint=t(h_pos);%极值点时间值hpoint=h(h_pos);%极值点幅度值hpoint