eeg_toolbox package

eeg_toolbox.load.load_edf_data(filepath)

Load the raw EDF data from a file path into a Numpy array.

Parameters:

filepath (str) – Path to the EDF file.

Returns:

The loaded data stored in a numpy array. ch_names: List of channel names. sfreq: Sampling frequency.

Return type:

data (np.ndarray)

eeg_toolbox.processing.bandpass_filter(data, freq, lowcut=None, highcut=None, order=5)

Apply bandpass Butterworth filter.

Parameters:
  • data (np.ndarray) – EEG data, shape (n_channels, n_times)

  • lowcut (float) – Low cutoff frequency.

  • highcut (float) – High cutoff frequency.

  • freq (float) – Sampling frequency.

  • order (int) – Filter order.

Returns:

Filtered EEG data.

Return type:

data_filtered (np.ndarray)

eeg_toolbox.processing.mean_centering(data)

Subtract mean per channel.

Parameters:

data (np.ndarray) – EEG data, shape (n_channels, n_times)

Returns:

centered (np.ndarray)

eeg_toolbox.processing.minmax_normalization(data)

Apply min-max normalization per channel.

Parameters:

data (np.ndarray) – EEG data, shape (n_channels, n_times)

Returns:

normalized (np.ndarray)

eeg_toolbox.processing.notch_filter(data, fs, filter_freq=50.0, Q=200)

Apply a notch filter at freq Hz to remove power line noise.

Parameters:
  • data (np.ndarray) – EEG data (n_channels, n_times)

  • fs (float) – Sampling frequency

  • filter_freq (float) – Line noise frequency to remove (50 or 60 Hz)

  • Q (float) – Quality factor (higher = narrower notch)

Returns:

EEG data with line noise removed

Return type:

filtered_data (np.ndarray)

eeg_toolbox.processing.resample_data(data, old_sfreq, new_sfreq)

Resample EEG data to a new sampling frequency.

Parameters:
  • data (np.ndarray) – EEG data, shape (n_channels, n_times)

  • old_sfreq (float) – Original sampling rate.

  • new_sfreq (float) – Target sampling rate.

Returns:

Resampled EEG data.

Return type:

data_resampled (np.ndarray)

eeg_toolbox.processing.zscore_normalization(data)

Apply z-score normalization per channel. (doesn’t work with fourier transform, only the dc component (0hz) remains in ft)

Parameters:

data (np.ndarray) – EEG data, shape (n_channels, n_times)

Returns:

Normalized EEG data.

Return type:

data_normalized (np.ndarray)

eeg_toolbox.visual.plot_eeg_overview(data, ch_names, sfreq, n_channels=5, offset=100)

Plots the first n EEG channels with an offset on the time axis.

Parameters:
  • data – The EEG data in a numpy array format.

  • ch_names – List containing the names of the EEG channels.

  • sfreq – Sampling frequency of the EEG data.

  • n_channels – The first n channels of the EEG data that appears on the plots. (Default: 5)

  • offset – Customize the offset of the data on the plot. (Default: 100)

eeg_toolbox.visual.plot_fft_spectrum(mean_fft, sfreq, n_samples)

Displays the average frequency spectrum of the EEG data (Fourier transform). Requires the returned data from data_fourier() function.

Parameters:
  • mean_fft – The fourier transformed EEG data (returned from data_fourier() function).

  • sfreq – Sampling frequency of the EEG data.

  • n_samples – The number of data points in the EEG data.

eeg_toolbox.visual.plot_graph_segments(data, sfreq, events, ch_names, window_sec=1.5, n_show=5)

Plots the EEG bands detected in the data with a custom size window around the detected events. Requires the returned data from detect_graphoelements() function.

Parameters:
  • data – A two dimensional array with the shape (n_channels, n_samples). n_channels: how many EEG channels; n_samples: how many samples are on each channel (length in time)

  • sfreq – Sampling frequency of the EEG data.

  • events – Events returned by the detect_graphoelements function. All elements have this structure: {“channel_index”: The index of the channel on which the event is occuring. “time_sec”: The time of the event expressed in secundum. “energy_3_8Hz”: The energy of the detected event between 3 and 8 Hz. “dominant_rhythm”: What kind of wave is the detected event e.g. theta, delta etc. energy of all the other bands}

  • ch_names – A list containing the names of the EEG channels. Returned from load_edf_data().

  • window_sec – The plot visualizes a +- window_sec second window around the detected events. Default: 1.5

  • n_show – How many detected events to draw from the events list.

eeg_toolbox.fourier_of_data.data_fourier(data)

Calculates the Fourier transform of EEG channels of the data.

Parameters:

data (np.ndarray) – The loaded data stored in a numpy array.

Returns:

The Fourier transform of EEG channels of the data separately. mean_fft (np.ndarray): The mean of the Fourier transforms.

Return type:

fft_magnitudes (np.ndarray)

eeg_toolbox.detection.detect_graphoelements(data, sfreq, bands, duration_sec=60)

Using Short-time Fourier transfrom, it examines the 3–8 Hz energy on all channels. If this is abnormal, the event is recorded.

Parameters:
  • data – EEG signal matrix [channel, time].

  • sfreq – Sampling frequency of the EEG data.

  • bands – Describes the frequency bands. Eg.: bands={“delta” : [0, 4], “theta”: [4, 8]})

  • duration_sec – The number of seconds to process the the signals.

Returns:

Events returned by the detect_graphoelements function. All elements have this structure:

{“channel_index”: The index of the channel on which the event is occuring. “time_sec”: The time of the event expressed in secundum. “energy_3_8Hz”: The energy of the detected event between 3 and 8 Hz. “dominant_rhythm”: What kind of wave is the detected event e.g. theta, delta etc. energy of all the other bands}

Return type:

results