JOVANA
Explore Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

Common Spatial Patterns and the Discriminative-Filter Family

The generalized-eigenvalue machinery behind CSP, why it overfits, how shrinkage and FBCSP rescue it, and how xDAWN carries the same idea to ERP decoding.

The problem CSP was built for

In motor imagery, imagining a left- versus right-hand movement suppresses the sensorimotor mu rhythm over the opposite hemisphere — an event-related desynchronization that shows up as a drop in band power. The discriminative signal is therefore a spatial pattern of variance, and common spatial patterns (CSP) is the optimal linear filter for exactly that: it finds directions where one class has high variance and the other has low.

Two motor-imagery classes as scalp topographies; drag the regularization slider to watch CSP trade filter sharpness for robustness.

A generalized eigenvalue problem

Let \Sigma_1 and \Sigma_2 be the average band-passed covariances of the two classes. CSP seeks \mathbf{w} maximizing the variance ratio — a Rayleigh quotient.

J(\mathbf{w}) = \frac{\mathbf{w}^{\top}\Sigma_{1}\mathbf{w}}{\mathbf{w}^{\top}\Sigma_{2}\mathbf{w}} \qquad\Longrightarrow\qquad \Sigma_{1}\mathbf{w} = \lambda\,\Sigma_{2}\mathbf{w}

Maximizing the variance ratio is a generalized eigenvalue problem; eigenvalues near 1 mark filters that pass class 1, near 0 those that pass class 2.

Common Spatial Patterns finds filters that make one class's variance large and the other's small — maximizing their ratio. Maximizing that ratio turns out to be a generalized eigenvalue problem; eigenvalues near 1 favour class 1, near 0 favour class 2.

J(\mathbf{w})
The variance ratio being maximized (a Rayleigh quotient).
\Sigma_1,\,\Sigma_2
The covariance matrices of the two classes.
\lambda
The eigenvalue — how strongly a filter separates the classes.
\Sigma_1\mathbf{w}=\lambda\Sigma_2\mathbf{w}
The generalized eigenvalue equation the solution satisfies.

Equivalently, whiten the data with the composite covariance \Sigma_1+\Sigma_2; the eigenvectors that simultaneously diagonalize both classes are the CSP filters. Their eigenvalues sum to one, so extreme values at both ends are the most discriminative — you keep the top and bottom m pairs.

The geometry: after whitening on Σ1+Σ2, the CSP axes point where the two class ellipsoids are most stretched apart.

# X1, X2: trials x channels x time, already band-pass filtered
S1 = mean_cov(X1)              # class-1 spatial covariance (C x C)
S2 = mean_cov(X2)              # class-2 spatial covariance
# generalized eigendecomposition of the pencil (S1, S1 + S2)
evals, W = eig(S1, S1 + S2)    # columns of W are spatial filters
order = argsort(evals)
W = W[:, order]                # sort by discriminability
filt = hstack([W[:, :m], W[:, -m:]])   # m most extreme pairs each end
feat = log(var(filt.T @ trial, axis=1))  # log-variance feature vector
CSP in a nutshell: one generalized eigendecomposition, then keep the extreme filters and take log-variance features.

From filters to features

You do not feed the filtered signal to a classifier directly; you feed its log-variance. The log both stabilizes the variance (making it more Gaussian for an LDA classifier) and turns the multiplicative gain of ERD into an additive feature.

f_j = \log\!\left(\frac{\mathbf{w}_j^{\top}\Sigma\,\mathbf{w}_j}{\sum_{k}\mathbf{w}_k^{\top}\Sigma\,\mathbf{w}_k}\right)

The normalized log-variance feature for filter j on a trial's covariance Σ — the classic CSP feature fed to LDA.

After CSP gives you filters, each trial is summarized by the log of its filtered variance, normalized across filters. Taking the log makes the feature well-behaved for a linear classifier like LDA.

f_j
The feature produced by filter j.
\mathbf{w}_j^{\top}\Sigma\,\mathbf{w}_j
The variance the filter passes on this trial's covariance \Sigma.
\sum_k \mathbf{w}_k^{\top}\Sigma\,\mathbf{w}_k
The total across all filters — the normalizer.
\log
Stabilizes the feature's distribution.

Why raw CSP overfits — and how to fix it

The standard cure is to shrink each class covariance toward a well-conditioned target before the eigendecomposition — this is spatial-filter regularization, and the analytic Ledoit–Wolf estimate picks the shrinkage strength \gamma for you.

\tilde{\Sigma} = (1-\gamma)\,\hat{\Sigma} + \gamma\,\frac{\operatorname{tr}(\hat{\Sigma})}{C}\,I, \qquad \gamma\in[0,1]

Shrinkage pulls the covariance toward a scaled identity, taming the smallest eigenvalues that wreck CSP.

With few trials, covariance estimates get unreliable — their smallest eigenvalues blow up and wreck CSP. Shrinkage mixes the noisy estimate with a clean, scaled identity, pulling extreme values back toward safety. \gamma sets how much you regularize.

\tilde{\Sigma}
The shrunk (regularized) covariance.
\hat{\Sigma}
The raw sample covariance.
\gamma
The shrinkage strength — 0 is raw, 1 is fully toward the identity.
\tfrac{\operatorname{tr}(\hat{\Sigma})}{C}\,I
The scaled-identity target it shrinks toward.

FBCSP: adding the frequency axis

Plain CSP needs you to pick a band in advance, but the discriminative mu/beta band is subject-specific. Filter-bank CSP (FBCSP) removes that guess: run CSP inside a bank of overlapping bands, then select the most informative band-and-filter combinations by mutual information. This near-parameter-free recipe won the BCI Competition IV and remains the reference EEG baseline.

  1. Band-pass the data into a bank of overlapping sub-bands (e.g. 4–8, 8–12, … Hz).
  2. Fit shrinkage-CSP inside each band and take the log-variance features.
  3. Select the top features across all bands by mutual information with the label.
  4. Classify the selected features (LDA is the usual, robust choice).

xDAWN: the ERP cousin

CSP separates variance, but P300 spellers need to separate an evoked shape buried in ongoing EEG. xDAWN carries the generalized-eigenvalue idea to ERP decoding: it finds filters that maximize the ratio of evoked-response power to total power, enhancing the P300 before classification. In modern pipelines its output feeds an ERP covariance representation for Riemannian classifiers.

\mathbf{w}_{\mathrm{xDAWN}} = \arg\max_{\mathbf{w}} \frac{\mathbf{w}^{\top}\Sigma_{\mathrm{ERP}}\,\mathbf{w}}{\mathbf{w}^{\top}\Sigma_{X}\,\mathbf{w}}

xDAWN maximizes evoked-response covariance over total covariance — the same Rayleigh quotient, a different numerator.

xDAWN adapts the same 'maximize a variance ratio' idea to evoked responses (like the P300): find filters that boost the repeatable evoked component relative to the total signal. Same Rayleigh quotient, just a different numerator.

\mathbf{w}_{\mathrm{xDAWN}}
The xDAWN spatial filter.
\Sigma_{\mathrm{ERP}}
Covariance of the evoked (ERP) response.
\Sigma_X
Covariance of the total signal.
\arg\max
Pick the filter maximizing the ratio to enhance the ERP.