赞
踩
关注微信公众号:脑机接口研习社
了解脑机接口最近进展
Python专栏 | 脑电图和脑磁图(EEG/MEG)的数据分析方法之载入数据
Python专栏 | MNE脑电数据(EEG/MEG)可视化
Python专栏 | 独立成分分析(ICA)的实例应用:消除伪影信号
持续更新中……
独立成分分析(ICA)是MNE-Python教程重点介绍的脑电数据预处理技术,在之前的几篇文章里我们重点介绍了如何通过ICA技术来清理原始数据里的伪影数据,以及如何在Components里识别伪影信号。戳下面的文章链接可查看具体内容,这里将不再赘述。
Python专栏 | 独立成分分析(ICA)的实例应用:消除伪影信号
代码示例:
# set up and fit the ICA
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2] # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)
输出结果:
Fitting ICA to data using 364 channels (please be patient, this may take a while) Selecting by number: 20 components Fitting ICA took 3.6s. Using multitaper spectrum estimation with 7 DPSS windows Not setting metadata Not setting metadata 138 matching events found No baseline correction applied 0 projection items activated 0 bad epochs dropped C:\ProgramData\Anaconda3\lib\site-packages\mkl_fft\_numpy_fft.py:331: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result. output = mkl_fft.rfft_numpy(a, n=n, axis=axis) Not setting metadata Not setting metadata 138 matching events found No baseline correction applied 0 projection items activated 0 bad epochs dropped
Note:
由前面介绍ICA的文章可知,ICA001和ICA002分别是眼动和心跳的伪影信号,故ICA.exclude选择了1和2。
在确定要删除哪些Components后,我们将它们作为exclude参数传递,然后将ICA应用于原始信号raw。
ICA.apply的方法要求将原始数据加载到内存中(默认情况下是仅从磁盘中读取数据),因此我们将首先使用load_data。
我们还将复制Raw对象,以便我们可以并行比较去除伪影之前和之后的信号。
代码示例:
orig_raw = raw.copy()
raw.load_data()#ICA.apply的方法要求将原始数据加载到内存中,因此我们将首先使用load_data。
ica.apply(raw)
# show some frontal channels to clearly illustrate the artifact removal
chs = ['MEG 0111', 'MEG 0121', 'MEG 0131', 'MEG 0211', 'MEG 0221', 'MEG 0231',
'MEG 0311', 'MEG 0321', 'MEG 0331', 'MEG 1511', 'MEG 1521', 'MEG 1531',
'EEG 001', 'EEG 002', 'EEG 003', 'EEG 004', 'EEG 005', 'EEG 006',
'EEG 007', 'EEG 008']
chan_idxs = [raw.ch_names.index(ch) for ch in chs]
orig_raw.plot(order=chan_idxs, start=12, duration=4)
raw.plot(order=chan_idxs, start=12, duration=4)
输出结果:
Reading 0 ... 41699 = 0.000 ... 277.709 secs...
Out[8]: <Raw | sample_audvis_filt-0-40_raw.fif, 376 x 41700 (277.7 s), ~122.9 MB, data loaded>
Applying ICA to Raw instance
Transforming to ICA space (20 components)
Zeroing out 2 ICA components
Projecting back using 364 PCA components
Note:
从图上可以很明显看到MEG信号的区别,第一张图是去除伪影之前的脑电数据图,而第二张图是去除伪影之后的脑电数据图。
未完待续……
参考链接:
https://mne.tools/stable/auto_tutorials/intro/plot_10_overview.html#preprocessing
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。