Skip to contents

Computes Common Spatial Pattern filters for two-class EEG discrimination. CSP maximizes the variance ratio between two conditions, making it a standard spatial filtering technique for motor imagery BCI.

Usage

eegCSP(x, labels, n_filters = 3, assay_name = NULL, output_assay = "csp")

Arguments

x

A PhysioExperiment object with epoched (3D) EEG data (time x channels x trials).

labels

Character or factor vector of class labels, one per trial. Must contain exactly two unique classes.

n_filters

Number of CSP filter pairs to retain (default: 3). The total number of spatial filters will be 2 * n_filters.

assay_name

Input assay name (default: first assay).

output_assay

Name the result is stored under. Despite the argument's name this is a key in metadata, NOT an assay: after the call assay(x, "csp") does not exist while metadata(x)$csp holds the result (default: "csp").

Value

Modified PhysioExperiment with CSP log-variance features in output_assay (a matrix of trials x 2 * n_filters) and CSP filter information stored in metadata(x)$csp as a list containing filters (spatial filter matrix), eigenvalues (selected eigenvalues), and classes (unique class labels).

References

Blankertz, B., et al. (2008). Optimizing spatial filters for robust EEG single-trial analysis. IEEE Signal Processing Magazine, 25(1), 41-56.

Examples

pe <- make_eeg_bci(n_trials = 30, n_channels = 8, sr = 256)
labels <- S4Vectors::metadata(pe)$labels
result <- eegCSP(pe, labels = labels, n_filters = 3)
# CSP filters and log-variance features are stored in metadata
csp_features <- S4Vectors::metadata(result)$csp_features
dim(csp_features)  # trials x (2 * n_filters)
#> [1] 60  6