(1)获取原肌电数据,生成图片
1.使用的库:mne
2.肌电数据的格式:edf
def Show_Information(file): raw = read_raw_edf(file,preload = True) info = raw.info print("raw:\n",raw,end="\n-----------------------\n") print("file:\n",file,end="\n-----------------------\n") print("channel name:\n",info['ch_names'],end = "\n-----------------------\n") print("channel number list:\n", mne.pick_channels(info['ch_names'],include=['BIP BIP1-Ref', 'BIP BIP2-Ref','BIP BIP3-Ref','BIP BIP4-Ref','BIP BIP5-Ref','BIP BIP6-Ref','BIP BIP7-Ref', 'BIP BIP8-Ref', 'BIP BIP9-Ref', 'BIP BIP10-Ref', 'BIP BIP11-Ref', 'BIP BIP12-Ref']), end = "\n-----------------------\n" ) # def Show_Pictrue(file): raw = read_raw_edf(file, preload=True) info = raw.info sampling_freq = raw.info['sfreq'] start_stop_seconds = np.array([5, 20]) start_sample, stop_sample = (start_stop_seconds * sampling_freq).astype(int) channel_list = mne.pick_channels(info['ch_names'],include=['BIP BIP1-Ref', 'BIP BIP2-Ref','BIP BIP3-Ref','BIP BIP4-Ref','BIP BIP5-Ref','BIP BIP6-Ref','BIP BIP7-Ref', 'BIP BIP8-Ref', 'BIP BIP9-Ref', 'BIP BIP10-Ref', 'BIP BIP11-Ref', 'BIP BIP12-Ref']) file_path = os.path.dirname(os.path.dirname(file)) for channel_index in range(len(channel_list)): raw_selection = raw[channel_index, start_sample:stop_sample] print(raw_selection) x = raw_selection[1] y = raw_selection[0].T svfile = os.path.join(file_path,'caichuanmeng','原肌电数据',"channel"+str(channel_index)+".png") if not os.path.exists(os.path.dirname(svfile)): os.mkdir(os.path.dirname(svfile)) EMG_picture = plt.plot(x, y) plt.savefig(svfile) plt.title(label=channel_index) #plt.show() plt.close() if __name__ == '__main__': from EMG_Filter_2 import * current_path = os.path.dirname(__file__) project_path = os.path.dirname(current_path) file = os.path.join(project_path,'cushion experiments_ EMG','caichuanmeng','cai_chuanmeng_2022-07-07_11-28-55_Segment_0.edf') Show_Information(file) Show_Pictrue(file)
生成的图片如下所示:
(2)去趋势
1.介绍、原理
去趋势处理可以去除传感器获取数据时产生的偏移,将数据分析集中在波动上。其原理为对数据减去一条最优(拟合)的直线、平面或者曲面,使得处理后的数据均值为0.
2.库:scipy
3.写法:
scipy.signal.detrend(data, axis=- 1, type='linear', bp=0, overwrite_data=False)
4.调用(待补充)
生成的图片如下所示:
(3)带通滤波(30~300Hz)
# 被限制在狭窄频率范围内的伪影有时可以通过过滤数据来修复。
# 频率受限伪影的两个例子是缓慢漂移和电力线噪声。
# 用低通滤波去除电源线噪声,用高通滤波消除缓慢漂移.
# 曹等的研究表明:当高通滤波器的截止频率为30Hz时,有助于去除心电干扰。
1.巴特沃斯滤波器原理
可参照:(21条消息) 数字信号处理公式变程序(四)——巴特沃斯滤波器(上)_没事多学点的博客-CSDN博客_巴特沃斯滤波器参数计算
2.库:scipy
需要提供截止频率Wn
Wn = 截止频率/(采样频率/2)
3.代码:
lowpass = 300 highpass = 30 wn1 = 2 * highpass / sampling_freq wn2 = 2 * lowpass / sampling_freq wn = [wn1, wn2] b, a = signal.butter(8, wn, 'bandpass') ....... filted_data = signal.filtfilt(b, a,data[channel_index],padlen=None)
生成的图片如下所示:
【Thanks to】
(21条消息) Matlab 去趋势处理_assassinIU的博客-CSDN博客_去趋势
标签:edf,Python,os,09,raw,file,path,Ref,BIP From: https://www.cnblogs.com/zhimingyiji/p/16705370.html