Feature Extraction#
Sleep Feature Extractor#
The Feature Extractor package contains SleepSpectralFeatureExtractor for spectral feature extraction from designed for hypnogram classification from a raw EEG signal.
The extractor can return data rate which gives a relative ratio of valid values in the input signal based on a number of NaN values. The extractor requires information about frequency bands at which parameters will be calculated. Please see an example below.
Example
import numpy as np
from brainmaze_eeg.features.feature_extraction import SleepSpectralFeatureExtractor
from brainmaze_eeg.features.spectral_features import (mean_bands, mean_frequency,
relative_bands)
# synthetic signal: 10 Hz sine + noise, 5 min at 500 Hz
fs = 500 # sampling frequency (Hz)
t = np.arange(0, 300, 1 / fs)
x = np.sin(2 * np.pi * 10 * t) + 0.1 * np.random.default_rng(0).normal(size=t.size)
segm_size = 30 # s, one feature value per 30-s segment
fbands = [[1, 4], [4, 8], [8, 12], [12, 14], [14, 20], [20, 30]] # Hz
extractor = SleepSpectralFeatureExtractor(fs=fs, segm_size=segm_size, fbands=fbands,
datarate=True)
extractor.extraction_functions = [mean_bands, mean_frequency, relative_bands]
feature_values, feature_names = extractor(x) # one array (n_segments,) per feature
# feature_names: DATA_RATE, MEAN_PSD1-4Hz, ..., MEAN_DOMINANT_FREQUENCY, REL_PSD_1-4Hz, ...
Sources#
This Feature Extractor implementation is based on the following papers (when use whole, parts, or are inspired by, we appreciate you acknowledge and refer these journal papers)
and on repository Semi Automated Sleep Classifier, see details in the original repository.
- class brainmaze_eeg.features.feature_extraction.SleepSpectralFeatureExtractor(fs: float = None, segm_size: float = None, fbands: list = None, sperwelchseg: float = None, soverlapwelchseg: float = 0.0, nfft: int = None, filters_attenuate: list = [], repeat_attenuate: int = 1, ignore_bands: list = [], datarate: bool = False, n_processes: int = 1)#
- attenuate(x)#
Apply attenuation filters to remove specific frequencies (e.g., stimulation artifacts).
- design_filters()#
Design FIR bandpass filters for each frequency band.
- property extraction_functions#
Get the list of feature extraction functions.
- prefilter(x)#
Apply low and high pass filters to the signal.
- process_signal(x)#
- Parameters:
x