Skip to main content

EegData

Struct EegData 

Source
pub struct EegData {
    pub channel_labels: Vec<String>,
    pub data: Vec<Vec<f64>>,
    pub sampling_rates: Vec<f64>,
    pub duration: f64,
    pub annotations: Vec<Annotation>,
    pub stim_channel_indices: Vec<usize>,
    pub is_discontinuous: bool,
    pub record_onsets: Vec<f64>,
}
Expand description

Raw EEG signal data read from a data file.

Stores multichannel time-series data as a channel × samples matrix, where each inner Vec<f64> represents one channel’s signal in physical units. Also carries annotations parsed from the file (EDF+ TAL, BDF+ status, or BrainVision markers).

Fields§

§channel_labels: Vec<String>

Channel labels in order.

§data: Vec<Vec<f64>>

Signal data: one Vec<f64> per channel, all in physical units (e.g., µV).

§sampling_rates: Vec<f64>

Sampling rate per channel in Hz.

§duration: f64

Total duration in seconds.

§annotations: Vec<Annotation>

Annotations parsed from the data file (EDF+ TAL, BDF+ status, .vmrk markers).

§stim_channel_indices: Vec<usize>

Indices of channels detected as stimulus/trigger channels.

§is_discontinuous: bool

Whether this recording is from an EDF+D/BDF+D discontinuous file. If true, there may be gaps in the time axis — use record_onsets to reconstruct the true timeline.

§record_onsets: Vec<f64>

Actual onset time of each data record in seconds (from EDF+ TAL). For continuous recordings this is empty or [0, dur, 2*dur, ...]. For discontinuous (EDF+D), these give the real timestamps of each record, which may have gaps.

Implementations§

Source§

impl EegData

Source

pub fn n_channels(&self) -> usize

Number of channels.

Source

pub fn n_samples(&self, channel: usize) -> usize

Number of samples for the given channel index.

Source

pub fn channel(&self, index: usize) -> Option<&[f64]>

Get a single channel’s data by index.

Source

pub fn channel_by_name(&self, name: &str) -> Option<&[f64]>

Get a single channel’s data by label.

Source

pub fn times(&self, channel: usize) -> Option<Vec<f64>>

Generate a times array in seconds for the given channel (like MNE’s raw.times).

Returns one f64 per sample: [0.0, 1/sr, 2/sr, ...].

Source

pub fn get_data_with_times(&self) -> (Vec<Vec<f64>>, Vec<f64>)

Get the data together with the times array (like MNE’s get_data(return_times=True)).

Source

pub fn select_channels(&self, names: &[&str]) -> EegData

Select a subset of channels by name (include), returning a new EegData.

Source

pub fn exclude_channels(&self, names: &[&str]) -> EegData

Exclude channels by name, returning a new EegData with all other channels.

Source

pub fn time_slice(&self, start_sec: f64, end_sec: f64) -> EegData

Extract a time window (in seconds) from all channels.

Source

pub fn convert_units(&mut self, unit_map: &HashMap<String, f64>)

Convert channel data to different units by applying a scale factor.

unit_map maps channel name → scale factor. For example, to convert from µV to V: {"EEG1": 1e-6}.

Source

pub fn pick_types( &self, types: &[ChannelType], channel_types: &[ChannelType], ) -> EegData

Select channels by type (like MNE’s pick_types).

types should be a list of ChannelType variants to keep. Requires that channel_types is available (from channels.tsv).

Source

pub fn concatenate(&mut self, other: &EegData) -> Result<(), String>

Concatenate another EegData in time (appending samples).

Both must have the same channels in the same order. Annotations from other are time-shifted by self.duration.

Source

pub fn reject_by_annotation(&self, pattern: &str) -> EegData

Remove (zero-out) data segments that overlap with annotations matching a description pattern (like MNE’s reject_by_annotation).

Returns a new EegData where samples overlapping “BAD” annotations (or annotations matching pattern) are replaced with f64::NAN.

Source§

impl EegData

Source

pub fn filter( &self, l_freq: Option<f64>, h_freq: Option<f64>, order: usize, ) -> EegData

Apply a bandpass filter to all channels (like MNE’s raw.filter(l_freq, h_freq)).

Uses a Butterworth IIR filter with zero-phase filtfilt application. l_freq and h_freq are in Hz. If l_freq is None, applies lowpass only. If h_freq is None, applies highpass only.

Source

pub fn notch_filter(&self, freq: f64, quality: f64) -> EegData

Remove power line noise at freq Hz and its harmonics (like MNE’s raw.notch_filter()).

Source

