Neurokit 分析心率的简单用法

NeuroKit

显示 ECG 数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import neurokit2 as nk
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('Polar_ECG.csv')
ecg = df['ECG']
# ecg = df.ECG
signals, info = nk.ecg_process(ecg, sampling_rate=130) # 传感器采样率
nk.ecg_plot(signals, info)

figure = plt.gcf()
figure.set_size_inches(32 / 1.5, 18 / 1.5) # 拉伸图片
plt.savefig('ECG.png', bbox_inches='tight', dpi=120)
# plt.show()

分析HRV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# This is not an error but just a warning that some indices will not be calculated due to the short recordings
# 时间太短的话,hrv分析不出来

import neurokit2 as nk
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('Polar_ECG.csv')
# ecg = df['ECG']
ecg = df.ECG

# data = nk.data("bio_resting_8min_100hz")
# print(data['ECG'])
# print(type(data['ECG']))
# 这里可以看到官方给的数据

# ecg = pd.Series(ecg, name='ECG')
# 如果 ecg 是 list 的话,要把 list 转换成 series

peaks, info = nk.ecg_peaks(ecg, sampling_rate=130)
# Compute HRV indices
hrv = nk.hrv(peaks, sampling_rate=130, show=True)

hrv.to_csv('HRV.csv', index=False, header=True)

figure = plt.gcf()
figure.set_size_inches(32 / 1.5, 18 / 1.5)
plt.savefig('HRV.png', bbox_inches='tight', dpi=120)
# plt.show()

Neurokit 分析心率的简单用法
https://wonderhoi.com/2024/03/02/Neurokit-分析心率的简单用法/
作者
wonderhoi
发布于
2024年3月2日
许可协议