import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat
# 读取.mat数据文件
data = loadmat('D:/cwru1/12k Drive End Bearing Fault Data/105.mat')
# 提取数据中的轴承故障类型和轴承的振动信号
fault_type = data['X105_FE_time'][0]
vibration_signals = data['X105_FE_time']
# 设置采样频率
fs = 12000
# 绘制时频图
plt.specgram(vibration_signals.flatten(), Fs=fs, NFFT=fs//2, noverlap=fs//4)
plt.colorbar()
plt.xlabel('Time (s)')
plt.ylabel('Frequency (Hz)')
plt.show()