**3. Discrete wavelet transform**

The concept of wavelet was proposed by Jean Morlet in 1981. In this chapter, The Daubechies wavelet, proposed by Dr Daubechies in 1988 [20], was used to extract the features from EEG signals. It is often used in signal compression, digital signal analysis and noise filtering, and so on. In Daubechies wavelet, several series db wavelets can get better performance in signal analysis. In this chapter, db4 wavelets were used to extract main features from EEG signals. Multiresolution analysis in the WT algorithm was proposed by Mallat [21] in 1989. When a signal resolution has a high-degree variation in a proper area, it is difficult to get detailed features while the multiresolution strategy can decompose the lower layer signal to get more information. Therefore, the decomposed low-frequency signal can be decomposed continuously to display more features. However, the decomposed iterations of the signal are so many to make the number of samples so few that results in less obvious characteristics of the signal.

Therefore, the number of signal decomposition layer is limited. In the wavelet decomposition, the original signal is input to a low-pass filter g[k] and a high-pass filter h[k], respectively. The low-pass filter retains the consistency of the original signal, and the high-pass filter reserves the variability of the original data. Discrete wavelet transform can be combined with wavelet function and scale function. In the low-frequency part, it has a high frequency resolution and low temporal resolution, while there was a lower frequency resolution and a higher time resolution in the high-frequency part. The discrete wavelet transform decomposition and recombination is shown in **Figure 3** and the multiresolution analysis in the WT is shown in **Figure 4**.

The left half is wavelet decomposition, after the high-pass and low-pass decomposition and then downsampling to get two groups of detailed signal and the approximate signal. The right half in **Figure 3**, the decomposition of the series for the rise of sampling, and then through the high-frequency synthesis filter and low-frequency synthesis filter can be reconstructed.

**Figure 3.** Discrete wavelet decomposition and reconstruction.

**Figure 2.** Locations C3, C4, and Cz are used in the 10–20 system.

**2. System architecture**

18 Evolving BCI Therapy - Engaging Brain State Dynamics

The proposed BCI system is integrated as EEG signals extracting subsystem through the Emotiv EPOC chip, g.SAHARAbox system, and g.SAHARA electrodes. The g.SAHARAbox system and g.SAHARA electrodes are shown in **Figure 1**. The system's electrodes are dry manner and nonintrusive conductive system that allows 16 EEG channels to be embedded into the input of EPOC chip at the same time. The electrode locations C3, C4, and Cz based on the international 10–20 system, shown in **Figure 2**, were used to extract EEG signals, while locations A1 and A2 were used as reference points. For the MI-EEG signals, two motion-imagination brain signals were recognized, respectively. One is "imagining right-hand action" and the other is "imagining left-hand action." In order to establish a sampling model, we captured 9-s EEG signals for every imagining action from every channel. And, the extracted brainwave signal is transformed through DWT to obtain the spectrums in frequency domain. Then, the frequency feature was calculated and classified into different categories by using LSTM and GRNN.

**Figure 1.** The subsystems in the proposed BCI: (a) g.SAHARAbox system and (b) g.SAHARA electrodes.

**Figure 4.** Discrete wavelet multiresolution decomposition.

#### **4. LSTM-based recurrent network**

RNNs are popular networks that have shown great promise in many sequential tasks. RNNs are called recurrent because they perform the same task for every element of a sequence, with the output being depended on the previous states. Recently, several researchers have developed more sophisticated types of RNNs to deal with some of the shortcomings of the vanilla RNN model. Training an RNN is similar to training a traditional neural network (TNN). Because RNNs trained by TNN's style have difficulties in learning long-term dependencies due to the vanishing and exploding gradient problem. LSTMs do not have a fundamentally different architecture from RNNs, but they use a different function to calculate the states in hidden layer. The memory in LSTMs is called cells and can be thought as black boxes that take as input the previous state and current input. Internally, these cells decide what to be kept in (and what to be erased from) memory. They then combine the previous state, the current memory, and the input. It turns out that these types of units are very efficient at capturing long-term dependencies. In this chapter, a peephole-connection LSTM, proposed by Gers and Schmidhuber [22], is applied and shown in **Figure 5**. In **Figure 5**, the state of forget gate *f*(*t*), shown as in Eq. (1), is decided by a sigmoid function from the previous cell state *Ct*−<sup>1</sup> , the previous hidden layer state *ht*−*<sup>i</sup>* , and input data *xt* .

$$f\_t = \sigma(w\_{c\_\ell} \mathbf{C}\_{t-1} + w\_{x\_\ell} \mathbf{x}\_t + w\_{h\_\ell} h\_{t-\ell}) + b\_f \tag{1}$$

From **Figure 6**, we can find the cell state shown as Eq. (2), calculated with the previous cell

*<sup>t</sup>* ∗ *Ct*−<sup>1</sup> + *i*

*C*˜ *<sup>t</sup>* = tanh(*wx*,*<sup>c</sup>* ∗ *xt* + *wh*,*<sup>c</sup>* ∗ *ht*−<sup>1</sup> + *bc*) (4)

