EEGLAB Format¶
EEGLAB is a MATLAB toolbox for processing EEG, MEG, and other electrophysiological data. biosigIO can import EEGLAB .set files to work with biosignal data stored in this format.
Format Description¶
EEGLAB .set files are MATLAB files that contain:
- Signal data in a matrix format
- Channel information (names, locations, types)
- Event markers
- Metadata about the recording
- Processing history
Structure¶
A typical EEGLAB .set file contains these fields:
| Field | Description |
|---|---|
data |
Signal data matrix (channels × time points) |
chanlocs |
Channel information (names, types, locations) |
srate |
Sampling rate in Hz |
xmin |
Time of first data point (seconds) |
xmax |
Time of last data point (seconds) |
times |
Time points vector |
event |
Event markers |
epoch |
Epoch information (if epoched) |
subject |
Subject identifier |
condition |
Condition name or description |
Importer Implementation¶
The EEGLAB importer in biosigIO (biosigio.importers.eeglab) works by:
- Loading the
.setfile usingscipy.io.loadmat(pre-v7.3, non-HDF5 MAT-files only) - Normalizing the two EEGLAB save forms to a flat field map. Real EEGLAB saves a
dataset as a single MATLAB struct named
EEG, soloadmatreturns{'EEG': struct}with every field nested one level down; the legacy form writes the fields at the top level. biosigIO unwraps the nestedEEGstruct (and accepts the flat form) before reading any field, so a real-world.setloads correctly instead of silently importing as an empty recording - Extracting the EEG structure with signal data and metadata. When the matrix is
stored in a separate float32
.fdtfile (EEGLAB's default for large recordings, whereEEG.dataholds the.fdtfilename), the sibling.fdtnext to the.setis loaded and reshaped to(nbchan, pnts * trials) - Converting channel information to biosigIO's channel format
- Creating appropriate metadata dictionary
- Loading event markers into the recording's
eventstable (onset/duration in seconds)
Code Example¶
from biosigio import Recording
# Load data from EEGLAB .set file
rec = Recording.from_file('data.set', importer='eeglab')
# Print metadata
print(f"Subject: {rec.get_metadata('subject')}")
print(f"Condition: {rec.get_metadata('condition')}")
print(f"Sampling rate: {rec.get_metadata('srate')} Hz")
# Print channel information
print(f"Number of channels: {rec.get_n_channels()}")
channel_types = rec.get_channel_types()
print(f"Channel types: {channel_types}")
# Plot data
rec.plot_signals(time_range=(0, 5))
Channel Type Mapping¶
EEGLAB doesn't always explicitly designate channel types. biosigIO's EEGLAB importer uses the following rules to assign channel types:
- Channels with 'EMG' in the name are assigned type 'EMG'
- Channels with 'EEG' in the name are assigned type 'EEG'
- Channels with 'ACC' in the name are assigned type 'ACC'
- Other channels are assigned type 'OTHER'
Notes and Limitations¶
- Both EEGLAB save forms load: the standard single
EEGstruct (loadmatreturns{'EEG': struct}, which is what real EEGLAB writes) and the legacy flat layout. The importer normalizes them before reading, so a nested-struct file no longer imports as an empty recording - Only pre-v7.3 (non-HDF5)
.setfiles are supported, viascipy.io.loadmat; MATLAB v7.3/HDF5.setfiles are not supported - Signal data stored inline in the
.setor in a separate float32.fdtfile is supported; the sibling.fdtis resolved by the.setpath (so BIDS-renamed files load even thoughEEG.datakeeps the original.fdtname) - Event markers are loaded into the
eventstable (rec.events): EEGLAB event latency/duration (samples) are converted to onset/duration in seconds and the eventtypebecomes the description - Channel locations (if available) are preserved in the channel information
- Some EEGLAB-specific information may not be fully preserved in the conversion
- Time information is properly handled to maintain accurate timing in the imported data