Python时频谱图

2024-09-26 17:41:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我在256Hz的频率下采集了64个通道的脑电数据,我试图对每个通道进行时频分析并绘制一个频谱图。

数据存储在numpy 3d阵列中,其中一个维度的长度为256,每个元素包含在所有采样时间点上读取的微伏(每个数据通道的总长度为1秒)。

需要说明的是:我的3D阵列是64*256*913(电极*电压*试用)。试验只是试验的单一试验。所以我想做的是,从一次试验中,取一个单一的电极,和整个一维电压矢量,并创建一个时频谱图。例如,我想从数据[0,:,0]创建一个光谱图。

对于每个元素,我想要一个图,其中y轴是频率,x轴是时间,颜色/强度是功率

我在python中试过使用这个:

from matplotlib.pyplot import specgram
#data = np.random.rand(256)
specgram(data, NFFT=256, Fs=256)

这给了我这样的东西:

enter image description here

在我看来这是不正确的,因为轴的范围是不正确的

此外,当我对所有的EEG通道运行相同的代码时,在所有的数据上,我得到的是完全相同的图(即使我已经验证了每个通道的数据是不同的)

我对信号处理还不太熟悉,我的数据是如何布局的,还是如何使用我的函数,有什么地方出了问题吗?


Tags: 数据numpy元素data时间绘制电极频谱
1条回答
网友
1楼 · 发布于 2024-09-26 17:41:20

specgram函数的documentation

Plot a spectrogram.

Call signature:

specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, window=mlab.window_hanning, noverlap=128, cmap=None, xextent=None, pad_to=None, sides='default', scale_by_freq=None, mode='default', scale='default', **kwargs)

Compute and plot a spectrogram of data in x. Data are split into NFFT length segments and the spectrum of each section is computed. The windowing function window is applied to each segment, and the amount of overlap of each segment is specified with noverlap. The spectrogram is plotted as a colormap (using imshow).

x: 1-D array or sequence Array or sequence containing the data

看起来你的问题是你没有传递一维数据。尝试:

from matplotlib.pyplot import specgram
specgram(data.flatten(), NFFT=256, Fs=256)

相关问题 更多 >

    热门问题