pub fn resample(&self, new_sr: f64) -> EegData

Resample all channels to a new sampling rate (like MNE’s raw.resample()).

Applies an anti-aliasing lowpass filter before downsampling.

Source

pub fn set_average_reference(&self) -> EegData

Re-reference to the average of all channels (like MNE’s raw.set_eeg_reference('average')).

Subtracts the mean across channels at each time point.

Source

pub fn set_reference(&self, ref_channel: &str) -> EegData

Re-reference to a specific channel (like MNE’s raw.set_eeg_reference([ch_name])).

Source

pub fn epoch( &self, tmin: f64, tmax: f64, event_desc: Option<&str>, ) -> Vec<EegData>

Extract epochs around events (like MNE’s mne.Epochs(raw, events, tmin, tmax)).

Returns a Vec of EegData, one per event matching event_desc. tmin and tmax are relative to event onset in seconds. If event_desc is None, epochs around all annotations.

Source

pub fn average_epochs(epochs: &[EegData]) -> Option<EegData>

Average a list of epochs to compute an ERP (Event-Related Potential).

All epochs must have the same shape. Like MNE’s epochs.average().

Source

pub fn compute_psd(&self, n_fft: Option<usize>) -> (Vec<f64>, Vec<Vec<f64>>)

Compute power spectral density using Welch’s method (like MNE’s raw.compute_psd()).

Returns (frequencies, psd) where psd[ch] is the power spectrum for each channel. n_fft is the FFT window size (default: sampling rate = 1 Hz resolution).

Trait Implementations§

Source§

impl Clone for EegData

Source§

fn clone(&self) -> EegData

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EegData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for EegData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TimeSeries for EegData

Source§

fn n_channels(&self) -> usize

Number of channels.
Source§

fn n_samples(&self) -> usize

Number of time samples (for channel 0; channels may differ for multi-rate).
Source§

fn channel_names(&self) -> &[String]

Channel names / labels.
Source§

fn sampling_rate(&self) -> f64

Primary sampling rate in Hz.
Source§

fn channel_data(&self, index: usize) -> Option<&[f64]>

Get one channel’s data by index.
Source§

fn duration(&self) -> f64

Total duration in seconds.
Source§

fn channel_data_by_name(&self, name: &str) -> Option<&[f64]>

Get one channel’s data by name.
Source§

fn times(&self) -> Vec<f64>

Time array for channel 0: [0, 1/sr, 2/sr, ...].
Source§

fn channel_means(&self) -> Vec<f64>

Mean value per channel.
Source§

fn channel_stds_with_means(&self, means: &[f64]) -> Vec<f64>

Standard deviation per channel (using pre-computed means).
Source§

fn channel_stds(&self) -> Vec<f64>

Standard deviation per channel.
Source§

fn z_score(&self) -> Vec<Vec<f64>>

Z-score normalize all channels (zero mean, unit variance). Returns a new Vec<Vec<f64>>.
Source§

fn min_max_normalize(&self) -> Vec<Vec<f64>>

Min-max normalize all channels to [0, 1].
Source§

fn window(&self, start_sec: f64, end_sec: f64) -> Vec<Vec<f64>>

Extract a time window as a channels × samples Vec<Vec<f64>>. Read more
Source§

fn epochs(&self, window_sec: f64) -> Vec<Vec<Vec<f64>>>

Extract non-overlapping fixed-length epochs. Read more
Source§

fn epochs_with_stride( &self, window_sec: f64, stride_sec: f64, ) -> Vec<Vec<Vec<f64>>>

Extract epochs with a given stride (allows overlap when stride < window). Read more
Source§

fn to_flat_vec(&self) -> Vec<f64>

Flatten channels × samples into a single contiguous Vec<f64> (row-major). Read more
Source§

fn to_column_major(&self) -> Vec<f64>

Get data as a contiguous Vec<f64> in column-major order (samples × channels). Read more
Source§

fn shape(&self) -> (usize, usize)

Shape as (n_channels, n_samples) — matches tensor dimension conventions.
Source§

fn log_variance(&self) -> Vec<f64>

Log-variance per channel — a simple but effective BCI feature. Read more
Source§

fn band_power(&self) -> Vec<f64>

Band power per channel — average power in the signal. Read more
Source§

fn rms(&self) -> Vec<f64>

RMS (root-mean-square) per channel.
Source§

fn peak_to_peak(&self) -> Vec<f64>

Peak-to-peak amplitude per channel: max - min.
Source§

fn covariance_matrix(&self) -> Vec<f64>

Compute the covariance matrix (channels × channels). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.