如何在python中使用平均频率进行心电特征提取?

2024-09-26 18:11:37 发布

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

你能帮我更正下面的代码吗

在这里,我试图通过计算平均频率来提取心电信号的特征

首先,我用以下代码阅读音频:

Fs, data = read('ecg_file.wav')

数据输出: enter image description here

然后,对数据进行FFT处理

Y = np.abs(rfft(data))

fft的输出: enter image description here

现在,我想应用这个公式,它是平均频率的公式。 enter image description here

根据我阅读的参考资料,M是频率单元的长度。要查找P,我使用以下代码:

power_spectrum = Y**2

我仍然对计算fj的值感到困惑。 你们能帮我纠正上面的代码吗


Tags: 数据代码imagereaddatahere特征description
1条回答
网友
1楼 · 发布于 2024-09-26 18:11:37

Numpy有一个很好的操作,可以从傅里叶变换中获取频率值,例如fftfreqrfftfreq

import numpy as np
# First get the frequency vector
freq = np.fft.rfftfreq(len(data), Fs)
# Then calculate (weighted) mean

mean_f = np.sum(freq * power_spectrum / np.sum(power_spectrum)) # This should equal to the formula in your image.

您不需要对numpy数组执行元素级乘法

相关问题 更多 >

    热门问题