XDAWN filters are trained from epochs, signal is projected in the sources space and then projected back in the sensor space using only the first two XDAWN components. The process is similar to an ICA, but is supervised in order to maximize the signal to signal + noise ratio of the evoked response.
As this denoising method exploits the known events to maximize SNR of the contrast between conditions it can lead to overfitting. To avoid a statistical analysis problem you should split epochs used in fit with the ones used in apply method.
 Rivet, B., Souloumiac, A., Attina, V., & Gibert, G. (2009). xDAWN algorithm to enhance evoked potentials: application to brain-computer interface. Biomedical Engineering, IEEE Transactions on, 56(8), 2035-2043.
 Rivet, B., Cecotti, H., Souloumiac, A., Maby, E., & Mattout, J. (2011, August). Theoretical analysis of xDAWN algorithm: application to an efficient sensor selection in a P300 BCI. In Signal Processing Conference, 2011 19th European (pp. 1382-1386). IEEE.
# Authors: Alexandre Barachant <email@example.com> # # License: BSD (3-clause) from mne import (io, compute_raw_covariance, read_events, pick_types, Epochs) from mne.datasets import sample from mne.preprocessing import Xdawn from mne.viz import plot_epochs_image print(__doc__) data_path = sample.data_path()
Set parameters and read data
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' event_fname = data_path + '/MEG/sample/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 epochs = Epochs(raw, events, event_id, tmin, tmax, proj=False, picks=picks, baseline=None, preload=True, verbose=False) # Plot image epoch before xdawn plot_epochs_image(epochs['vis_r'], picks=, vmin=-500, vmax=500)
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 sec) Not setting metadata Not setting metadata 70 matching events found No baseline correction applied 0 projection items activated 0 bad epochs dropped
Now, we estimate a set of xDAWN filters for the epochs (which contain only
Using up to 1388 segments Number of samples used : 41640 [done] Computing rank from data with rank='full' MEG: rank 305 from info Created an SSP operator (subspace dimension = 3) Reducing data rank from 305 -> 305 Estimating covariance using EMPIRICAL Done.
Epochs are denoised by calling
apply, which by default keeps only the
signal subspace corresponding to the first
n_components specified in the
Xdawn constructor above.
Transforming to Xdawn space Zeroing out 303 Xdawn components Inverse transforming to sensor space Not setting metadata Not setting metadata 70 matching events found No baseline correction applied 0 projection items activated 0 bad epochs dropped
Total running time of the script: ( 0 minutes 8.331 seconds)
Estimated memory usage: 128 MB