The common spatial patterns (CSP) algorithm [1, 2] is a popular supervised decomposition method for the EEG signal analysis which is used to distinguish between two classes (conditions). It finds spatial filters that maximize the signal variance for one class, while simultaneously minimizing the signal variance for the opposite class. Here, we review the CSP algorithm and its two main implementation approaches.

We assume that the EEG is already band-pass filtered and centered. Let be the EEG signal of trial where is the number of channels and is the number of samples per trial. We compute the spatial covariance by averaging over trials of class 1:

(1) where is the set of indices corresponding to trials belonging to class 1, denotes the size of the set , and is the trace of a matrix, and spatial covariance equivalently for class 2. In the following derivations of CSP, we assume that and have full rank (i.e, ).

The goal of CSP is to find a decomposition matrix that projects the signal in the original space to as follows:

(2) with the following properties:

(3) (4) and scaling such that

(5) where is the identity matrix. In other words, and share the same eigenvectors and the sum of corresponding eigenvalues is always 1. The eigenvector with the largest eigenvalue for class 1 has the smallest eigenvalue for class 2 and vice-versa.
Columns of are spatial filters. Columns of a matrix represent spatial patterns.

### Geometric approach

We determine whitening transformation matrix for composite spatial covariance such as

(6) We factorize composite spatial covariance

(7) where is the orthogonal matrix of eigenvectors (in columns) and is the diagonal matrix of the corresponding eigenvalues of . We define whitening transformation as

(8) and transform matrices and (9) We factorize matrix (10) where is the orthogonal matrix of eigenvectors and is the diagonal matrix of the corresponding eigenvalues of . We define decomposition matrix as

(11) Then this satisfy 3

(12) and also 4 using 5

(13) ### Generalized eigenvalue problem approach

We can directly solve by getting from 5 :

(14) as

(15) and by inserting this into 3

(16) we get

(17) which is an equation of generalized eigenvalue problem. Or equivalently, by inserting into 4 we get the following generalized eigenvalue problem

(18) #### Another solution

We also mention another solution (with different diagonal values and ), which is often present in the literature, that satisfies only 3 and 4 but not 5. We get from 3 as

(19) and by inserting this into 4

(20) we get

(21) which is a generalized eigenvalue problem. This solution has different eigenvalues. differs from only by a diagonal scaling matrix (22) with to satisfy 5. J. Müller-Gerking, G. Pfurtscheller, and H. Flyvbjerg, “Designing optimal spatial filters for single-trial EEG classification in a movement task,” Clinical neurophysiology, vol. 110, iss. 5, p. 787–798, 1999.
[Bibtex]
@article{Muller-Gerking1999,
abstract = {We devised spatial filters for multi-channel EEG that lead to signals which discriminate optimally between two conditions. We demonstrate the effectiveness of this method by classifying single-trial EEGs, recorded during preparation for movements of the left or right index finger or the right foot. The classification rates for 3 subjects were 94, 90 and 84{\%}, respectively. The filters are estimated from a set of multi-channel EEG data by the method of Common Spatial Patterns, and reflect the selective activation of cortical areas. By construction, we obtain an automatic weighting of electrodes according to their importance for the classification task. Computationally, this method is parallel by nature, and demands only the evaluation of scalar products. Therefore, it is well suited for on-line data processing. The recognition rates obtained with this relatively simple method are as good as, or higher than those obtained previously with other methods. The high recognition rates and the method's procedural and computational simplicity make it a particularly promising method for an EEG-based brain–computer interface.},
author = {M{\"{u}}ller-Gerking, Johannes and Pfurtscheller, Gert and Flyvbjerg, Henrik},
doi = {10.1016/S1388-2457(98)00038-8},
issn = {13882457},
journal = {Clinical Neurophysiology},
month = {may},
number = {5},
pages = {787--798},
publisher = {Elsevier},
title = {{Designing optimal spatial filters for single-trial EEG classification in a movement task}},
volume = {110},
year = {1999}
} B. Blankertz, R. Tomioka, S. Lemm, M. Kawanabe, and K. Muller, “Optimizing Spatial filters for Robust EEG Single-Trial Analysis,” Ieee signal processing magazine, vol. 25, iss. 1, p. 41–56, 2008.
[Bibtex]
@article{Blankertz2008,
author = {Blankertz, Benjamin and Tomioka, Ryota and Lemm, Steven and Kawanabe, Motoaki and Muller, Klaus-robert},
doi = {10.1109/MSP.2008.4408441},
issn = {1053-5888},
journal = {IEEE Signal Processing Magazine},
number = {1},
pages = {41--56},
title = {{Optimizing Spatial filters for Robust EEG Single-Trial Analysis}},
url = {http://ieeexplore.ieee.org/document/4408441/},
volume = {25},
year = {2008}
} L. C. Parra, C. D. Spence, A. D. Gerson, and P. Sajda, “Recipes for the linear analysis of EEG,” Neuroimage, vol. 28, iss. 2, p. 326–341, 2005.
[Bibtex]
@article{Parra2005,
abstract = {In this paper, we describe a simple set of “recipes” for the analysis of high spatial density EEG. We focus on a linear integration of multiple channels for extracting individual components without making any spatial or anatomical modeling assumptions, instead requiring particular statistical properties such as maximum difference, maximum power, or statistical independence. We demonstrate how corresponding algorithms, for example, linear discriminant analysis, principal component analysis and independent component analysis, can be used to remove eye-motion artifacts, extract strong evoked responses, and decompose temporally overlapping components. The general approach is shown to be consistent with the underlying physics of EEG, which specifies a linear mixing model of the underlying neural and non-neural current sources.},
author = {Parra, Lucas C. and Spence, Clay D. and Gerson, Adam D. and Sajda, Paul},
doi = {10.1016/j.neuroimage.2005.05.032},
issn = {10538119},
journal = {NeuroImage},
month = {nov},
number = {2},
pages = {326--341},
}