Matlab Scripts for Hilbert Transform
Short Description
Descripción: Transformada de Hilbert - Matlab...
Description
Hilbert Vibration Decomposition Matlab script % function [Y,A,om_r,dev]=hvd(x,n,fp); % % x - initial signal, n - number of decomposed components % Y - decomposed components, A - component envelopes , % F_r - component relative angular frequency % F=Fs*om_r/2/pi - Absolute frequecy [Hz], Fs -sampling frequency, % dev=std(Y_i)/std(Y_1)) - relative standard deviation of the decomposed component % % Example: [Y,A,om_r,dev]=hvd(x,2,0.02); % % LIMITATIONS: % The sampling frequency Fs has to be in the range Fs=(20-80)*f0. % The minimum of points in time domain is 230*3+1 = 691 % % © 2011 Michael Feldman % For use with the book "HILBERT TRANSFORM APPLICATION % IN MECHANICAL VIBRATION", John Wiley & Sons, 2011 % if n>7; disp('Max number of components not greater than 7'); end if n7 s(2)=7; end F=F_r*Fs/2/pi;
%
';
'g- ';
'c- ';
'y- ' ];
Frequency, [Hz]
[F1,I]=sort(F'); F=F1'; %for j = 1:s(2), Y1(:,j) = Y(I(:,j),j); end ; Y=Y1'; %for j = 1:s(2), A1(:,j) = A(I(:,j),j); end ; A=A1'; for j = 1:s(1), Y1(j,:) = Y(j,I(:,j)); end ;Y=Y1; for j = 1:s(1), A1(j,:) = A(j,I(:,j)); end ;A=A1; for k=1:s(2), figure(1); subplot(s(2),1,k,'align'); plot(t,Y(pp,k),c(k,:));grid on;drawnow; ylabel(['^Y' int2str(k)]); axis([min(t) max(t) min(Y(pp,k)) max(Y(pp,k))]); xlabel('Time, s'); figure(2); subplot(211); plot(t,F(pp,k),c(k,:),'Linewidth',2);drawnow;hold on; grid on; axis([min(t) max(t) 0 1.2*max(max(F(pp,:)))]); ylabel('Frequency, Hz'); subplot(212); plot(t,A(pp,k),c(k,:),'Linewidth',2);drawnow;hold on;
grid on; axis([min(t) max(t) 0 1.2*max(max(A(pp,:))) ]); ylabel('Amplitude') xlabel('Time, s'); figure(3); subplot(211) plot(t,Y(pp,k),c(k,:));drawnow;hold on; grid on; axis([min(t) max(t) min(min(Y(pp,:))) max(max(Y(pp,:)))]); ylabel('Y'); end figure(1); subplot(s(2),1,1,'align'); title('Components'); figure(2); subplot(211); title('Component instantaneous frequency'); subplot(212); title('Component envelope'); figure(3); subplot(211); title('Components'); subplot(212); plot(t,sum(Y(pp,:)')); drawnow; grid on; axis([min(t) max(t) min(sum(Y(pp,:)')) max(sum(Y(pp,:)'))]); xlabel('Time, s'); ylabel('Y'); title('Sum of components') figure(4); for k=1:s(2), stem3(t(1:dec:length(pp)),F(pp(1:dec:length(pp)),k),(A(pp(1:dec:length(pp )),k)),c(k),'.'); hold on;drawnow; end xlabel('Time, s');ylabel('Frequency, Hz');zlabel('Amplitude') axis([min(t) max(t) 0.7*min(min(F(pp,:))) 1.3*max(max(F(pp,:))) min(min(A(pp,:))) max(max(A(pp,:)))]); title('Hilbert spectrum') view(-50,70); %tilefigs([2 2],20) return % Example clear; close all Fs=1; % Sampling frequency [Hz] dt=1/Fs; % Time sample interval [s] n=1024; % signal length T=dt*(n-1); % Signal duration [s] t=(0:dt:T)'; % Time vector f01=0.02*ones(1,length(t)); % Signal amplitude A01=0.005+0.06.*linspace(0,1,length(t)); % Signal frequency [Hz] f02=0.05*ones(1,length(t)); % Signal amplitude A02=0.04-0.02.*linspace(0,1,length(t)); % Signal frequency [Hz] x1=A01.*cos(2*pi*cumtrapz(f01.*dt)); % Signal x2=A02.*cos(2*pi*cumtrapz(f02.*dt)); % Signal x=x1+x2; [Y,A,F_r,dev]=hvd(x,2,0.05); plfreq(Y,A,F_r,2*pi)
%
% function [Ac, Fc]=congr(Y,A,F_r) % % % % % % % % %
Congruent envelope and instantaneous frequency Y - decomposed components, A - component envelopes , F_r - component relative angular frequency Example:
[Ac, Fc]=congr(Y,A,F_r);
© 2011 Michael Feldman For use with the book "HILBERT TRANSFORM APPLICATION IN MECHANICAL VIBRATION", John Wiley & Sons, 2011
S=size(Y); k=S(2); if k==1, Ac=A(:,1); Fc=(F_r(:,1))./Ac; else for l=2:k phi(:,l)=coph(Y(:,1),Y(:,l)); Ac(:,l)=A(:,l).*cos(pi.*phi(:,l)/180); Fc(:,l)=A(:,l).*F_r(:,l).*cos(pi.*phi(:,l)/180); end Ac=A(:,1)+sum(Ac')'; Fc=(F_r(:,1)+sum(Fc')')./Ac; end
return % Example x1=cos(0.1*(1:1024)); x2=0.3*cos(0.3*(1:1024)); x=x1-x2; [Y,A,F_r,dev]=hvd(x,2,0.05); [Ac, Fc]=congr(Y,A,F_r); figure(1) plot([x' Ac Fc]); legend('Signal','Congruent envelope','Congruent frequency') %
Vibration system modeling
Nonlinear free vibration % close all; clear Fs=16; % Sampling frequency a1=1; % Linear angular frequency squared f0=1/2/pi=0.16 a3=10; % Cubic nonlinear stiffness a5=0.0; % Nonlinear stiffness b1=0.05; % Linear damping b2=0; % Nonlinear damping x0=1e0; % Initial velocity sim('s19', 2e2); % Simulate a Simulink model figure(1) plot(y); grid on xlabel('Points, s'); ylabel('Displacement'); title(['Free vibration, a1=' num2str(a1) ', b1=' num2str(b1)]); %
Nonlinear forced vibration close all; clear Fs=3000; % Sampling frequency, [Hz] t_stop=2.5; % stop simulation time f_start=20; % Initial frequency [Hz] f_stop=90; % Stop frequency {Hz} a1=(2*pi*30)^2; % Linear angular frequency squared f0=1/2/pi=0.16 [Hz] a3=2000; % Cubic nonlinear stiffness a5=0.0; % Nonlinear stiffness d=0.0; % Dead zone (Backlash) b1=2*2.5; % Linear damping b2=0; % Nonlinear damping sim('s20', t_stop); % Simulate a Simulink model figure(1) subplot(211) plot(x); axis tight subplot(212) plot(y,'k'); grid on axis tight xlabel('Points, s'); ylabel('Displacement'); title(['Free vibration, a1=' num2str(a1) ', b1=' num2str(b1)]); %
Asymmetric vibration % close all; clear Fs=1000; % Sampling frequency, [Hz] t_stop=10; a1=(2*pi*10.0)^2; %The positive stiffness, a2=(2*pi*20.0)^2; % The negative stiffness b=2; % Linear damping
f0=10 [Hz]
sim('s21', t_stop); % Simulate a Simulink model figure(1) plot(y,'k'); grid on axis tight xlabel('Points, s'); ylabel('Displacement'); title(['Asymmetric free vibration, a1=' num2str(a1) ', num2str(a2)]); %
a2='
Two DOF system vibration % clear; close all eta=1.0; k1=(0.1592*2*pi)^2; k2=(0.3*2*pi)^2; c1=0.008; c2=0.01; m1=1; m2=1; alpha=0.0; beta=3.0; Fs=5; % Sampling frequency, [Hz] t_stop=6e2; sim('s22', t_stop); % Simulate a Simulink model figure(1); subplot(211) plot(y1,'b'); axis tight ylabel('1st mode'); subplot(212) plot(y2,'k'); axis tight xlabel('Points'); ylabel('2nd mode'); title(['Free vibration, \eta=' num2str(eta) ', k1=' num2str(k1) ', k2=' num2str(k2) ', c1=' num2str(c1)]); %
Vibration system IDENTIFICATION
FREEVIB identification ff1=sqrt(abs(4.*pi^2.*f0.^2-2*h.^2+4.*pi.*f0.*h.*... sqrt( (max(A))^2./(A.^2 +eps) -1+... (h).^2./(4.*pi^2.*f0.^2+eps))))/2/pi ; ffi=4.*pi^2.*f0.^2-2*h.^2-4.*pi.*f0.*h.*... sqrt( (max(A))^2./(A.^2 +eps) -1+... (h).^2./(4.*pi^2.*f0.^2+eps)); ind_ffi=find(ffi>0); ff2=zeros(length(y),1); ff2(ind_ffi)=sqrt(ffi(ind_ffi))./2/pi; FRF=[ff1 ff2];
% Freqyency Response Function
subplot(111); plot(FRF(pp,:),A(pp),'r--','LineWidth',1);hold on plot(f0(pp),A(pp),'b','LineWidth',2); xlabel('Frequecy, Hz');ylabel('Amplitude'); title(['Back-Bone, FRF']); grid on; % Static force calculation figure(3);set(3,'Position',[509 42 482 284]); iel=find(y > 0.98*A & y < 1.02*A); yH = hilbfir(y); ifr=find(yH > 0.97*A & y < 1.03*A); iel(iel=pp(length(pp)))=[]; ifr(ifr=pp(length(pp)))=[]; fofr=2*h(ifr).*Ayd(ifr); % Friction Force foel=4*(pi*f0(iel)).^2.*A(iel); % Elastic force subplot(121); plot([-A(iel) A(iel)],[-foel foel],'k.'); hold on plot([-A(iel) A(iel)],[-foel foel],'g'); title('Elastic Static Force'); ylabel('Elastic Force'); xlabel('Displacement') grid on; hold off subplot(122); plot([-Ayd(ifr) Ayd(ifr)],[-fofr fofr],'k.'); hold on plot([-Ayd(ifr) Ayd(ifr)],[-fofr fofr],'m'); title('Friction Force'); xlabel('Velocity');ylabel('Friction Force') grid on; hold off; returrn
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% load duffrd [z,A,f0,h,Ayd]=freevib(y,Fs,'d'); plfree(z,A,f0,h,Ayd); %
%
Free Vibration identification (FREEVIB) % clear all; close all; load duffrd.mat %Fs=1000; % Sampling Frequency t=((1:length(y))/Fs)'; u=y; N=220; % Remez filter length sim('s23.mdl'); A = f = f0 = d = h1 = Ayd= y = h2 =
yout(:,1); yout(:,2); yout(:,3); yout(:,4); yout(:,5); yout(:,6); yout(:,7); yout(:,8);
% % % % % % %
The The The The The The The
% Lowpass filtering fp=0.02;
Envelope instantaneos frequency natural frequency decrement damping coefficient envelope initial signal
A f0 h Ayd
= = = =
lpf(A, fp); lpf(f0,fp); lpf(h1,fp); lpf(Ayd,fp);
% Result plotting pp=600:length(y); figure(1); subplot(2,2,[1:2]) plot([y A]) axis('tight') xlabel('points') title('Signal and Envelope') subplot(2,2,3) plot(f0(pp),A(pp),'.') axis([0 1.5*max(f0(pp)) 0.9*min(A()) 1.1*max(A(pp)) ]); title('Skeleton curve') xlabel('Frequency, Hz') ylabel('Amplitude') subplot(2,2,4) plot(h(pp),A(pp),'.k') axis([0 2*max(h(pp)) 0.9*min(A()) 1.1*max(A(pp)) ]); title('Damping curve') xlabel('Damping coefficient, 1/s') ylabel('Amplitude') %
http://ht.technion.ac.il/Simulink/s23.mdl
FORCEVIB identification % function [yy,A,f0,h,Ayd,f,m]=forcevib(x,y,Fs,stype); % Function FORCEVIB (Forced Vibration Analysis) % It determines instantaneous modal parameters of % linear and non-linear vibration SDOF system under forced % quasiharmonic excitation input. % Input: % Vector y is a forced vibration signal in time domain, % Vector x is an input force excitation, % stype is a signal type, e.g. displacement, velocity, or acceleration. % Fs is the sampling frequency [Hz] % % Output: % yy - displacement, A - envelope, f0 - natural frequency [Hz], % h - damping coefficient [1/sec],Ayd - envelope of the velocity, % f - instantaneous frequency [Hz], m - mass value % % m*y'' + 2*m*h*y' +m*(2*pi*f0)^2*y = x % % EXAMPLE: % [yy,A,f0,h,Ayd,f,m]=forcevib(x,y,1000,'d'); % % LIMITATIONS: % The sampling frequency Fs has to be in the range Fs=(10-100)*f0. % The minimum of points in time domain is 3*230+1. % % © 2011 Michael Feldman % For use with the book "HILBERT TRANSFORM APPLICATION % IN MECHANICAL VIBRATION", John Wiley & Sons, 2011 % N=230; if length(y)=100; disp('PLEASE WAIT') options = optimset('Display','off'); % Optimization for Natural Frequency m=-lsqnonlin(@omer,m,[],[],options); end
om01_2=alpha./m-beta.*Ad_A_om/m+om0_2; h=h0+0.5*A2.*beta./(var2+eps)./m; % Low pass filtration (Result fp=0.02; f = lpf(f,fp); % A = lpf(A,fp); % f0 = sqrt(abs( lpf(om01_2,fp) h = lpf(h,fp); %
Smoothing) Frequency [Hz] Amplitude, Displaycement ))/2/pi; % Natural frequency [Hz] Damping [1/s]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function F = omer(m); shift=20; om01_2i=[]; er=[]; for i=1:length(ppz)-shift; om01_2i=alpha(ppz(i:i+shift))./mbeta(ppz(i:i+shift)).*Ad_A_om(ppz(i:i+shift))/m-om0_2(ppz(i:i+shift)); er(i)=std(om01_2i); end F=er; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% returrn %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% load duffod [yy,A,f0,h,Ayd,f,m]=forcevib(x,y,Fs,'d'); plfor(yy,A,f0,h,Ayd,f,m); %
View more...
Comments