非官方中文翻译 本页译自 MNE-Python 官方文档: 查看英文原文 ↗。 文档版权归 MNE Developers 所有(BSD-3-Clause)。

XDAWN 去噪#

XDAWN 滤波器由分段训练得到,把信号投影到源空间,再只用前两个 XDAWN 成分投影回传感器空间。该过程类似 ICA,但为监督式,以最大化诱发响应的信号/(信号+噪声)比 [1] [2]。

警告

由于该去噪方法利用已知事件来最大化条件间对比的信噪比,可能导致过拟合。为避免统计分析问题,应把 fit 使用的分段与 apply 使用的分段分开。

# Authors: Alexandre Barachant <alexandre.barachant@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
from mne import Epochs, compute_raw_covariance, io, pick_types, read_events
from mne.datasets import sample
from mne.preprocessing import Xdawn
from mne.viz import plot_epochs_image

print(__doc__)

data_path = sample.data_path()

设置参数并读取数据

meg_path = data_path / "MEG" / "sample"
raw_fname = meg_path / "sample_audvis_filt-0-40_raw.fif"
event_fname = meg_path / "sample_audvis_filt-0-40_raw-eve.fif"
tmin, tmax = -0.1, 0.3
event_id = dict(vis_r=4)

# Setup for reading the raw data
raw = io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 20, fir_design="firwin")  # replace baselining with high-pass
events = read_events(event_fname)

raw.info["bads"] = ["MEG 2443"]  # set bad channels
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False, exclude="bads")
# Epoching, applying the SSP projectors that come with this dataset
raw.apply_proj()
epochs = Epochs(
    raw,
    events,
    event_id,
    tmin,
    tmax,
    proj=True,
    picks=picks,
    baseline=None,
    preload=True,
    verbose=False,
)

# Plot image epoch before xdawn
plot_epochs_image(epochs["vis_r"], picks=[230], vmin=-500, vmax=500)
MEG 2031, fT
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
        Average EEG reference (1 x 60)  idle
    Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Ready.
Reading 0 ... 41699  =      0.000 ...   277.709 secs...
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 1 - 20 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 1.00
- Lower transition bandwidth: 1.00 Hz (-6 dB cutoff frequency: 0.50 Hz)
- Upper passband edge: 20.00 Hz
- Upper transition bandwidth: 5.00 Hz (-6 dB cutoff frequency: 22.50 Hz)
- Filter length: 497 samples (3.310 s)

Created an SSP operator (subspace dimension = 4)
4 projection items activated
SSP projectors applied...
Not setting metadata
70 matching events found
No baseline correction applied
0 projection items activated

现在为分段(只含 vis_r 类)估计一组 xDAWN 滤波器。

应用上述三个 SSP 投影会使数据秩亏(302 而非 305),因此 xDAWN 依赖的广义特征值分解条件很差(甚至可能直接失败),除非告知它数据的秩。传入 rank="info" 可把分解限制在信号协方差的 302 维主子空间,并把所得滤波器与模式投影回 305 个传感器。

# Estimates signal covariance
signal_cov = compute_raw_covariance(raw, picks=picks)

# Xdawn instance
xd = Xdawn(n_components=2, signal_cov=signal_cov, rank="info")

# Fit xdawn
xd.fit(epochs)
Using up to 1388 segments
Number of samples used : 41640
[done]
Computing rank from data with rank='info'
    data: rank 302 after 3 projectors applied to 305 channels
    Created an SSP operator (subspace dimension = 3)
    Setting small data eigenvalues to zero (without PCA)
Estimating covariance using EMPIRICAL
Done.
Xdawn(rank='info',
      signal_cov=<Covariance | kind : full, shape : (305, 305), range : [-2.1e-23, +6.6e-23], n_samples : 41639>)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


调用 apply 对分段去噪,默认只保留上面 Xdawn 构造函数中 n_components 指定的前若干个成分所对应的信号子空间。

epochs_denoised = xd.apply(epochs)

# Plot image epoch after Xdawn
plot_epochs_image(epochs_denoised["vis_r"], picks=[230], vmin=-500, vmax=500)
MEG 2031, fT
Transforming to Xdawn space
Zeroing out 300 Xdawn components
Inverse transforming to sensor space
Not setting metadata
70 matching events found
No baseline correction applied
0 projection items activated

参考文献#

脚本总运行时间:(0 分 2.444 秒)

图库由 Sphinx-Gallery 生成