# INTRODUCTION # lectroencephalographic (EEG)provides the electrical action potentials produced by cerebral cortex neurons [1]. The ease of use and noninvasive technique gives the power to EEG to be widely used to diagnose brain diseases such as (autismepilepsy-head injury-dementia-brain tumors, etc?). Epilepsy is a type of neurological disease. It is ranked as second most rife neurological disorder in humans, with around 40-50 million people in the world suffer from epilepsy [2]. A seizure is a paroxysmal event happening due to hyper synchronous, excessive neuronal discharges [3]. The scalp EEG is a test used for the clinical diagnoses of Epilepsy [4,5]. Automatic detection of seizure began in the 1970s and various methods addressing this problem have been presented [6]. Ling Guo introduced line length feature extracted from the EEG signal after discrete wavelet transform and utilized the artificial neural network as a classifier [7]. B. Suguna Nanthini et al. [8] perform automatic detection for seizure by using Shannon Entropy. They decomposed the EEG signal and utilized SVM for classification. Manisha Chandani et al. [9] applied DWT for decomposition and two classifiers (SVM and Author ? ?: Biomedical and System Engineering Department, Cairo University, Giza 12613, Egypt. e-mail: sh.elgohary@eng1.cu.edu.eg Multilayer Perceptron Neural network) [8,9]. They represented their detection only on sets Z and S from database which introduced by (Andrzejak et al.) [10]. DWT has been used to decompose each channel signal to sub-bands. Various wavelet types have been employed such as (Daubechies, Haar, Coiflets, and Reverse Bior) with different levels. Moreover, a comparison between the wavelet types will be represented to select the optimum wavelet and level. A distinct technique was used for decomposition as DT-CWT which separates the real and imaginary parts of each signal and decomposes them by different filters. Then, line length was extracted from each sub-band in both cases (DWT and DT-CWT). After signal processing and feature extraction, the features were applied to the machine learning algorithms to classify the signal to normal or abnormal. This work introduced epilepsy classification method with optimum accuracy and execution time. Moreover, detection of the focal area will lead to estimate the location of the epilepsy source. # II. # MATERIAL AND METHODS a) Dataset Description There are two different datasets. The first one which described by Andrzejac et al. [10], is employed to study the classification algorithms and the important features to be extracted. The second data set was used for applying the best technique in epilepsy classification and for localization. The first dataset consists of five sets (Z, O, N, F, and S) each set has recorded from five patients. Each patient has 20 channels sampled at 173.61Hzusing 12-bits resolution. All EEG recording was preprocessed with the same 128 channel amplifier. Number of points in each signal is 4097 points with duration of 23.6 seconds. First set is Z which represented normal EEG with the eye open and taken from scalp. Set O had been recorded from the scalp but with the eye closed. Sets N, F, S were measured via intracranial electrodes. N recorded from the epileptogenic zone but F from the opposite side both at seizure-free interval. Finally, set S was taken from the epileptogenic zone but during seizure activity. The entire five datasets were filtered by filter 0.53-40 Hz band-pass and examined by a physician, as shown in figure 1.The second data set was collected by Warsaw memorial child hospital [12]. It contains records of 23 patients with severe epilepsy, mostly caused by different lesions. The patients aged 1-18 years. EEG was taken by a 10-20 system with 19 electrodes sampled at 250 HZ. The hardware reference was "fpz" channel. Physicians examined each data set recording and put markers at the seizure period. With each patient, there is an MRI image that locate the focal area of epilepsy in the brain. A random EEG signal to patient id "Chimic" shown in figure 2, and the seizure period marked by physicians. # b) Discrete wavelet transforms (DWT) Analysis Recently, a discrete wavelet transform (DWT) widely applied in many engineering fields for solving various real-life problems [11]. DWT equation is shown below [13]: DWT (j,k) = 2 ?j 2 ? ??(??)??( ?? ? 2 ?? ?? 2 ?? ? ?? ) ???? (1) Fig. 2: EEG signals from patient id "Chimic" We used various wavelets techniques such as Daubechies (dB), Haar, Coiflets, and Reverse Bior. Selecting the optimum technique and order is our aim to be the input of the feature extraction stage. The wavelet type evaluation depends on the execution time of signal decomposition and parameters such as (accuracy, specificity, sensitivity) of the classification algorithms. # c) Analysis with double-tree complex wavelet transforms (DT-CWT) DWT has certain limitations, first a small change in input signal will lead to a large change in wavelet coefficients. Second, it has poor directional selectivity [14]. ð??"ð??" 0 (??) = ? 0 (?? ? 0.5) (2) DT-CWT decomposes the EEG signal to complex wavelet function and scaling function. ?? ?? is the complex wavelet function transform and described by Equation (3). Where ?? ?? , the real part, is related to the upper tree, and ?? ?? is the imaginary part that related to the lower tree. ?? ?? (??) = ?? ?? (??) + ???? ?? (??) (3) The scaling function ? ?? was represented by equation (4), where (? ?? , ? ?? ) for real and imaginary part, respectively. "t" is the time domain transformation. Where: ?? is the given mother wavelet, J is the scale parameters, and k is the shift parameter. ??(??) is the signal in the time domain. Equation (1) shows the signal decomposition to sub-bands. DWT is an efficient method to decompose the EEG signal to sub-bands by applying a set of low-pass filters g(n) and high-pass filters h(n) on the signal as shown in Figure .3. This operation repeated the same value as the choosing level. We choose the level to be four that generates five sub-bands, as described in Table 1. To overcome those limitations, we introduced DT-CWT, as shown in Figure 4. A group of low-pass and high-pass filters used for decomposition. This process repeated until the system reaches 4 th stage. The upper part of the tree for the real part (? 0, ? 1 ) where ? 0 for low pass filters and ? 1 for high pass filters. The lower part of thetree for the imaginary part (ð??"ð??" 0 , ð??"ð??" 1 )where ð??"ð??" 0 for lowpass filters and ð??"ð??" 1 for high-pass filters. Equation (2) shows the relation between the upper tree and the lower tree. Where the upper filters and the lower filters are half sampled delay as follow: # d) Feature Extraction Detection of epileptic seizures depends on two types of features driven from signal's amplitude, such as (Min, Max, etc?) and the frequency features. High accuracy results achieved from a combination of amplitude and frequency features such as line length "LL.". The features included in our study in EEG signal without decomposition were (Min, Max, Mean, Median, Mode, 1st quartile, 3rd quartile, Inter Quartile Rang (IQR), Standard division (STD), and LL. However, we applied the line length feature to the decomposition signal in all sub-bands. Line length is a parameter to measure signal complexity or waveform fractal dimension, and it's like Katz's fractal dimension, as stated in [7,15], and describes in Equation (5). ???? = 1 ?? ? 1 ? ??????(?? ??+1 ? ?? ?? ) ???1 ??=1(5) Where, X stands for the signal, N is the total number of samples and I is the signal samples indices. # e) Epilepsy Classification Classifying data is a vital task in machine learning algorithms. Support vector machine (SVM) was used to assort not only linear classification but also nonlinear classification by using the Kernel trick, which is Transforming data into another dimension that has a clear dividing margin between all classes of data. ??(??, ??) = ???? + ?? 2 ?? 2 (6) Equation ( 6) describes the kernel trick using a kernel function K(x, y) where the training points mapped to a 3-dimensional space where a separating hyperplane can be easily detected [8]. There are several types of SVM (linear-quadratic, cubic, fine Gaussian, medium Gaussian, coarse). Bagged trees algorithm will be introduced on this work. Bagging is a method for enhancing the results of machine learning classification algorithms. This technique leads to classify epilepsy, and reduces the variance, which helps to avoid over fitting problem [9]. Four channels from the normal persons and nine channels from the patients are used to build the learning dataset. Cross-validation was utilized with five folds. A twenty randomly channels from sets (Z, O, N, F, S) will be classified. Finally, obtain Accuracy, Specificity, Sensitivity, and execution time). As shown in Equations (7,8,9). Accuracy (??????) = ????+???? ????+????+????+???? (7) Specificity (????) = ???? ????+???? (8) Sensitivity (????) = ???? ????+???? (9) Where, TP, TN, is the true positive and true negative, respectively. FP, FN, is the false positive and false negative, respectively. Execution time is the elapsed time that the program used only for classification. The computer hardware was CORE i5 with 4 GB ram. We used four types of classification. Type I is performed on the ten features without DWT. While type II performed on the better of two classifiers without, the line length feature and decomposition. While type III executed on line length feature only for the five subbands after DWT. Finally, type VI, DT-CWT applied with level four and line length feature. A proposed algorithm was built to take each sub-band and divided it into sub-signals. Sixty-four points were chosen to be the length of each sub-signal. The output will be a matrix [m, n] (m) is rows which equals 64 that is the total number of segments, and (n) is the column that will be the total number of features. f) The Localization EEG LAB is utilized as an open-source Matlab toolbox used for EEG signal analysis. The feature extraction and plotting procedure of the spectra in the time domain and frequency domains added to the opensource code. Moreover, EEGLAB will be edited to generate a heat map 2D model of the scalp that represents the area that caused the seizure. ii. Classification The classification procedure started to estimate the variation of amplitude in all channels. As the variation of all channels amplitude occurred, that will be a sign of the seizure period as seen in figure. 5. # iii. EEG Mapping and Localization After finishing classification, the tool will localize the most affected channel in amplitude and plot a heat map model to the scalp that appears the affected area in more red color and less affected area in blue. Then, we validated the affected area generated by our system with the area determined by the physician on MRI image, as seen in figure. 6. # III. RESULTS AND DISCUSSION A classifier evaluation procedure performed to select DWT types. Table 2 shows the results of the types of SVM and Bagged tree algorithms while using ten features without using signal decomposition methods. Medium Gaussian SVM and Bagged tree improves the accuracy for classification. Table 3 shows the change in the result while not using line length and only use the nine features (Min, Max, Mean, Median, Mode, STD, 1 st DWT is applied to the signal and extracts the line length feature from the five sub-bands, as in table.4. Reducing the number of features from ten to only five will have a massive effect on the execution time, particularly on the bagged tree algorithm. Table 5 and 6 show different types of DWT and their orders. Table 5 shows medium and fine Gaussian SVM results for db and coif with 4 th order and Coif at the optimum level. When the order increases the execution time increases too, while the accuracy stay the same. Table 6 shows the effect of different types and orders of DWT on the bagged tree algorithm. A comparison in accuracy between Db4 and Coif 4 both almost the same, but the execution time of Db was a little bit better. Moreover, we applied DT-CWT to the signal, and line length feature extracted from different levels as declared in table 7. DT-CWT gives the optimum classification result with the fine Gaussian SVM as it uses the real and imaginary parts of the signal but with higher execution time. Wavelet types in DWT show improvement in the classification accuracy. Therefore, choosing the optimal wavelet type will enhance the final result. Moreover, Median-SVM and bagged trees give the best result compared with the related work. Table 8 shows a comparison between the proposed method and literature reviews done on the same dataset. Previously, some researchers evaluate their work only by set Z, and S. However, this work utilized all different sets Z, O, N, F as normal person dataset and S as patient dataset. After using the localization procedure on the second dataset, a heat map model is most similar to the MRI image. Figure 7 shows the heat map at different seizure periods. # CONCLUSION Seizure detection is a significant step for epilepsy classification. This work shows that decomposing the EEG signal enhancing the evaluation parameters result. Utilizing DT-CWT in signal decomposition and fine Gaussian SVM will improve the SP and SE of classification, but the execution time was higher as a comparison with DWT. The classification execution time is vital as the classification accuracy. As for real-time EEG data, the classification delay could have magnificent effect on system performance. Such outputs will help on real-time analysis to test the performance and localize the cerebral cortex focal area. As passing throw the localization, the application proves that determining the focal area could be achieved from the EEG signal. ![?? (??) = ? ?? (??) + ??? ?? (??) (4) Table1: Frequency bands of EEG signals with four-level DWT decomposition. ("A" stands for approximation, and "D" stands for details; the number following the letter is the level.) Sub-signals Frequency bands (Hz) Decomposition level D1](image-2.png "?") 1![Fig. 1: EEG signals from five different sets (Z, O, N, F, and S) where x-axis for seconds and y-axis for micro volt.](image-3.png "Fig. 1 :") 3![Fig. 3: Discrete wavelets transform (DWT) implementtation sub-band decomposition where g (n) is low pass filters and h (n) high pass filters.](image-4.png "Fig. 3 :") 4![Fig. 4: Double-tree complex wavelets transform (DT-CWT) implementation real and imaginary parts decomposition (four levels).](image-5.png "Fig. 4 :") ![Study of EEG Signal for Epilepsy Detection and Localization using Bagged Tree and SVM Algorithms](image-6.png "") 5![Fig. 5: EEG signal with a seizure period as labeled by a black box.](image-7.png "Fig. 5 :") 6![Fig. 6: a. An MRI image with a green marked focal area. b. The generated heat map model.](image-8.png "Fig. 6 :") ![Study of EEG Signal for Epilepsy Detection and Localization using Bagged Tree and SVM Algorithms](image-9.png "") 2AlgorithmACCSPSEExecution Time (ms)Linear SVMQuadratic98.6%99%98.2%19SVM99.34%99.4%99.2%25Cubic SVM98.18%99.2%93.9%24Fine SVM99.25%99.3%99.1%22Medium SVM99.4%99.35%99.3%22Coarse SVM98.6%99%97.3%23Bagged Tree99.3%99.4%99.1%78 3AlgorithmACCSPSEExecution Time (ms)Medium SVM Bagged Tree98.2% 98.1%98.3% 98.2%97.6% 97.6%21 74 4AlgorithmACCSPSEExecution Time (ms)Linear SVMQuadratic99.5%99.8%98.2%17SVM99.4%99.5%98.9%21Cubic SVM99.5%99.7%99%20Fine SVM99.6%99.6%99.5%22Medium SVM99.8%99.75%99.6%19Coarse SVM99.5%99.6%99%19Bagged Tree99.65%99.64%99.68%50 5AlgorithmACCSPSEExecution time(ms)Db4 Haar Coif3 Coif4 Rbio3.9 Rbio4.499.8% 98.2% 99.6% 99.7% 99.5% 99.4%99.75% 99.6% 99.7% 99.8% 99.4% 99.3%99.6% 92.03% 99.5% 99.55% 99.6% 99.4%19 17 20 22 23 25 6AlgorithmACCSPSEExecution time(ms)Db4 Haar Coif3 Coif4 Rbio3.9 Rbio4.499.65% 98.5% 99.6% 99.6% 99.4% 99.2%99.64% 99.3% 99.5% 99.65% 99.4% 99.1%99.68% 94.5% 99.4% 99.55% 99.5% 99.4%50 32 41 54 49 61 7AlgorithmACCSPSEExecution Time (ms)Fine Gaussian99.87599.999.6885SVMBagged tree99.2599.3798.75225 8ResearchersMethodDatasetAcc%Kannathal et al.2005bEntropy measures-inference system adaptive neuro fuzzyZ,S99.20Kannathal etChaotic measures-al.2005asurrogate dataZ,S~90.0analysisPolat and Gunes.2007FFT-Decision treeZ,S98.72Subasi 2007DWT mixture of expert modelZ,S95.00Tzallas et al.2007bTime frequency analysis ANNZONF-S97.73Ling Guo et al.2010DWT Line length-MLPNNZONF-S97.77Suguna et al.2014SVM with Shannon EntropyZ,S95.00Manisha et al.2018aDWT -MLPNNZ,S100.0Manisha et al.2018aDWT-SVMZ,S99.00This workDWT-Line length-SVMZONF-S99.80This workDWT-Line length-Bagged TreeZONF-S99.65This workDT-CWT fine Gaussian SVMZONF-S 99.875IV. ( ) K © 2019 Global Journals Study of EEG Signal for Epilepsy Detection and Localization using Bagged Tree and SVM Algorithms rd International Conference on Advances in Medical, Signal and information Processing, MEDSIP; 2006. * Automatic epileptic seizure detection in EEGs based on line length feature and artificial neural networks LingGuo DanielRivero JulianRRabunal AlejandroPazos 2010 * EEG Signal Analysis for Epileptic Detection Using Soft Computing Techniques BSuguna Nanthini BSanthi 2014 * EEG signal processing for epileptic seizure Prediction by using MLPNN and SVM Classifiers ManishaChandani ArunKumar American Journal of Information Science and Technology 2 2 2018 * Indications of nonlinear deterministic and finite-dimensional structures in time series of brain electrical activity: dependence on recording region and brain state RAndrzejak KLehnertz FMormann CRieke PDavid CElger Physical review 64 6 E2001 * Open Database of Epileptic with MRI and Post Operational Assessment of Foci-a Real World Verification for the EEG Inverse Solutions PiotrZwolinski MarcinRoszkoski JaroslawZygierewicz StefanHaufe GuidoNolte PiotrJDurka * Open database of epileptic EEG with MRI and post operational assessment of foci-a real world verification for the EEG inverse solutions PZwoli?ski MRoszkowski JZygierewicz SHaufe GNolte PJDurka Neuro informatics 8 4 2010 * A multistage system to detect epileptic form activity in the EEG CChui ADingle RJones GCarroll WFright IEEE Transactions on Biomedical Engineering 40 12 1992. 1993 Academic Press An Introduction to Wavelets * Wong Hin Young. Classification of Focal and Non focal EEG Signals Using ANFIS Classifier for Epilepsy Detection SDeivasigaman CSenthilpari 2016 * Line length: An efficient feature for seizure onset detection REsteller Echauz J TTcheng BLitt 23 rd Annual International Conference of the IEEE Engineering in Medicine and Biology Society 2001 4