1 Introduction

Brain–computer interface (BCI) systems can straightly transform brain signals such as electroencephalogram (EEG) to control external devices without the involvement of peripheral nerves or muscles (Makand and Wolpaw, 2009). BCIs provide a new communication/control channel for patients who have lost normal communication/control abilities due to severe motor impairments, which have gained interest in neuroscience and rehabilitation engineering (Birbaumerand Cohen, 2007). Motor imagery (MI) is a mental representation of motor behavior. The tasks associated with motor imagery can bring variations in the rhythmic activities of the brain electrophysiological signals which can be expressed as event-related desynchronization /synchronization (ERD/ERS) phenomenon (Pfurtscheller 1977, 1992), specifically in mu (8–12Hz) and beta rhythm (13–30Hz) (McFarland et al., 2000; Pfurtscheller et al., 2006). The corresponding differences in EEG signals can be transformed to control commands. Such MI-based BCIs are usually more convenient to use than stimuli-based BCIs since it can be operated without external stimuli (Qiu et al., 2016). It has shown promising application values in medical rehabilitation (post-stroke rehabilitation), auxiliary control (e.g., neuroprosthesis control (Müller-Putz et al., 2005), 2D cursor control (Long et al., 2012), wheelchair control (Tang et al., 2018), etc.), and social entertainment (Folgieri and Zampolin, 2014; van de Laar etal., 2013). However, it has reported that many MI-based BCIs users cannot obtain sufficient accuracy of control commands (Guger et al., 2003). One of the reasons is that it is hard to accurately extract the features about MI. Thus, an urgent problem in MI-based BCIs is how to further improve the feature extraction performance.

Various feature extraction methods have been proposed, such as adaptive autoregressive model (ARR) (Schlögl et al., 1997), wavelet transform (WT) (Hsu and Sun, 2009), wavelet packet transform (WPT) (Zhou and Wan, 2012), and common spatial pattern (CSP) (Yang and Wu, 2014). Particularly, CSP is always regarded as one of highly successful algorithms due to its good performance in extracting spatial domain features (Blankertz et al., 2008), which can extract task-related signal components from multi-channel EEG data and suppress uncorrelated signal components (Ramoser et al., 2000). Commonly, a fixed starting point and length of EEG signals have been used to extract the MI features in the majority of state-of-the-art MI-based BCIs (Qiu et al., 2016; Ang et al., 2012; Rodriguez-Bermudez et al., 2013). However, considering it is hard to determine certainly when participants begin to perform MI task and how long it lasts, and fixed time window method may lead to low classification accuracy because of deficient information or interference from invalid data. To address this issue, recently, a correlation-based time window selection (CTWS) algorithm has been proposed and achieved better classification accuracy than fixed time window method (Feng et al., 2018). In CTWS, the optimized starting point of MI task-relevant signals was determined based on correlation analysis. However, CTWS using a fixed window length did not consider the influence of window length to MI feature extraction.

In this paper, an optimized correlation-based time window selection (OCT-

WS) algorithm is proposed to select the starting point and length of MI task-relevant time windows simultaneously. In the proposed method, correlation analysis and performance evaluation are used to determine the starting point and length of time windows. The common spatial pattern (CSP) method is used to extract MI features, and a support vector machine (SVM) with linear kernel is then trained on the selected features to classify MI tasks. The proposed method is validated on a public EEG dataset (BCI Competition IV Dataset I) and compared with fixed time window length-based CSP and CTWS. Experimental results show that OCTWS achieves more superior classification performance.

The remainder of this paper is organized as follows: Sect. 2 describes the materials and methods in details; Sect. 3 shows the experimental results; Sect. 4 gives the discussion; and finally, Sect. 5 serves as conclusion.

2 Materials and Methods

2.1 Materials

The Dataset I from BCI Competition IV was used to evaluate the performance of proposed method. This dataset consists of EEG signals based on MI, obtained from seven subjects (numbered by S1–S7), recorded via 59 electrodes with 100 Hz sampling frequency. The timing scheme of single trial is shown in Fig. 1 where each trial lasts for 8 s, including three phases: in preparation phase (0–2 s), a fixation cross would show on the monitor to remind the subject focusing attention to the task, then in MI task phase (2–6 s), the subject was asked to perform corresponding MI task (Left hand/Right hand/Foot) according to the cue, finally, in rest period (6–8 s), a black screen would appear on the monitor. More details about the dataset can be found at Web site: https://www.bbci.de/competition/iv/. In this paper, only the calibration data in total of 200 trials for each subject were used to evaluate the algorithms.

Fig. 1
figure 1

Timing scheme of single MI trial

2.2 Methods

CTWS is an effective method for selecting trial-specific time window for each subject that can facilitate effective feature extraction. The main principle of CTWS is to iteratively adjust the time window of the training data to find the optimized reference signals based on the maximum correlation between current reference signals and EEG signals with different starting points, as described in Eqs. (1) and (2).

$$\begin{aligned} {\mathrm{cov}}(R_{ij},C_{ij})=\frac{1}{N_t} \sum _{t-1}^{N_t}(R_i(t)-\bar{R}_i(t))(C_i(t)-\bar{C}_i(t)),\quad i=1,2;j=C3,C4 \end{aligned}$$
(1)
$$\begin{aligned} V =\mathop {{\mathrm{argmax}}}\limits _{k}({\mathrm{cov}}(R_{i3},C_{i3}^k))+{\mathrm{cov}}(R_{i4},C_{i4}^k), k=1,2, \ldots ,n \end{aligned}$$
(2)

where t is the index of current point in the time window with the length of Nt, i is the index of class, j is the index of channel (channel C3 and C4 were selected), R is the reference signal, C is the signal of current sample, \(\overline{{\boldsymbol{R}}}\) and \(\overline{{\boldsymbol{C}}}\) are the average value of R and C over t; V represents the time window with maximum average correlation value, and n is the number of generated new time windows.

After obtaining the optimized reference signals, the starting points of the time windows for both training and test samples are adjusted using correlation analysis by Eqs. (1) and (2). Note that, in CTWS, only the starting point of the time window is adjusted, while the length of the time window is not considered.

As for the improvement of traditional CTWS, the proposed OCTWS aims to select optimal starting point and length of time window simultaneously. The CTWS is used to determine the starting point of the time window, and a wrapper-based feature selection method (Foitong et al. 2012) is used to select the best length of the time window. The CSP and SVM are used for feature extraction and classification, respectively. The procedure of OCTWS can be described as follows:

(1) Firstly, divide the preprocessed EEG samples (\({\boldsymbol{X}}\in \mathbb {R}^{{\boldsymbol{M}}}\times {\boldsymbol{N}}\times {\boldsymbol{K}}\), where M, N, and K denote the number of channels, sampling points, and trials, respectively) into two parts (training samples and test samples).

(2) Next, for the training samples, set the current window length to the minimum window length (1000 ms was selected in this paper), and perform the CTWS to obtain the optimized reference signals (OR\(_1\) and OR\(_2\)) of each class; then, adjust the start time point for test samples with OR\(_1\) and OR\(_2\) based on Eqs. (1), and calculate the test classification accuracy.

(3) Then, update the length of the time window (increased by a window change step, 200 ms was used in this paper), and repeat (1) and (2) until the current window length reaches the maximum window length (3000 ms was selected in this paper). If the new classification accuracy is higher than the previous classification accuracy, replace OR\(_1\) and OR\(_1\) with the new reference signals (NOR\(_1\) and NOR\(_2\)). The process above was repeated ten times with a tenfold cross-validation scheme to evaluate the average classification accuracies.

(4) Finally, select the OR\(_1\) and OR\(_2\) corresponding to the highest average classification accuracy as the optimized reference signals NOR\(_1\) and NOR\(_2\), which are then employed to select the optimal time windows for each raw sample using correlation analysis through Eqs. (1) and (2).

The pseudocode of OCTWS is given in Table 1.

Table 1 Pseudocode of OCTWS

3 Results

The proposed OCTWS was compared with traditional CSP and CTWS with fixed window length. For CSP and CTWS, window length is set to 2000 ms according to (Feng et al. 2018). For all three methods, all samples were filtered by a fifth order Butterworth filter (frequency band ranging from 8 to 30 Hz).

In order to test the performance of the proposed OCTWS, it was combined with CSP (OCTWS + CSP) to extract feature on BCI Competition IV Dataset I. The obtained feature distributions by CTWS + CSP and OCTWS + CSP are shown in Fig. 2, respectively, for seven subjects. The blue and red circles represent the two different feature classes. It can be clearly observed that compared to the traditional CTWS combined with CSP (CTWS+CSP) method, the OCTWS+CSP method improves the distinguishing degree of the two classes of EEG signals for each subject. Especially, subject 3 and subject 6 are of most obvious. Therefore, it qualitatively shows that the proposed OCTWS method provides a better effect on the extraction of EEG features than the CTWS method, which will promote the pattern classification of MI-based EEG signals.

Fig. 2
figure 2

Feature distribution of each class extracted by CTWS + CSP and OCTWS + CSP for seven subjects. a Five subjects tested on right and left hand. b Two subjects tested on right hand and foot

The above results of feature distribution indicate that the optimization of time window length is also an important factor for MI-based BCIs. Figure  3 presents two examples to show the effects of varying time window length (from 1000 to 3000 ms) on the average classification accuracy in a tenfold cross-validation for subject 3 (S3) and 4 (S4). It can be seen that the average accuracy varies with the length of time, and the optimal time window length is subject specific, for S3 is 1600 ms and for S4 is 2600 ms.

Fig. 3
figure 3

Effects of varying time window length on the average classification accuracy for subject 3 (S3) and subject 4 (S4)

To quantitatively evaluate the performance of the proposed OCTWS algorithm for time window length optimization, we compared the classification accuracy of OCTWS + CSP, CTWS + CSP, and CSP method using SVM with linear kernel as the classifier (Feng et al. 2018). A tenfold cross-validation is implemented to evaluate the classification performance. The experimental results of classification accuracy of OCTWS+CSP, CTWS+CSP, and CSP are given in Table 2, for seven subjects. The first obvious finding is that the classification accuracy of CTWS + CSP (82.93% ± 11.12%) and OCTWS + CSP (88.21% ± 6.55%) significantly outperform CSP (66.21% ± 18.56%) with fixed window. Moreover, the average classification accuracy of OCTWS+CSP method has improved by 5.28% compared to CTWS + CSP method (82.93% versus 88.21%). The comparison of classification results further verifies the superior performance of OCTWS in obtaining the optimal starting point and length of time window in MI-based BCI system.

Table 2 Classification accuracy (%) of CSP, CTWS + CSP, and OCTWS + CSP, for seven subjects

4 Discussion

For motor imagery (MI)-based BCI systems, extracting the features matching MI tasks is a key link to improve the recognition rate. CSP is an effective feature extraction algorithm, and some improved CSP algorithms have been proposed in recent studies. In particular, the time window selection of EEG signals has an important influence on the feature extraction based on CSP ((Feng et al., 2018)). The study based on CTWS algorithm has indicated that the starting point time window varies from one trail to the next among any one individual during motor imagery. However, the length is also a major factor in determining the time window. As shown in Fig. 3, the classification accuracy changed as time window length varied for different subjects. Therefore, it is necessary to select the starting point and length of time window at the same time before feature extraction.

In this study, the proposed OCTWS algorithm further considers the length of time window based on traditional CTWS algorithm (only considering the starting point of time window). It has confirmed that CTWS is more superior in feature extraction than CSP in BCI Computation IV Datasets. But as shown in Fig. 2, we can find that the distribution of MI feature based on OCTWS algorithm has once again improved. So overall, the proposed OCTWS algorithm is more conducive to feature extraction than CSP and CTWS algorithms.

As given in Table 2, the proposed OCTW algorithm also brings about a higher classification accuracy compared to CSP and CTWS algorithm, which evaluate the effectiveness and practicality. Of course, in both OCTWS and CTWS algorithms, only the time window of MI is selected. So in future work, we can further consider the frequency band selection of EEG signals in order to boost the performance of OCTWS algorithm.

5 Conclusion

In this paper, we have proposed an optimized correlation-based time window selection (OCTWS) algorithm for further improving the classification performance of traditional CTWS which can select optimal starting point and length of time window simultaneously. We incorporated CSP and SVM into the structure of the OCTWS algorithm for feature extraction and classification on BCI Competition IV Dataset I. The experimental results demonstrated that the optimization of time window length was also an important factor for MI-based BCIs besides starting time point. The features extracted by proposed OCTWS algorithm were easier to classify and could also achieve better classification performance compared to the traditional CTWS.