我是python中的新手,我想在文本文件中提取幅度的光谱图
这是我的代码
dataset = np.loadtxt("trainingdataset.txt", delimiter=",", dtype = np.int32)
fake_size = 1415684
time = np.arange(fake_size)/1415684 # 1kHz
base_freq = 2 * np.pi * 100
x = dataset[:,2]
y = dataset[:,3]
z = dataset[:,4]
xyz_magnitude = x**2 + y**2 + z**2
to_plot = [('x', x), ('y', y), ('z', z), ('xyz', xyz_magnitude)]
for chl, data in to_plot:
plt.figure(); plt.title(chl)
d = plt.specgram(data, Fs=1000)
plt.xlabel('Time [s]'); plt.ylabel('Frequency [Hz]')
plt.show()
并且有一个我的数据集样本,数据集标题如下(患者编号,时间/毫秒,X轴,Y轴,Z轴,标签
1,15,70,39,-970,0
1,31,70,39,-970,0
1,46,60,49,-960,0
1,62,60,49,-960,0
1,78,50,39,-960,0
1,93,50,39,-960,0
1,109,60,39,-990,0
从评论中编辑:
警告代码警告(来自警告模块):文件“C:\ Users ****** \ AppData \ Local \ Programs \ Python \ Pytho n36 \ lib \ site-package s \ matplotlib \ axes_ax es.py“,第7221行Z = 10. * np.log10(规范)运行时警告:在log10中遇到零除 -