Digital Filtering - EEG
Difficulty Level:
Tags pre-process☁eeg☁digital filtering

EEG acquired signals are highly vulnerable to different kind of noise.
Some noise can be avoided by preparation of test surroundings, hence other noise can not be avoided and must be removed by specific filtering methods.
The Signal-to-Noise ratio (SNR) of an acquired EEG signal is a measure of signal quality and describes the ratio of signal power to noise power. The raw Electroencephalogram (EEG) data needs filtering in order for proper noise reduction and signal evaluation.
Reasons and implications of artefacts causing the noise are discussed in this Jupyter Notebook as well as the application and implication of different filters on the signal.

1 - Importation of the needed packages

In [1]:
# Biosignalsnotebooks python package
import biosignalsnotebooks as bsnb

# Scientific packages
from numpy import array, mean
from scipy.signal import welch

2 - Loading of acquired EEG data and Unit Conversion
For a detailed explanation on how to load the acquired EEG data as well as performing the Unit Conversion of the raw data, please refer to the notebooks Load acquired data from .txt file and EEG-Unit Conversion

2.1 - Load data from signal samples library

In [2]:
# Load Data from file path
data_artefact_segment_1, header = bsnb.load_signal("eeg_sample_artefacts_seg1", get_header=True)
data_artefact_segment_2 = bsnb.load_signal("eeg_sample_artefacts_seg2")
data_artefact_segment_3 = bsnb.load_signal("eeg_sample_artefacts_seg3")

2.2 - Select the relevant channel to work with

In [3]:
# [The acquired EEG data is at channel 2 ("CH2") 
# for segments 1 and 2 and at channel 1 ("CH1") for segment 3]
eeg_artefact_segment_1 = data_artefact_segment_1["CH2"]
eeg_artefact_segment_2 = data_artefact_segment_2["CH2"]
eeg_artefact_segment_3 = data_artefact_segment_3["CH1"]

2.3 - Store some acquisition constants inside variables
Two extremely relevant parameters defined before data acquisition are the sampling rate and ADC resolution. On the previous cell we only request the header of eeg_sample_artefacts_seg1 signal sample because the remaining signal samples were collected in similar conditions (at the same sampling rate and resolution).

In [4]:
sr = header["sampling rate"] # Sampling Rate
resolution = header["resolution"][0]

2.4 - Conversion of ADC sample values to physical units (uV) and generation of a time-axis
The device used to acquire EEG data belongs to the "biosignalsplux" model. In order to convert the raw EEG signal to its physical units, the recorded data must be passed as an input of raw_to_phy function.

In [5]:
#Unit Conversion
uv_eeg_artefact_segment_1 = bsnb.raw_to_phy("EEG", "biosignalsplux", eeg_artefact_segment_1, resolution, "uV")
time_eeg_artefact_segment_1 = bsnb.generate_time(uv_eeg_artefact_segment_1, sr)

uv_eeg_artefact_segment_2 = bsnb.raw_to_phy("EEG", "biosignalsplux", eeg_artefact_segment_2, resolution, "uV")
time_eeg_artefact_segment_2 = bsnb.generate_time(uv_eeg_artefact_segment_2, sr)

uv_eeg_artefact_segment_3 = bsnb.raw_to_phy("EEG", "biosignalsplux", eeg_artefact_segment_3, resolution, "uV")
time_eeg_artefact_segment_3 = bsnb.generate_time(uv_eeg_artefact_segment_3, sr)

3 - Plot of Raw Data and Artefact check
In the following topics, the previously loaded raw data is compared to check for artefacts influencing the signal.

Types of Artefacts which can influence the signal:

  1. Noise such as coffee machine, elevator, people talking
  2. Movement artefacts such as eye movement, jaw clenching
  3. Electrical Noise such as wlan, electricity (50Hz)
  4. Electrode placement

The latter is explained in detail in the notebook EEG - Electrode Placement
Besides the mentioned artefacts, it needs to be considered that the signal varies among different test subjects!

3.1 Noise Artefacts
Surrounding noise can be eliminated but in some locations not completely be prevented. To illustrate surrounding noise in the signal, the following plot shows a baseline test with closed eyes: The electrodes were placed in the occipital lobe O1 and O2 electrode placement.

In [6]:
#Plot of Raw data - eys closed
bsnb.plot_eeg_signal_wind(time_eeg_artefact_segment_3, uv_eeg_artefact_segment_3, time_range=[0, 90.5], time_windows_evt_1=[(20.5,23), (55, 65),(89.5,90.5)], time_windows_evt_2=[], y_axis_label="Electric Voltage (uV)", legend=["Noise - coffee machine / people talking"])