Matlab实现HHT程序(源码-非常珍贵)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

clearall;x=load('06514135360001170106.TXT');fs=1000000;N=length(x);t=0:1/fs:(N-1)/fs;z=x;c=emd(z);%计算每个IMF分量及最后一个剩余分量residual与原始信号的相关性[m,n]=size(c);fori=1:m;a=corrcoef(c(i,:),z);xg(i)=a(1,2);endxg;fori=1:m-1%--------------------------------------------------------------------%计算各IMF的方差贡献率%定义:方差为平方的均值减去均值的平方%均值的平方%imfp2=mean(c(i,:),2).^2%平方的均值%imf2p=mean(c(i,:).^2,2)%各个IMF的方差mse(i)=mean(c(i,:).^2,2)-mean(c(i,:),2).^2;end;mmse=sum(mse);fori=1:m-1mse(i)=mean(c(i,:).^2,2)-mean(c(i,:),2).^2;%方差百分比,也就是方差贡献率mseb(i)=mse(i)/mmse*100;%显示各个IMF的方差和贡献率end;%画出每个IMF分量及最后一个剩余分量residual的图形figure(1)fori=1:m-1disp(['imf',int2str(i)]);disp([mse(i)mseb(i)]);end;subplot(m+1,1,1)plot(t,z)set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['signal','Amplitude'])fori=1:m-1subplot(m+1,1,i+1);set(gcf,'color','w')plot(t,c(i,:),'k')set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['imf',int2str(i)])endsubplot(m+1,1,m+1);set(gcf,'color','w')plot(t,c(m,:),'k')set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['r',int2str(m-1)])%画出每个IMF分量及剩余分量residual的幅频曲线figure(2)subplot(m+1,1,1)set(gcf,'color','w')[f,z]=fft(t,z);plot(f,z,'k')set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['initialsignal',int2str(m-1),'Amplitude'])fori=1:m-1subplot(m+1,1,i+1);set(gcf,'color','w')[f,z]=fft(t,c(i,:));plot(f,z,'k')set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['imf',int2str(i),'Amplitude'])endsubplot(m+1,1,m+1);set(gcf,'color','w')[f,z]=fft(t,c(m,:));plot(f,z,'k')set(gca,'fontname','timesNewRoman')set(gca,'fontsize',14.0)ylabel(['r',int2str(m-1),'Amplitude'])hx=hilbert(z);xr=real(hx);xi=imag(hx);%计算瞬时振幅sz=sqrt(xr.^2+xi.^2);%计算瞬时相位sx=angle(hx);%计算瞬时频率dt=diff(t);dx=diff(sx);sp=dx./dt;figure(6)plot(t(1:N-1),sp)title('瞬时频率')%计算HHT时频谱和边际谱[A,fa,tt]=hhspectrum(c);[E,tt1]=toimage(A,fa,tt,length(tt));figure(3)disp_hhs(E,tt1)%二维图显示HHT时频谱,E是求得的HHT谱pausefigure(4)fori=1:size(c,1)faa=fa(i,:);[FA,TT1]=meshgrid(faa,tt1);%三维图显示HHT时频图surf(FA,TT1,E)title('HHT时频谱三维显示')holdonendholdoffE=flipud(E);fork=1:size(E,1)bjp(k)=sum(E(k,:))*1/fs;endf=(1:N-2)/N*(fs/2);figure(5)plot(f,bjp);xlabel('频率/Hz');ylabel('信号幅值');title('信号边际谱')%要求边际谱必须先对信号进行EMD分解function[A,f,tt]=hhspectrum(x,t,l,aff)error(nargchk(1,4,nargin));ifnargin2t=1:size(x,2);endifnargin3l=1;endifnargin4aff=0;endifmin(size(x))==1ifsize(x,2)==1x=x';ifnargin2t=1:size(x,2);endendNmodes=1;elseNmodes=size(x,1);endlt=length(t);tt=t((l+1):(lt-l));fori=1:Nmodesan(i,:)=hilbert(x(i,:)')';f(i,:)=instfreq(an(i,:)',tt,l)';A=abs(an(:,l+1:end-l));ifaffdisprog(i,Nmodes,max(Nmodes,100))endendfunctiondisp_hhs(im,t,inf)%DISP_HHS(im,t,inf)%displaysinanewfigurethespectrumcontainedinmatrixim%(amplitudesinlog).%%inputs:-im:imagematrix(e.g.,outputoftoimage)%-t(optional):timeinstants(e.g.,outputoftoimage)%-inf(optional):-dynamicrangeindB(wrtmax)%default:inf=-20%%utilisation:disp_hhs(im);disp_hhs(im,t);disp_hhs(im,inf)%disp_hhs(im,t,inf)figurecolormap(bone)colormap(1-colormap);ifnargin==1inf=-20;t=1:size(im,2);endifnargin==2iflength(t)==1inf=t;t=1:size(im,2);elseinf=-20;endendifinf=0error('infdoitetre0')endM=max(max(im));im=log10(im/M+1e-300);inf=inf/10;imagesc(t,fliplr((1:size(im,1))/(2*size(im,1))),im,[inf,0]);set(gca,'YDir','normal')xlabel(['time'])ylabel(['normalizedfrequency'])title('Hilbert-Huangspectrum')function[f,z]=fftfenxi(t,y)L=length(t);N=2^nextpow2(L);%fft默认计算的信号是从0开始的t=linspace(t(1),t(L),N);deta=t(2)-t(1);m=0:N-1;f=1./(N*deta)*m;%下面计算的Y就是x(t)的傅里叶变换数值%Y=exp(i*4*pi*f).*fft(y)%将计算出来的频谱乘以exp(i*4*pi*f)得到频移后[-2,2]之间的频谱值Y=fft(y);z=sqrt(Y.*conj(Y));

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功