python - python中连续小波变换图(比例图)中的频率轴

标签 python signal-processing wavelet pywt

我有一个 EEG 信号,我有兴趣在时域和频域中对其进行分析。我已经使用过 scipy.signal.spectrogram 函数,但我认为使用小波可以产生更好的特征提取结果。 我尝试对我创建的人工信号运行连续小波变换,如下所示:

fs = 128.0
sampling_period = 1/fs
t = np.linspace(0, 2, 2*fs)
x = chirp(t,10,2,40,'quadratic')

coef, freqs = pywt.cwt(x, np.arange(1,50),'morl', 
sampling_period=sampling_period)

然后我绘制了系数矩阵:

plt.matshow(coef)
plt.show()

the resuls for the code above

我的问题是如何调整比例和时间轴?

最佳答案

函数 plt.matshow(coef) 不使用时间和频率数组来创建轴(但它创建基于样本索引的轴)。

我建议使用 plt.pcolormesh(t, freqs, coef),因此时间和频率用于轴。然后你可以玩比例尺——比如,将频率轴放在对数比例尺中——并产生类似的东西:

enter image description here

这是生成图像的代码,源自您的示例:

import pywt
import numpy as np
import matplotlib.pyplot as plt

from scipy.signal import chirp

# Define signal
fs = 128.0
sampling_period = 1 / fs
t = np.linspace(0, 2, 2 * fs)
x = chirp(t, 10, 2, 40, 'quadratic')

# Calculate continuous wavelet transform
coef, freqs = pywt.cwt(x, np.arange(1, 50), 'morl',
                       sampling_period=sampling_period)

# Show w.r.t. time and frequency
plt.figure(figsize=(5, 2))
plt.pcolor(t, freqs, coef)

# Set yscale, ylim and labels
plt.yscale('log')
plt.ylim([1, 100])
plt.ylabel('Frequency (Hz)')
plt.xlabel('Time (sec)')
plt.savefig('egg.png', dpi=150)

关于python - python中连续小波变换图(比例图)中的频率轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43587314/

相关文章:

algorithm - DCF77 解码器与噪声信号

python - 如何使用Tensorflow进行信号处理?

machine-learning - 小波神经网络 : why no Inverse Transform?

java - Gabor 过滤器的不同 'theta' 返回没有方向的图像

python - 在包含列表的列表上搜索并删除我们搜索的特定列表

python - 计算用户输入的偶数 PYTHON 3

python - web.py session : AttributeError: 'ThreadedDict' object has no attribute 'count'

python - 带有 pandas 数据框的矢量化半正矢公式

matlab - Matlab 中的局部最大值

java - 我应该使用什么图像值来生成 haar 小波?