【发布时间】:2014-11-30 05:38:42
【问题描述】:
我正在使用 matplotlib 的 specgram 函数来生成频谱图。我试图在频谱图的右侧添加一个颜色条,以指示 dB 到颜色的映射。
但由于某种原因,颜色条指示的 dB 没有意义。
也许我没有正确生成颜色条?也许我需要将一些参数传递给 specgram?
我生成的信号是以 32Khz 采样的 1Khz、2Vpp 正弦波。
我预计频谱图上的暗红色峰值对应于 0dB(意味着 +1V 是我的参考)
有人知道我的方法有什么问题吗?
def plot_specgram(data, title='', x_label='', y_label='', fig_size=None):
fig = plt.figure()
if fig_size != None:
fig.set_size_inches(fig_size[0], fig_size[1])
ax = fig.add_subplot(111)
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
pxx, freq, t, cax = plt.specgram(data, Fs=32000)
fig.colorbar(cax).set_label('Intensity [dB]')
plot_specgram(a,title='Spectrogram', x_label='time (in seconds)', y_label='frequency', fig_size=(14,8))
这是我得到的频谱图:
【问题讨论】:
-
从色图上看,深红色确实似乎对应0,只是没有显示0……0db(深红色)对应峰值1kHz 的光谱分量...正如预期的那样,蓝色具有较低的强度值(
-
实际上,您所看到的可能是您没有考虑到的窗口函数的结果。我很确定
specgram使用 Hanning 窗口作为默认值,这可能会影响您对缩放的期望。
标签: python matplotlib spectrogram