## 2 Materials and Methods
### Feature Extraction and Classification Algorithms  
#### 2.5.1 Common Spatial Patterns  
The CSP is a spatial filtering algorithm specifically designed for binary classification tasks, and it is widely used in the field of brain signal processing. This algorithm effectively extracts spatial distribution features from multichannel EEG data. CSPs have been extensively applied in brain-computer interface systems and other neural signal analysis tasks, demonstrating particularly strong performance in decoding motor imagery, such as hand movement intentions. The core principle of CSPs involves the use of matrix diagonalization techniques to identify an optimal set of spatial filters. These filters are then used to project the EEG data in a way that maximizes the variance difference between two classes. This approach enables the extraction of feature vectors with enhanced class separability. Assume two classes of EEG data, \(X_{1}\) and \(X_{2}\), with each trial having dimensions of N \(\times\) T (number of channels \(\times\) number of time points). By applying Equations (7) and (8) to \(X_{1}\) and \(X_{2}\), the average sample covariance matrices for the two classes, \(\overline{R_{1}}\) and \(\overline{R_{2}}\), can be obtained. \[\overline{R_{1}}=\frac{1}{M_{1}}\sum_{i=1}^{M_{1}}\frac{X_{1,i}X_{1,i}^{T}}{ trace(X_{1,i}X_{1,i}^{T})} \tag{7}\]  
\[\overline{R_{2}}=\frac{1}{M_{2}}\sum_{i=1}^{M_{2}}\frac{X_{2,i}X_{2,i}^{T}}{ trace(X_{2,i}X_{2,i}^{T})} \tag{8}\]  
In these equations, \(M_{1}\) and \(M_{2}\) represent the total number of samples in \(X_{1}\) and \(X_{2}\), respectively. \(X_{1,i}^{T}\) and \(X_{2,i}^{T}\) denote the transpose of the \(i\)-th sample in \(X_{1,i}\) and \(X_{2,i}\), respectively. \(trace(X)\) refers to the sum of the elements along the main diagonal of matrix \(X\). Next, the composite spatial covariance matrix is calculated using Equation (9), and eigenvalue decomposition is performed on the resulting composite covariance matrix \(R\) using Equation (10):  
\[R=\overline{R_{1}}+\overline{R_{2}} \tag{9}\]  
\[R=U\lambda U^{T} \tag{10}\]  
In this equation, \(\lambda\) denotes the diagonal matrix of eigenvalues of the covariance matrix \(R\), \(U\) represents the matrix of corresponding eigenvectors, and \(U^{T}\) is the transpose of \(U\). After obtaining the eigenvalue matrix \(\lambda\) and eigenvector matrix \(U\) through decomposition, the whitening transformation matrix \(P\) is computed as follows:  
\[P=\sqrt{\lambda}U^{T} \tag{11}\]  
The whitening matrix \(P\) is then applied to transform the average covariance matrix \(\overline{R_{1}}\) and \(\overline{R_{2}}\), as follows:  
\[S_{1}=P\overline{R_{1}}P^{T} \tag{12}\]  
\[S_{2}=P\overline{R_{2}}P^{T} \tag{13}\]  
Subsequently, principal component decomposition is performed on \(S_{1}\) and \(S_{2}\). \[S_{1}=B\Lambda_{1}B^{T} \tag{14}\]  
\[S_{2}=B\Lambda_{2}B^{T} \tag{15}\]Using Equations (14) and (15), it can be demonstrated that the eigenvector matrices of \(S_{1}\) and \(S_{2}\) are identical. Under this condition, the eigenvalue matrices of \(S_{1}\) and \(S_{2}\) satisfy the following relationship:  
\[\Lambda_{1}+\Lambda_{2}=I \tag{16}\]  
According to Equation (16), the eigenvalue matrices of \(S_{1}\) and \(S_{2}\) are complementary and sum to the identity matrix. This implies that when an eigenvalue of \(S_{1}\) reaches its maximum, the corresponding eigenvalue of \(S_{2}\) attains its minimum. Therefore, the eigenvalues of \(S_{1}\) are sorted in descending order, while those of \(S_{2}\) are sorted in ascending order. The eigenvectors corresponding to the top mmm largest eigenvalues of \(S_{1}\) and the top mmm smallest eigenvalues of \(S_{2}\) are selected and combined to form \(\hat{B}\). Consequently, the final spatial filter projection matrix \(W\) is obtained as:  
\[\overline{R_{2}}=\frac{1}{M_{2}}\sum_{i=1}^{M_{2}}\frac{X_{2,i}X_{2,i}^{T}}{ trace(X_{2,i}X_{2,i}^{T})} \tag{8}\]0  
Let \(X\) denote the input EEG signal.