*ot* = *σ*(*wc*,*<sup>o</sup>* ∗ *Ct* + *wx*,*<sup>o</sup>* ∗ *xt* + *wh*,*<sup>o</sup>* ∗ *ht*−<sup>1</sup> + *bo*) (5)

The GRNN was proposed by Cho et al. [19] in order to make each recurrent unit to extract dependencies of different timescales adaptively. The GRNN, shown in **Figure 7**, has gating units that modulate the flow of information inside the unit like the LSTM unit but without

having a separate memory cell. The parameters in the GRNN are updated as follows:

t anh(C*<sup>t</sup>*

and hidden-layer state ht

*<sup>t</sup>* = *σ*(*Wc*,*<sup>i</sup>* ∗ *Ct*−<sup>1</sup> + *wx*,*<sup>i</sup>* ∗ *xt* + *wh*,*<sup>i</sup>* ∗ *ht*−<sup>1</sup> + *bi*) (3)

A Motor-Imagery BCI System Based on Deep Learning Networks and Its Applications

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

21

*<sup>t</sup> C*˜ *<sup>t</sup>* (2)

are computed by Eq. (5) and Eq. (6),

) (6)

state *Ct*−<sup>1</sup>

where

and

respectively.

, forget-gate state *f*

**Figure 6.** The proposed BCI control system.

*i*

Finally, the output-gate state O<sup>t</sup>

*ht* = *o <sup>t</sup>*

**5. Gated recurrent neural network (GRNN)**

*t* , and *i t* ∗ *C*˜ *t* .

C*<sup>t</sup>* = *f*

**Figure 5.** The block diagram of LSTM.

A Motor-Imagery BCI System Based on Deep Learning Networks and Its Applications http://dx.doi.org/10.5772/intechopen.75009 21

**Figure 6.** The proposed BCI control system.

From **Figure 6**, we can find the cell state shown as Eq. (2), calculated with the previous cell state *Ct*−<sup>1</sup> , forget-gate state *f t* , and *i t* ∗ *C*˜ *t* .

$$\mathbf{C}\_{t} = f\_{t} \* \mathbf{C}\_{t-1} + \mathbf{i}\_{t} \mathbf{\bar{C}}\_{t} \tag{2}$$

where

$$\mathbf{i}\_{t} = \sigma(\mathbf{W}\_{c,l} \* \mathbf{C}\_{t-1} \* \mathbf{w}\_{x,l} \* \mathbf{x}\_{t} \* \mathbf{w}\_{h,l} \* \mathbf{h}\_{t-1} \* \mathbf{b}\_{l})\tag{3}$$

and

**Figure 5.** The block diagram of LSTM.

tion from the previous cell state *Ct*−<sup>1</sup>

*f*

**4. LSTM-based recurrent network**

20 Evolving BCI Therapy - Engaging Brain State Dynamics

**Figure 4.** Discrete wavelet multiresolution decomposition.

RNNs are popular networks that have shown great promise in many sequential tasks. RNNs are called recurrent because they perform the same task for every element of a sequence, with the output being depended on the previous states. Recently, several researchers have developed more sophisticated types of RNNs to deal with some of the shortcomings of the vanilla RNN model. Training an RNN is similar to training a traditional neural network (TNN). Because RNNs trained by TNN's style have difficulties in learning long-term dependencies due to the vanishing and exploding gradient problem. LSTMs do not have a fundamentally different architecture from RNNs, but they use a different function to calculate the states in hidden layer. The memory in LSTMs is called cells and can be thought as black boxes that take as input the previous state and current input. Internally, these cells decide what to be kept in (and what to be erased from) memory. They then combine the previous state, the current memory, and the input. It turns out that these types of units are very efficient at capturing long-term dependencies. In this chapter, a peephole-connection LSTM, proposed by Gers and Schmidhuber [22], is applied and shown in **Figure 5**. In **Figure 5**, the state of forget gate *f*(*t*), shown as in Eq. (1), is decided by a sigmoid func-

, the previous hidden layer state *ht*−*<sup>i</sup>*

*<sup>t</sup>* = *σ*(*wc*,*<sup>f</sup> Ct*−<sup>1</sup> + *wx*,*<sup>f</sup> xt* + *wh*,*<sup>f</sup> ht*−*<sup>i</sup>*) + *bf* (1)

, and input data *xt*

.

$$\bar{\mathbf{C}}\_{t} = \tanh\left(\mathbf{w}\_{\mathbf{x},\boldsymbol{\epsilon}} \ast \mathbf{x}\_{t} \ast \mathbf{w}\_{h,\boldsymbol{\epsilon}} \ast h\_{t+1} \ast b\_{\boldsymbol{\epsilon}}\right) \tag{4}$$

Finally, the output-gate state O<sup>t</sup> and hidden-layer state ht are computed by Eq. (5) and Eq. (6), respectively.

$$o\_t = \sigma(w\_{c,o} \* C\_t + \mathfrak{w}\_{x,o} \* \mathfrak{x}\_t + \mathfrak{w}\_{h,o} \* h\_{t-1} + b\_o) \tag{5}$$

$$h\_i = o\_i \text{t} \text{anh} \langle \mathcal{C}\_i \rangle \tag{6}$$
