【问题标题】:Increase the resolution of my Python Spectrogram增加我的 Python 频谱图的分辨率
【发布时间】:2021-01-22 09:28:12
【问题描述】:

如何更改频谱图的分辨率?我正在使用matplotlib.pyplot.specgramfunction

我想我必须放大窗口,但我不知道该怎么做。在这里问可能很容易,但我希望得到答案。

这是我的代码:

import numpy as np
import matplotlib.pyplot as plot

#Import data
a1.resize(np.size(a1))
signaldata = a1
samplingFrequency=2000
    
plot.subplot
plot.specgram(signalData,Fs=samplingFrequency)
plot.xlabel('Time in seconds')
plot.ylabel('Frequency')
plot.ylim(0,100)
plot.show()

这是我的信号数据:a1

这是我的光谱图:

在 4-14 秒和 0-40 (Hz) 区域内只有两个条形,没有比分辨率更高的只有两种颜色。我希望更具体地看看那里发生了什么。有没有可能提高分辨率?

提前谢谢你。

【问题讨论】:

  • 结果的分辨率受输入信号之一的限制。您可以缩放(使用 matplotlib 的交互式图形)或使用 plot.xlim(4, 14),仅此而已。
  • 您可以使用更长的窗口长度 - 更长的窗口将为您提供更少的时间分辨率,但更高的频率分辨率。
  • 抱歉,您通过更改 NFFT 来延长窗口。

标签: python matplotlib resolution spectrogram


【解决方案1】:

分辨率本质上受到傅里叶变换的限制,您对此无能为力。尽管如此,我相信您拥有的信号在 4 秒后几乎没有频率信息。您可以尝试使用Lomb-Scargle periodogram 等工具进行一些调查。

几年前我写了一个你可能会觉得有用的辅助函数(你可以通过 pip 安装: pip install fitwrap 或从github 下载)。

这是一个可以使用的sn-p,你只需要设置span(窗口维度),你需要的最小和最大频率min_freqmax_freq,时间箱n_bins,和频率垃圾箱grid_size

import fitwrap as fw
import matplotlib.pyplot as plt

span = 0.4
n_bins = 100
grid_size = 100
min_freq = 0.01
max_freq = 40

t_tot = 1/samplingFrequency*signaldata.shape[0]
t = np.linspace(0, t_tot, signaldata.shape[0])
tmin = np.min(t)
tmax = np.max(t)
x_bins = np.linspace(tmin+span, tmax-span, n_bins)

spectrogram = np.zeros([grid_size, x_bins.shape[0]])
for index, x_bin in enumerate(x_bins):
    mask = np.logical_and((x_bin-span)<=t, (x_bin+span)>=t) 
    frequency_grid, lombscargle_spectrum = fw.lomb_spectrum(t[mask], signaldata[mask],
                    frequency_span=[min_freq, max_freq], grid_size=grid_size)
    spectrogram[:, index] = lombscargle_spectrum

plt.imshow(spectrogram, aspect='auto', extent=[x_bins[0],x_bins[-1],
            frequency_grid[0],frequency_grid[-1]], origin='lower') 
plot.xlabel('Time in seconds')
plot.ylabel('Frequency')

【讨论】:

    【解决方案2】:

    您也可以使用arlpy python 包,它具有使用散景图的内置交互功能。你可以做pip install arlpy 或在github 上找到。可以用方框放大,也可以用滚轮放大。

    import arlpy.plot
    import numpy as np
    arlpy.plot.specgram(np.random.normal(size=(10000)), fs=10000, clim=30)
    

    【讨论】:

      猜你喜欢
      • 2022-08-22
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 2015-09-23
      • 2018-01-18
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      相关资源
      最近更新 更多