Common Spatial Patterns (CSP)

Description

This module implements the Common Spatial Patterns (CSP) filter, a spatial filtering technique used to enhance the discriminability of EEG signals for binary classification tasks.

The CSP filter maximizes the variance of one class while minimizing the variance of another, making it ideal for tasks like motor imagery classification. The implementation uses eigenvalue decomposition to compute the spatial filters.

Class

class bciflow.modules.sf.csp.csp(m_pairs: int = 2)[source]

Bases: object

n_electrodes

(int) The number of electrodes.

m_pairs

(int) The number of pairs of spatial filters to extract (default is 2).

W

(np.ndarray) The spatial filters.

bands

(int) The number of bands used.

fit(eegdata: dict) ndarray[source]

Fits the CSP filter to the input data, calculating the spatial filters.

Parameters:

eegdata (dict) – The input data.

Return type:

self

fit_transform(eegdata: dict) dict[source]

Combines fitting and transforming into a single step.

Parameters:

eegdata (dict) – The input data.

Returns:

output – The transformed data.

Return type:

dict

transform(eegdata: dict) dict[source]

Applies the learned spatial filters to the input data.

Parameters:

eegdata (dict) – The input data.

Returns:

output – The transformed data.

Return type:

dict

For more details on CSP, refer to:
  • Ramoser, H., et al. (2000). Optimal Spatial Filtering of Single Trial EEG During Imagined Hand Movement. IEEE Transactions on Rehabilitation Engineering.