5.1. EEG: Electroencephalography

5.1.1. Preprocessing

5.1.1.1. Filtering

5.1.1.2. Power computation

5.1.1.3. Rhythmic Features

../_images/sphx_glr_plot_sp_eeg_rhythmic_features_001.png

5.1.1.4. Topographic Map

../_images/sphx_glr_plot_sp_eeg_topomaps_001.png

5.1.2. Working with different files/frameworks

Several file formats are used for storing EEG Data. Some are specifically designed to support device recording systems, and some are there to support specific frameworks and tools, such as eeglab/mne, etc. Even though these file formats/tools/frameworks are efficient for a particular field/scope, they limit the researchers/users’ ability to explore data freely (at least that’s how I feel). And sometimes, they even limit the understanding of the data itself.

We prefer to extract raw signals from these files to process. This approach gives researchers/users much more independence, as after extracting signals as arrays (numpy.arrays), one can apply any signal processing algorithm, from a wide-variety of fields or even to custom-built algorithms.

5.1.2.1. Read from EDF Files

Spkit have function spkit.io.read_bdf that supports reading EDF/BDF files of EEG.

Here is an example

../_images/sphx_glr_plot_sp_EDF_FILE_002.png

5.1.2.2. Work with MNE Raw Object

MNE is one of the tool used for EEG data processing. It allows to read several file formates as Raw Object, which further includes many analysis algorithms

Here is an example of reading MNE Raw object, extract EEG data from it, process it with ATAR algorithm and put EEG data back to MNE Raw Object for further processing and analysis.

Raw EEG Data

After Applying ATAR

../_images/sphx_glr_plot_sp_ATAR_MNE_RAW_001.png

Fig 1. Raw EEG Data

../_images/sphx_glr_plot_sp_ATAR_MNE_RAW_002.png

Fig 2. After Applying ATAR

5.1.3. Removing Artifacts

5.1.3.1. ATAR Algorithm

Apply ATAR on short windows of signal (single channel):

Signal is decomposed in smaller overlapping windows and reconstructed after correcting using overlap-add method.

For more details, check [1]

Operating Modes

1. Soft Thresholding

\[ \begin{align}\begin{aligned}\lambda_s (w) &= w & \quad \text{if } |w|<\theta_{\gamma}\\ &= \theta_{\alpha} \frac{1 - e^{\alpha w}}{1 + e^{\alpha w}} & \quad \text{otherwise}\end{aligned}\end{align} \]

2. Elimination

\[ \begin{align}\begin{aligned}\lambda_e (w) &= w & \quad \text{if } |w| \le \theta_{\alpha}\\ &= 0 & \quad \text{otherwise}\end{aligned}\end{align} \]

3. Linear Attenuation

\[ \begin{align}\begin{aligned}\lambda_a (w) &= w & \quad \text{if } |w| \le \theta_{\alpha}\\ &= sgn(w) \theta_{\alpha} \Big( 1 - \frac{|w| - \theta_{\alpha}}{\theta_{\beta}-\theta_{\alpha}} \Big) & \quad \text{if } \theta_{\alpha} < |w| \le \theta_{\beta}\\ &= 0 & \quad \text{otherwise}\end{aligned}\end{align} \]

Computing Threshold

  • \(f_{\beta}(r) = k_2 \cdot exp \Big(-\beta \frac{w_{max}}{k_2} \times \frac{r}{2} \Big)\)

  • \(\theta_{\alpha} = f_{\beta}(r) \quad \text{if } f_{\beta}(r) \ge k_1\) otherwise \(\theta_{\alpha} = k_1\)

  • \(\theta_{\gamma} = g_f \times \theta_{\alpha}\) , where a default value for ‘g_f = 0.8’ For Soft-threshold

  • \(\theta_{\beta} = b_f \times \theta_{\alpha}\) , where a default value for ‘b_f = 2’ For Linear Attenuation

https://raw.githubusercontent.com/Nikeshbajaj/spkit/master/figures/atar_beta_tune.gif

5.1.3.2. ICA Algorithm

ICA Filtering algorithm uses following three criteria for removing artifacts for EEG.

  1. Kurtosis based artifacts - mostly for motion artifacts:
    • parameter kur_thr is used as threshold on kurtosis of ICs. Any IC above kur_thr

      is removed. As higher kurtosis of component, more peaky it is.

  2. Correlation Based Index (CBI) for eye movement artifacts:
    • CBI method [1] computed the comparaision of power in prefrontal electrodes with frontal eletrodes, in IC.

      A component, that stisfy the criteria, is considered as component capturing eye-blink activity and removed.

    • For applying CBI method, index of prefrontal (AF - First Layer of electrodes towards frontal lobe)

      and frontal lobe (F - second layer of electrodes) channels needs to be provided.

    • For case of 14-channels Emotiv Epoc
      • ch_names = [‘AF3’,’F7’,’F3’,’FC5’,’T7’,’P7’,’O1’,’O2’,’P8’,’T8’,’FC6’,’F4’,’F8’,’AF4’]

      • Pre-frontal Channels =[‘AF3’,’AF4’],

      • Fronatal Channels = [‘F7’,’F3’,’F4’,’F8’]

      • then suplied index of channels are as follow;
        • AF_ch_index =[0,13]

        • F_ch_index =[1,2,11,12]

  3. Correlation of any IC with many EEG channels:
    • If any IC is correlated corr_thr % (80%) of elecctrodes, is considered to be artifactual

    • Similar like CBI, except, not comparing fronatal and prefrontal but to all

../_images/sphx_glr_plot_sp_eeg_artifact_removal_ICA_004.png