使用Python从心电图信号中提取呼吸频率(BPM)

问题描述 投票:0回答:1

我正在尝试使用 Neurokit2 库从心电图信号中提取每分钟呼吸 (BPM) 中的呼吸频率 (RR)。

我在neurokit2文档中发现了这个ECG衍生呼吸(EDR)分析,这似乎很有帮助,但我不确定我是否理解得很好。

我在网上找不到有人实际这样做的代码。

有人可以帮助我吗?

到目前为止,我已经编写了以下代码,但我不确定这是否正确:

ecg = nk.data('ecg_1000hz.csv')

sampling_rate = 1000

 
# Visualize signal

nk.signal_plot(ecg)

# Check the results of every possible method at function ecg_rsp()  
method_name_lst = ["vangent2019", "sarkar2015", "charlton2016", "soni2019"]

 
# Clean an ECG signal to remove noise and improve peak-detection accuracy.

# Different cleaning method are implemented.

# Return: Vector containing the cleaned ECG signal.

cleaned_ecg = nk.ecg_clean(ecg_signal = ecg, sampling_rate = sampling_rate, method = "neurokit")

 
# Find R-peaks in an ECG signal using the specified method.

# The method accepts unfiltered ECG signals as input,

# although it is expected that a filtered (cleaned) ECG will result in better results

rpeaks, info = nk.ecg_peaks(cleaned_ecg, sampling_rate = sampling_rate)


# Calculate signal rate (per minute) from a series of peaks. It is a general function that works

# for any series of peaks (i.e., not specific to a particular type of signal). It is computed as

# ``60 / period``, where the period is the time between the peaks (see func:`.signal_period`).

# Return: A vector containing the rate (peaks per minute).

ecg_rate = nk.signal_rate(rpeaks, sampling_rate = sampling_rate, desired_length = len(rpeaks))

 
for method_name in method_name_lst:

    print("Method: {}\n".format(method_name))

  
    # Extract ECG-Derived Respiration (EDR), a proxy of a respiratory signal based on heart rate.

    # Return: A Numpy array containing the derived respiratory rate.

    # ????? Is this actually the respiratory signal ????

    resp_signal = nk.ecg_rsp(ecg_rate, sampling_rate = sampling_rate, method = method_name)

   
    #nk.signal_plot(resp_signal)

   
    # Clean a respiration signal

    # Return: Vector containing the cleaned respiratory signal.

    rsp_cleaned = nk.rsp_clean(resp_signal, sampling_rate = sampling_rate)

   
    # Find respiration rate

    # Return: Instantenous respiration rate.

    rsp_rate_onsets = nk.rsp_rate(rsp_cleaned, sampling_rate = sampling_rate, method = "trough")

    rsp_rate_xcorr = nk.rsp_rate(rsp_cleaned, sampling_rate = sampling_rate, method = "xcorr")

   
    # ??? Is this correct ????

    print("\tMean RR (Trough): {}\n".format(np.mean(rsp_rate_onsets)))

    print("\tMean RR (Xcorr): {}\n".format(np.mean(rsp_rate_xcorr)))
python signal-processing
1个回答
0
投票

我在文档中逐行检查了您的代码,并且您使用正确的参数调用了所有函数,因此一切正常!!!

© www.soinside.com 2019 - 2024. All rights reserved.