【问题标题】:python - spectrogram divide by zero encountered in log10 warningpython - 在log10警告中遇到频谱图除以零
【发布时间】:2018-05-23 11:37:23
【问题描述】:

我试图为我的数据集中的每个轴生成一个频谱图 这是我尝试过的

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()

但它给出了以下警告

Warning (from warnings module):
  File "C:\Users\hadeer.elziaat\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 7221
    Z = 10. * np.log10(spec)
RuntimeWarning: divide by zero encountered in log10

数据集标题 (患者编号、时间/毫秒、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

【问题讨论】:

    标签: python-3.x signal-processing spectrogram


    【解决方案1】:

    根据手册,默认缩放为 dB。如果计算的频谱图中的值为零,则对数刻度的评估将导致错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-29
      • 1970-01-01
      相关资源
      最近更新 更多