**2.3 Extraction of EEG trials**

Extraction of EEG trials means the process of finding trial of interest of EEG signals by segment the signal according to the event associated with the dataset.

Events gives the time that the MI trail starts and ends to facilitate extraction of the task and the segment number, also the dataset that gives the artifact in each trial to eliminate it if need, in our case we need a clear signal so we eliminate these artifacts for the subjects. The proposed system segments the signals of each channel (C3, C4, Cz), these channels are the most effected by MI tasks. Also, because we use two classes only

(left and right hand) the other two classes (feet and tongue) eliminated and their corresponding trials also eliminated. **Figure 2** shows the signal of C3 channel before and after segmentation for three trials.

**Figure 2.**

*(a) Signal three channels before trials extraction; (b) signal after trials extraction (c) show the deference between original signal and extracted signal for three trial.*

### **2.4 Artifact's reduction**

Artifacts can be defining as the unwanted signals that appear in EEG signals, they can be caused from various origins including body or eye movement, heart beating blinking, or frequency from utility, which is (50 Hz in Europe or 60 Hz in the United States) [23]. The utility frequency was removed already by applying notch filter while eye artifacts are left due to possibility of artifacts removal algorithms testing [22].

To handle eye artifact, there are three main approaches: avoidance, rejection, and removal [23].

For artifacts avoidance can be by asking the user to avoid movement during the recording that causes EEG artifact, which decreases the artifact's number, but eye movement and blinks cannot be avoided.

Another way is to reject all corrupted trials by artifacts, which can automatically have done or manually. Manually can be done through visual examination, as the corrupted trials marked if they are corrupted or not by an expert. An algorithm is implemented in automatic artifact rejection, that can determine if artifacts corrupt a trial or not, and artifact rejection reduces the size of the training set. Last, is artifact removal, in order to remove the EEG signal artifact, some algorithms are used that leave the desired brain-originated signal intact.

#### **2.5 Bandpass filtering**

After applying segmentation algorithm to segment signals of each channel into 3 s sub signal according to the event associated with the data set then remove all marked artifact trials, **Figure 3** shows EEG signal for three trials after applying bandpass filter, the signal is filtered using a bandpass filter designed for a given frequency band. Using, for each channel, a 4th order Butterworth infinite impulse response (IIR) filter, IIRs are used to change the frequency component of a time signal by reducing or amplifying a particular frequency. This filter is used to pass only the band-limited portion of frequency content.

**Figure 3.** *Signal of C3 channel after applying bandpass filter between (8–30 HZ).*
