一 概念
NeuroKit2是一个开源的、社区驱动的、以用户为中心的Python库,可用于多种生理信号的分析处理(例如ECG、PPG、EDA、EMG、RSP),还包括用于特定处理步骤(如频率)的工具提取和过滤方法,并在易用性和参数微调之间进行权衡。其目标是提高神经生理学研究的透明度和再现性,并促进探索和创新,它的设计理念以用户体验和对新手和高级用户的可用性为中心。
二 实例解析
1.安装不是很麻烦,这里太基础,就不讲了,直接上一个生成心电数据的实例:
import warnings
warnings.filterwarnings('ignore')
# Load NeuroKit and other useful packages
import neurokit2 as nk
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#%matplotlib inline
# Alternate heart rate and noise levels
ecg50 = nk.ecg_simulate(duration=10, noise=0.05, heart_rate=50)
print(ecg50)
ecg100 = nk.ecg_simulate(duration=10, noise=0.01, heart_rate=100)
plt.rcParams['figure.figsize'] = [20, 6] # Bigger images
# Visualize
ecg_df = pd.DataFrame({"ECG_100": ecg100,
"ECG_50": ecg50})
print(ecg_df)
nk.signal_plot(ecg_df, subplots=True)
plt.show()
2.另外一种方式:
import warnings
warnings.filterwarnings('ignore')
# Load NeuroKit and other useful packages
import neurokit2 as nk
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
#%matplotlib inline
# Alternate methods
ecg_sim = nk.ecg_simulate(duration=10, method="simple")
ecg_com = nk.ecg_simulate(duration=10, method="ecgsyn")
# Visualize
methods = pd.DataFrame({"ECG_Simple": ecg_sim,
"ECG_Complex": ecg_com})
nk.signal_plot(methods, subplots=True)
plt.show()
3.这两个代码都可以直接运行并显示结果的,结果如下所示: