**Algorithm I.**

Step 1. Dividing (windowing) the original EEG signals into several intervals;

Step 2. Executing discrete Fourier transformation (DFT) in different intervals and normalizing the transformation results;

Step 3. Calculating the average power spectrum of banded (limited) frequencies in each phases;

Step 4. Finding a special (feature) interval, in which average power spectrum is the most different one from its neighborhoods;

Step 5. The power spectrum of FFT in the windowed frequencies and their average values are used as the feature data for classifiers.

A sample of the first processing (Step 1) is shown in **Figure 4**. In **Figure 4**, an EEG signal, which is a time series data (the potential of an electrode) of one channel, is divided into five intervals. DFT is executed in each interval at Step 2, and as a sample, the result of the second intervals (at time 30–60) is shown in **Figure 5**.

**Figure 1.** Overlapping of the probabilities of two classes of data.

**Figure 2.** AUC of ROC curve.

The normalization of DFT results is given by a nonlinear function [4].

**Figure 4.** A sample of Step 1 processing: dividing EEG signals into several intervals.

Mental Task Recognition by EEG Signals: A Novel Approach with ROC Analysis

http://dx.doi.org/10.5772/intechopen.71743

69

where *x*(*n*) is the original DFT power spectrum of frequency *n*.

*<sup>x</sup>*(*n*) <sup>=</sup> log(*x*(*n*) <sup>−</sup> max(*x*(*n*)) <sup>+</sup> 1) \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ log(max(*x*(*n*)) <sup>−</sup> min(*x*(*n*)) <sup>+</sup> 1) (1)

**Figure 5.** A sample of Step 2 processing: DFT and normalizing results of an interval of EEG time series data.

**Figure 3.** Flow chart of EEG signal recognition in [8].

**Figure 4.** A sample of Step 1 processing: dividing EEG signals into several intervals.

**Figure 2.** AUC of ROC curve.

**Figure 1.** Overlapping of the probabilities of two classes of data.

68 Human-Robot Interaction - Theory and Application

**Figure 3.** Flow chart of EEG signal recognition in [8].

EEG Signals

Windowing

Averaging

Finding Feature Window

Classifiers

Recognized mental tasks

DFT

**Figure 5.** A sample of Step 2 processing: DFT and normalizing results of an interval of EEG time series data.

The normalization of DFT results is given by a nonlinear function [4].

The normalization of DFT results is given by a nonlinear function [4].

$$\mathbf{x}(n) = \frac{\log(\mathbf{x}(n) - \max(\mathbf{x}(n)) + 1)}{\log(\max(\mathbf{x}(n)) - \min(\mathbf{x}(n)) + 1)}\tag{1}$$

where *x*(*n*) is the original DFT power spectrum of frequency *n*.

This nonlinear normalization reduces the vibration of time series of DFT results, avoiding the overfitting when classifiers are designed.

A frequency interval, which has distinguished power spectra for a certain mental task is chosen by Eq. (2).

$$\arg\max\_{p} L(p) = \sum\_{h=h\_{\nu}}^{h=h\_{\nu}} |\mid F\_{(p+1)h} - F\_{ph}\ |\tag{2}$$

**Figures 7**–**9** showed a sample of the processing. In **Figure 7**, a raw EEG signal and its FFT result are shown. Note that the number of horizontal axis indicates the order of frequencies, and the value of vertical axis is the power spectrum. In **Figure 8**, the distribution of the power

EEG Signals

Mental Task Recognition by EEG Signals: A Novel Approach with ROC Analysis

http://dx.doi.org/10.5772/intechopen.71743

71

FFT

AUC of FFT

Select Frequencies with High AUC

Obtain Power Spectra of Selected Frequencies

Classifiers

Recognized mental tasks

**Figure 7.** A raw EEG signal (left) and its FFT results (right).

**Figure 6.** Flow chart of the EEG signal classification using ROC analysis.

where *p* = 1, 2, …, *P* is the number of intervals, *Fph* is the power spectrum on the frequency, *h* = *hlow, hlow* <sup>+</sup> <sup>1</sup> , …, *hup* is the frequency, *hlow* and *hup* are bands of feature frequencies of mental tasks and they were 4 and 45 Hz, respectively in our experiments.

For ROC analysis, it gives a measure of the difference between two probability distributions, it is validly used to find the discriminant features for EEG signal classification. In [13], Nguyen et al. utilized the AUC of ROC curve to select the elite wavelet coefficients, and in [9], we adopted an algorithm that using high AUC values to select metal task-related frequencies of EEG signals in different channels, respectively, and using the power spectrum of these frequencies as discriminant features for various classifiers such as SVM, ANN [including multi-layer perceptron (MLP), and deep neural networks (DNN)], k-nearest neighbor, decision tree (DT), and so on. The discriminant feature extraction method using ROC analysis is given by **Algorithm II**.

## **Algorithm II.**

Let the input signals be *xkc*, *m*, *<sup>n</sup>* (*c* = 1 or 2, *k* = 1, 2, …, *K*), where *k* indicates the *k*th EEG signal of a set of EEG data, and *c* indicates the class of mental task, *m* indicates the channel number, and *n* is the time of signal.

Step 1. Perform FFT to all the EEG signals *xkc*, *m*, *<sup>n</sup>* and let the result be power spectrum *Em*, *<sup>p</sup>* (*p* = 1, 2, …, *P*) corresponding to frequency *Fkc*, *m*, *p*, where *p* indicates the order number of frequencies.

Step 2. Obtain *Pk*1, *m*, *<sup>p</sup>* and *Pk*2, *m*, *<sup>p</sup>* , which are two probability density functions of *Fkc*, *m*, *<sup>p</sup>* at p frequency, where class c = 1 and 2 of K signals of channel m.

Step 3. Calculate the ROC curve and its AUC *Am*, *<sup>p</sup>* of *Pk*1, *m*, *<sup>p</sup>* and *Pk*2, *m*, *<sup>p</sup>* .

Step 4. Repeat Step 2 and Step 3 on all channels, a set AUCm, n of frequency p in channel m is obtained.

Step 5. Find P points of frequencies, in which *Am*, *<sup>p</sup>* is high.

Step 6. Power spectrum *Em*, *<sup>p</sup>* (p = 1, 2, …, P) of the unknown EEG signal are used as input feature vector of a classifier.

The main difference between **Algorithm I** and **II** is that the power spectra in a special interval of frequencies, which is mostly related to an event of brain activity, are chosen in the former, meanwhile the power spectra of special frequencies chosen by high AUC of ROC are chosen as discriminant features in the later algorithm. The flow chart of EEG signal classification using ROC analysis is depicted in **Figure 6**.

Mental Task Recognition by EEG Signals: A Novel Approach with ROC Analysis http://dx.doi.org/10.5772/intechopen.71743 71

**Figure 6.** Flow chart of the EEG signal classification using ROC analysis.

This nonlinear normalization reduces the vibration of time series of DFT results, avoiding the

A frequency interval, which has distinguished power spectra for a certain mental task is cho-

where *p* = 1, 2, …, *P* is the number of intervals, *Fph* is the power spectrum on the frequency,

For ROC analysis, it gives a measure of the difference between two probability distributions, it is validly used to find the discriminant features for EEG signal classification. In [13], Nguyen et al. utilized the AUC of ROC curve to select the elite wavelet coefficients, and in [9], we adopted an algorithm that using high AUC values to select metal task-related frequencies of EEG signals in different channels, respectively, and using the power spectrum of these frequencies as discriminant features for various classifiers such as SVM, ANN [including multi-layer perceptron (MLP), and deep neural networks (DNN)], k-nearest neighbor, decision tree (DT), and so on. The discriminant feature extraction method using ROC analysis is

Let the input signals be *xkc*, *m*, *<sup>n</sup>* (*c* = 1 or 2, *k* = 1, 2, …, *K*), where *k* indicates the *k*th EEG signal of a set of EEG data, and *c* indicates the class of mental task, *m* indicates the channel number,

Step 4. Repeat Step 2 and Step 3 on all channels, a set AUCm, n of frequency p in channel m

The main difference between **Algorithm I** and **II** is that the power spectra in a special interval of frequencies, which is mostly related to an event of brain activity, are chosen in the former, meanwhile the power spectra of special frequencies chosen by high AUC of ROC are chosen as discriminant features in the later algorithm. The flow chart of EEG signal classification

, …, *hup* is the frequency, *hlow* and *hup* are bands of feature frequencies of mental

∣ *F*(*p*+1)*<sup>h</sup>* − *Fph* ∣ (2)

and let the result be power spectrum *Em*, *<sup>p</sup>*

and *Pk*2, *m*, *<sup>p</sup>*

, which are two probability density functions of *Fkc*, *m*, *<sup>p</sup>*

(p = 1, 2, …, P) of the unknown EEG signal are used as input

of *Pk*1, *m*, *<sup>p</sup>*

is high.

where *p* indicates the order number of frequencies.

.

(*p* = 1,

at p

*L*(*p*) = ∑ *h*=*hlow h*=*hup*

*p*

tasks and they were 4 and 45 Hz, respectively in our experiments.

overfitting when classifiers are designed.

70 Human-Robot Interaction - Theory and Application

argmax

sen by Eq. (2).

*h* = *hlow, hlow* <sup>+</sup> <sup>1</sup>

given by **Algorithm II**.

and *n* is the time of signal.

Step 2. Obtain *Pk*1, *m*, *<sup>p</sup>*

Step 6. Power spectrum *Em*, *<sup>p</sup>*

feature vector of a classifier.

using ROC analysis is depicted in **Figure 6**.

is obtained.

Step 1. Perform FFT to all the EEG signals *xkc*, *m*, *<sup>n</sup>*

and *Pk*2, *m*, *<sup>p</sup>*

Step 3. Calculate the ROC curve and its AUC *Am*, *<sup>p</sup>*

Step 5. Find P points of frequencies, in which *Am*, *<sup>p</sup>*

frequency, where class c = 1 and 2 of K signals of channel m.

2, …, *P*) corresponding to frequency *Fkc*, *m*, *p*,

**Algorithm II.**

**Figures 7**–**9** showed a sample of the processing. In **Figure 7**, a raw EEG signal and its FFT result are shown. Note that the number of horizontal axis indicates the order of frequencies, and the value of vertical axis is the power spectrum. In **Figure 8**, the distribution of the power

**Figure 7.** A raw EEG signal (left) and its FFT results (right).

**Figure 8.** Calculation of the power spectra distribution (histogram) of each frequency of two classes of EEG signals. Frequency 200 (series number) is illustrated as a sample here.

**3. Experiments**

AUC

of classification, which is given by Eq. (3).

To compare the performance of different feature extract methods for EEG signal classification, experiments with two kinds of EEG data were performed [9]. One was a benchmark data set given by Brain-Computer Interfaces Laboratory, Colorado State University [14, 15], and another was from BCI competition II [16]. Classifiers used in the comparison experiments for different feature extraction methods were kernel SVM, MLP, kNN, deep neural network (DNN), and

**(input of classifiers)**

Mental Task Recognition by EEG Signals: A Novel Approach with ROC Analysis

Threshold of AUC

73

http://dx.doi.org/10.5772/intechopen.71743

The evaluation of the performance of different feature extraction methods uses the accuracy

*Accuracy* <sup>=</sup> \_\_\_\_\_\_\_\_\_\_\_\_ *TP* <sup>+</sup> *TN TP* <sup>+</sup> *TN* <sup>+</sup> *FP* <sup>+</sup> *FN* (3)

DT, in which source coded are in a software package R [17] as shown in **Table 2**.

**Figure 9.** AUC of the power spectra on each frequency of two classes of EEG signals.

**Ordered AUC Number of freq. Power spectrum**

0.695 896 1545.186 0.691 158 10.093 0.688 726 9.535

**Table 1.** A sample of discriminant features extracted by ROC analysis.

spectrum of each frequency is calculated using the labeled samples. For example, there are *K* samples including *N* samples of class A and *K−N* samples of class B as shown in **Figure 8**. AUC of the power spectra on each frequency is shown in **Figure 9**. Additionally, frequencies with high AUC extracted by a threshold line are used as criteria of discriminant feature selection. For example, in the case of three input dimensions for a classifier, the input vector is the power spectra with high AUC of frequencies as shown in **Table 1**.

Mental Task Recognition by EEG Signals: A Novel Approach with ROC Analysis http://dx.doi.org/10.5772/intechopen.71743 73

**Figure 9.** AUC of the power spectra on each frequency of two classes of EEG signals.


**Table 1.** A sample of discriminant features extracted by ROC analysis.

## **3. Experiments**

**Figure 8.** Calculation of the power spectra distribution (histogram) of each frequency of two classes of EEG signals.

spectrum of each frequency is calculated using the labeled samples. For example, there are *K* samples including *N* samples of class A and *K−N* samples of class B as shown in **Figure 8**. AUC of the power spectra on each frequency is shown in **Figure 9**. Additionally, frequencies with high AUC extracted by a threshold line are used as criteria of discriminant feature selection. For example, in the case of three input dimensions for a classifier, the input vector is the

Frequency 200 (series number) is illustrated as a sample here.

72 Human-Robot Interaction - Theory and Application

power spectra with high AUC of frequencies as shown in **Table 1**.

To compare the performance of different feature extract methods for EEG signal classification, experiments with two kinds of EEG data were performed [9]. One was a benchmark data set given by Brain-Computer Interfaces Laboratory, Colorado State University [14, 15], and another was from BCI competition II [16]. Classifiers used in the comparison experiments for different feature extraction methods were kernel SVM, MLP, kNN, deep neural network (DNN), and DT, in which source coded are in a software package R [17] as shown in **Table 2**.

The evaluation of the performance of different feature extraction methods uses the accuracy of classification, which is given by Eq. (3).

Oи сизисисиод, чиши з русито у наф·о):

$$Accuracy = \frac{TP + TN}{TP + TN + FP + FN} \tag{3}$$


**Table 2.** Software R [17] and its function used in the experiment.
