基于MATLAB的振动数据时频分析及可视化

本文将解析一段MATLAB代码,该代码用于对振动数据进行时频分析,并通过图形展示分析结果。

代码功能:

  • 加载振动数据。* 使用短时傅里叶变换(STFT)和时频同步压缩变换(TMSST)等方法进行时频分析。* 绘制时频表示图、频谱峰值和模式与原始信号的对比图。

**代码解析:**matlab% 清除工作区和图形窗口clear;% 加载数据文件load('vib_data1.mat')% 设置采样率和数据点数fs = 12000; N = 2400; % 创建时间序列time = (1:N)/fs; % 创建频率序列fre = (fs/2)/(N/2):(fs/2)/(N/2):(fs/2); % 创建反向频率序列fre2=fliplr(fre);% 截取数据data=data(1:N);% 使用STFT_Y函数进行短时傅里叶变换[tfr]=STFT_Y(data,150);

% 绘制Figure 1figure;subplot(211)% 绘制时间-幅值图像plot(time,data);xlabel('Time (s)');ylabel('Amp (g)');subplot(212)% 绘制时频表示图imagesc(time,fre/1000,abs(tfr));xlabel('Time (s)');ylabel('Fre (kHz)');axis xyaxis([time(1) time(end) 2.4 4]);

% ... 定义放大区域 ...

% 使用TMSST_Y函数进行时频同步压缩变换[Ts1]=TMSST_Y(data,170,1);

% 绘制Figure 2figure;subplot(2,2,[1 2])% 绘制时频表示图imagesc(time,fre/1000,abs(Ts1));xlabel('Time (s)');ylabel('Fre (kHz)');axis xyaxis([time(1) time(end) 2.4 4]);% 绘制放大区域rectangle('Position',[x1 y1 x2-x1 y2-y1],'EdgeColor','red','Linewidth',1);rectangle('Position',[x11 y11 x22-x11 y22-y11],'EdgeColor','red','Linewidth',1);ha=subplot(2,2,3);imagesc(time,fre/1000,abs(Ts1));xlabel('Time (s)');ylabel('Fre (kHz)');axis xyset(ha,'xlim',[x1 x2],'ylim',[y1 y2]);

ha=subplot(2,2,4);imagesc(time,fre/1000,abs(Ts1));xlabel('Time (s)');ylabel('Fre (kHz)');axis xyset(ha,'xlim',[x11 x22],'ylim',[y11 y22]);

% ... 使用不同参数进行TMSST变换并绘制Figure 3 ...

% 计算谱峰频率[Ts10]=TMSST_Y(data,170,10);for i=1:round(N/2)K11(i)=max(abs(fft(detrend(abs(Ts10(i,:))))));end[~,index]=max(K11);

% ... 定义放大区域 ...

% 绘制Figure 4figure;subplot(3,2,[1 2]);% 绘制频率-幅值图像plot(fre,K11);xlabel('Fre (Hz)');ylabel('Amp (g)');axis([0 6000 0 30]);subplot(3,2,[3 4]);% 绘制时间-幅值图像plot(time,abs(Ts10(index,:)));xlabel('Time (s)');ylabel('Amp (g)');% 绘制放大区域rectangle('Position',[x1 y1 x2-x1 y2-y1],'EdgeColor','red','Linewidth',1);rectangle('Position',[x11 y11 x22-x11 y22-y11],'EdgeColor','red','Linewidth',1);

ha=subplot(3,2,5);plot(time,abs(Ts10(index,:)));xlabel('Time (s)');ylabel('Amp (g)');set(ha,'xlim',[x1 x2],'ylim',[y1 y2]);ha=subplot(3,2,6);plot(time,abs(Ts10(index,:)));xlabel('Time (s)');ylabel('Amp (g)');set(ha,'xlim',[x11 x22],'ylim',[y11 y22]);

% 使用TMSST_Z和TCD_Z函数进行时频分析[Ts10]=TMSST_Z(data,170,10);[mode, TFM] = TCD_Z(Ts10,1.18);

Ts10=Ts10(1:round(N/2),:);TFM=squeeze(TFM(1,1:round(N/2),:));

% 绘制Figure 5figure;subplot(2,1,1)% 绘制时频表示图imagesc(time,fre/1000,abs(TFM));ylabel('Fre (kHz)');axis xyaxis([time(1) time(end) 2.4 4]);colorbar;subplot(2,1,2)% 绘制原始信号和重构信号plot(time,data,'b-','Linewidth',1);hold on;plot(time,mode,'r-','Linewidth',1);xlabel('Time (s)');ylabel('Amp (g)');axis([time(1) time(end) -3 3]);legend('Original signal','Reconstructed signal');

总结:

这段代码展示了如何使用MATLAB对振动数据进行时频分析,并通过多种图形直观地展示分析结果。代码中使用了多种时频分析方法,并通过对结果进行可视化,帮助我们更好地理解数据中蕴含的振动信息。

基于MATLAB的振动数据时频分析及可视化

原文地址: https://www.cveoy.top/t/topic/PKj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录