# Common spatial pattern

Common spatial pattern (CSP) is a mathematical procedure used in signal processing for separating a multivariate signal into additive subcomponents which have maximum differences in variance between two windows.[1]

## Details

Let ${\displaystyle \mathbf {X} _{1}}$ of size ${\displaystyle (n,t_{1})}$ and ${\displaystyle \mathbf {X} _{2}}$ of size ${\displaystyle (n,t_{2})}$ be two windows of a multivariate signal, where ${\displaystyle n}$ is the number of signals and ${\displaystyle t_{1}}$ and ${\displaystyle t_{2}}$ are the respective number of samples.

The CSP algorithm determines the component ${\displaystyle \mathbf {w} ^{\text{T}}}$ such that the ratio of variance (or second-order moment) is maximized between the two windows:

${\displaystyle \mathbf {w} ={\arg \max }_{\mathbf {w} }{\frac {\left\|\mathbf {wX} _{1}\right\|^{2}}{\left\|\mathbf {wX} _{2}\right\|^{2}}}}$

The solution is given by computing the two covariance matrices:

${\displaystyle \mathbf {R} _{1}={\frac {\mathbf {X} _{1}\mathbf {X} _{1}^{\text{T}}}{t_{1}}}}$
${\displaystyle \mathbf {R} _{2}={\frac {\mathbf {X} _{2}\mathbf {X} _{2}^{\text{T}}}{t_{2}}}}$

Then, the simultaneous diagonalization of those two matrices (also called generalized eigenvalue decomposition) is realized. We find the matrix of eigenvectors ${\displaystyle \mathbf {P} ={\begin{bmatrix}\mathbf {p} _{1}&\cdots &\mathbf {p} _{n}\end{bmatrix}}}$ and the diagonal matrix ${\displaystyle \mathbf {D} }$ of eigenvalues ${\displaystyle \{\lambda _{1},\cdots ,\lambda _{n}\}}$ sorted by decreasing order such that:

${\displaystyle \mathbf {P} ^{-1}\mathbf {R} _{1}\mathbf {P} =\mathbf {D} }$

and

${\displaystyle \mathbf {P} ^{-1}\mathbf {R} _{2}\mathbf {P} =\mathbf {I} _{n}}$

with ${\displaystyle \mathbf {I} _{n}}$ the identity matrix.

This is equivalent to the eigendecomposition of ${\displaystyle \mathbf {R} _{2}^{-1}\mathbf {R} _{1}}$:

${\displaystyle \mathbf {R} _{2}^{-1}\mathbf {R} _{1}=\mathbf {PDP} ^{-1}}$
${\displaystyle \mathbf {w} ^{\text{T}}}$ will correspond to the first column of ${\displaystyle \mathbf {P} }$:
${\displaystyle \mathbf {w} =\mathbf {p} _{1}^{\text{T}}}$

## Discussion

### Relation between variance ratio and eigenvalue

The eigenvectors composing ${\displaystyle \mathbf {P} }$ are components with variance ratio between the two windows equal to their corresponding eigenvalue:

${\displaystyle \mathbf {\lambda } _{i}={\frac {\left\|\mathbf {p} _{i}^{\text{T}}\mathbf {X} _{1}\right\|^{2}}{\left\|\mathbf {p} _{i}^{\text{T}}\mathbf {X} _{2}\right\|^{2}}}}$

### Other components

The vectorial subspace ${\displaystyle E_{i}}$ generated by the ${\displaystyle i}$ first eigenvectors ${\displaystyle {\begin{bmatrix}\mathbf {p} _{1}&\cdots &\mathbf {p} _{i}\end{bmatrix}}}$ will be the subspace maximizing the variance ratio of all components belonging to it:

${\displaystyle E_{i}={\arg \max }_{E}{\begin{pmatrix}\min _{p\in E}{\frac {\left\|\mathbf {p^{\text{T}}X} _{1}\right\|^{2}}{\left\|\mathbf {p^{\text{T}}X} _{2}\right\|^{2}}}\end{pmatrix}}}$

On the same way, the vectorial subpsace ${\displaystyle F_{j}}$ generated by the ${\displaystyle j}$ last eigenvectors ${\displaystyle {\begin{bmatrix}\mathbf {p} _{n-j+1}&\cdots &\mathbf {p} _{n}\end{bmatrix}}}$ will be the subspace minimizing the variance ratio of all components belonging to it:

${\displaystyle F_{j}={\arg \min }_{F}{\begin{pmatrix}\max _{p\in F}{\frac {\left\|\mathbf {p^{\text{T}}X} _{1}\right\|^{2}}{\left\|\mathbf {p^{\text{T}}X} _{2}\right\|^{2}}}\end{pmatrix}}}$

### Variance or second-order moment

CSP can be applied after a mean subtraction (a.k.a. "mean centering") on signals in order to realize a variance ratio optimization. Otherwise CSP optimizes the ratio of second-order moment.

### Choice of windows X1 and X2

• The standard use consists on choosing the windows to correspond to two periods of time with different activation of sources (e.g. during rest and during a specific task).
• It is also possible to choose the two windows to correspond to two different frequency bands in order to find components with specific frequency pattern.[2] Those frequency bands can be on temporal or on frequential basis. Since the matrix ${\displaystyle \mathbf {P} }$ depends only of the covariance matrices, the same results can be obtained if the processing is applied on the Fourier transform of the signals.
• Y. Wang [3] has proposed a particular choice for the first window ${\displaystyle \mathbf {X} _{1}}$ in order to extract components which have a specific period. ${\displaystyle \mathbf {X} _{1}}$ was the mean of the different periods for the examined signals.
• If there is only one window, ${\displaystyle \mathbf {R} _{2}}$ can be considered as the identity matrix and then CSP corresponds to Principal component analysis.

## Applications

This method can be applied to several multivariate signal but it seems that most works on it concern electroencephalographic signals.

Particularly, the method is mostly used on brain–computer interface in order to retrieve the component signal which best transduce the cerebral activity for a specific task (e.g. hand movement).[4]

It can also be used to separate artifacts from electroencephalographics signals.[2]

An adaptation of the common spatial pattern for event-related potentials has been formalized in.[5]