Epilepsy attacks recognition based on 1D octal pattern, wavelet transform and EEG signals

Electroencephalogram (EEG) signals have been generally utilized for diagnostic systems. Nowadays artificial intelligence-based systems have been proposed to classify EEG signals to ease diagnosis process. However, machine learning models have generally been used deep learning based classification model to reach high classification accuracies. This work focuses classification epilepsy attacks using EEG signals with a lightweight and simple classification model. Hence, an automated EEG classification model is presented. The used phases of the presented automated EEG classification model are (i) multileveled feature generation using one-dimensional (1D) octal-pattern (OP) and discrete wavelet transform (DWT). Here, main feature generation function is the presented octal-pattern. DWT is employed for level creation. By employing DWT frequency coefficients of the EEG signal is obtained and octal-pattern generates texture features from raw EEG signal and wavelet coefficients. This DWT and octal-pattern based feature generator extracts 128 × 8 = 1024 (Octal-pattern generates 128 features from a signal, 8 signal are used in the feature generation 1 raw EEG and 7 wavelet low-pass filter coefficients). (ii) To select the most useful features, neighborhood component analysis (NCA) is deployed and 128 features are selected. (iii) The selected features are feed to k nearest neighborhood classifier. To test this model, an epilepsy seizure dataset is used and 96.0% accuracy is attained for five categories. The results clearly denoted the success of the presented octal-pattern based epilepsy classification model.


Introduction
Epilepsy is accompanied by spontaneous debilitating seizures and currently affects 2.9 million individuals in the USA and roughly 70 million people worldwide. Epilepsy results in severe co-morbidities and tremendous loss of quality of life, while also costing $15.5 billion annually to the US healthcare system [69]. There are around 2.4 million new cases of Epilepsy around the world. Taking into account the aging society, according to forecasts, mental and neurological diseases, including epilepsy will be the main health problem in the world in the near future. For this reason, it is extremely important to develop appropriate tools (computer-aided diagnosis) that support the diagnosis of neurologists and psychiatrists.
Automatic identification and detection of Epilepsy or brain-related disorders are the major challenges for both clinicians and research scientists. Generally, neurological experts or brain surgeons inspect EEG recordings to detect the epileptic activity. Therefore, it is essential to develop a reliable and automated technique to detect Epileptic seizures is essential. An automatic interpretation of EEG signals in the diagnosis and treatment of brain diseases is one of the most important areas of study [46]. These systems, which are formed by the guidance of an expert physician due to intensive working hours and workload of physicians, play a significant role in diagnosis and treatment. The following advantages of EEG signals cause widespread use in automatic identification systems [3,64].
-Recording in digital devices, -High resolution, -Low cost -Applicable to people of all ages, -Noninvasiveness.
The EEG signal analysis is complex and tedious process, therefore, despite many methods presented in the literature, they still do not show sufficient effectiveness or are characterized by high computational complexity, which makes it difficult to implement them in practice. That is why there is no alarm system for future epilepsy attacks. Such a system would be very valuable for people with epilepsy because proper preparation for an impending epilepsy attack is crucial.
Therefore, the goal of our research was to create an effective and easy to use (not very computationally complex) method for automatically and mobile recognizing epilepsy seizures. Therefore, a texture feature generator (OP) and DWT based feature generation model is presented. As stated, texture feature generator can be implemented easily. However, they cannot reach high performance for some problems. Because they cannot extract both highlevel, mid-level and low-level features. To generates these types features, levels are created deploying DWT. The most discriminative/distinctive features are selected using NCA. By using this collaboration, high accuracy rates are attained.

Literature review
Owing to these advantages, variable methods have been presented in the literature. Some of them are given as follows. Ibrahim et al. (2018) [34] analyzed a method based wavelet and Shannon entropy for epilepsy. In their study, a SVM, LDA, artificial neural networks, and knearest neighbor were used as a classifier. Gruszczyńska et al. (2019) [25] suggested a study based recurrence quantification analysis to classify EEG signals. The principal component analysis was used to visualize the results. SVM was utilized for the classification of results obtained. Anuragi and Sisodia (2018) [9] presented an approach based machine learning methods and wavelet transform for alcohol use disorder. The aim of this study is to classify alcoholic and healthy individuals automatically. SVM and Naïve Bayes methods were utilized in the study. Motamedi-Fakhr et al. (2014) [47] investigated the effect of EEG signals on sleep. Signal processing techniques have been utilized for this purpose. Dose et al. (2019) [17] suggested a method using convolutional neural network for motor imagery electroencephalogram. Comparative results were presented according to time and accuracy parameter. Mutlu (2018) [48] proposed an approach using Hilbert vibration decomposition for epilepsy. In the study, the least squares SVM was selected as the classifier. The aim of the study is to distinguish the signals normal of and epileptic individuals. Time, accuracy, and receiver operating characteristics were selected as the evaluation parameter.   [4] presented a study using a neural network for EEG signal classification. This study was evaluated according to specificity, sensitivity, and accuracy. Yilmaz et al. (2018) [70] suggested a novel method to classify EEG signals. 2-D signal representation method was used in this study. Specificity, f-measure, sensitivity, and accuracy parameters were selected as evaluation criteria. Kocadagli and Langari (2017) [42] proposed a model by using wavelet transforms and ANN. In this study, comparative results were presented according to the accuracy parameter. Al-Salman et al. (2019) [7] proposed a study using wavelet Fourier analysis for detection of sleep spindles detection from EEG signals. Least squares SVM was used for the classifier. The results were presented according to accuracy, kappa coefficient, f-score, sensitivity, and specificity. Moreover, many intelligent classification methods have been proposed for signal (electrocardiography, electromyography, electrooculography) [13,18,24,27,37,44,49,57] and image or data (breast cancer, brain tumors, stomach cancer, kidney cancer) [1,2,11,16,29,55,65,74] processing in the literature related to medical studies. In addition, there are many different studies on machine learning and artificial intelligence in the literature [5,12,14,15,26,30,31,35,36,[61][62][63] [10,28,38,52,53,59,60,66]. Some of these studies, which include machine learning techniques, are on forecasting outside of medical studies [19-22, 32, 45, 71, 72].

The proposed 1D octal pattern
In this study, a novel method is presented for the feature extraction of EEG signals. This method is called the 1D octal pattern (1D-OP). Firstly, the average, standard and median deviation values of the signal are calculated. These are widely preferred statistical moments for feature generation (the two of the commonly used). The purposes of the presented 1D-OP are; -The mostly used texture feature generator for signals is one-dimensional binary pattern (1D-BP). 1D-BP uses 9 sized overlapping blocks and extract 256 features. The size of the generated feature vector is high. Therefore, it increases memory complexity. To decrease memory complexity, center symmetric model and less sized overlapping have been used. The presented 1D-OP generates 128 features using eight size overlapping blocks. -Hand-crafted features are divided into textural feature generation and statistical feature generation. Statistical features are generated employing statistical moments. Three statistical moments have been used to generate salient features.
The single EEG signal is seperated into 8 overlapping blocks of equal length. Centersymmetric signal values and the signum function are used to extract binary features. The average, median and standard deviation values of the block are calculated. Global and local statistical values are also used to extract binary features. Finally, 1D-OP extracts 7-bits feature values to each block. 4-bits feature values are extracted from blocks with a length of 8 using signum function, and 3-bits are extracted using statistical attributes. The signal is constructed using the extracted feature values, and histogram of the feature signal is used as a feature set.
Steps of the proposed 1D-OP is presented as below.
Step 2: Calculate the global statistical values of the EEG signals.
Where S is EEG signal, avr g , med g and std g describe the average, median and standard deviation of the signals.
Eight sized non-overlapping blocks are chosen to extract 7 bits, feature values of each block. Four bits feature values are extracted using Signum function, and 3 bits are calculated using statistical attributes.
Step 4: Calculate the statistical values of the block using Eqs. 1-3.
Step 5: Use the signum function to extract binary features. The signum function is given Eq.
Algorithm 1: Bit extraction process of the OP.
In this algorithm, std g , mdn g and avr g express standard deviation, median and average values of the input EEG signal respectively. std b , mdn b and avr b are standard deviation, median and average values of the each divided 8 sized overlapping blocks respectively. Both statistical and textural features are used together to generate salient/informative features from an EEG signal. By applying this algorithm (Algorithm 1), seven bits are generated for each eight sized overlapping block. Step 6: Calculate map signal values mv using binary to decimal conversion.
Step 7: Extract the histogram of the feature signal.
where feat is the feature set, H(.) is histogram extraction function, and fs represents feature signal.
A numerical example about the proposed 1D-OP is shown in Fig. 2 for better understanding the presented 1D-OP.

The proposed method
As we know from previously presented works, DWT has a positive effect on the EEG classification. Textural feature extraction methods for instance 1D LBP and 1D TP have already been found to be successful in EEG classification. Statistical features have also been used in texture classification. To use these positive effects directly, we proposed a novel 1D-OP method, coupled with multi-level DWT. We use seven-levels DWT to extract in-depth features. 1D OP is utilized to the signal and low pass filter coefficients of the signals, and the extracted features are concatenated and a 1024D feature set is obtained. NCA is employed to select the most discriminative/salient features and the length of final feature vector is calculated as 128. The selected 128 features are forwarded to kNN classifier. The graphical definition of this model is shown in Fig. 3. As can be seen Fig. 4, seven level DWT is applied to the EEG signal. Symlet 4 mother wavelet function is used for DWT. The presented 1D OP generates 128 features from each EEG signal and low-pass filter coefficients (L bands) and the extracted features are merged and final feature vector with a length of 1024 is created. 128 the most valuable features are selected by deploying NCA and the selected/chosen features are feed to kNN classifier. As known from the literature, variable models have been presented to classify/detect/predict the EEG signals. Our main objective is to reach high classification capability with a low computational complexity. Deep learning models have high performances but their time complexity is very high. The deep learning models uses variable layers to extract both low-level and high-level features. Moreover, they need set millions parameters. We presented a feed-forward feature creation method based EEG classification model. We need layers/levels to generate multiple leveled features. Therefore, DWT is used seven times and a multileveled transformation is created (See Fig. 4). In the feature generation phase, we need a both effective and lightweight feature generator. Therefore, OP is presented to generate discriminative features. In the recommended OP, statistical moments have been used. Moreover, time complexity of the presented OP is calculated as O(n). Feature selection is one of the critical phases for the multilayered/multileveled machine learning models. By applying NCA, both performance of the model is increased and execution time of the used classifier is decreased. Briefly, simple and effective methods are used together to create an effective EEG classification model.
The steps of the feature extraction method are as follows.
Where DWT(.) represent DWT function with haar filter. L 1 , L 2 , …, L 7 are low pass filter coefficients of three level DWT. H 1 , H 2 , …, H 7 are high pass filter coefficients. Here, DWT is utilized as decomposition method. As stated, to reach high classification accuracy, high level, low level and medium level features must be generated. To generate feature with 3-levels, a transformation/decomposition method must be used. In the deep network, pooling based decomposition methods such as maximum, average and minimum pooling methods have been used. This work employs DWT as decomposition methods. Also, we used 3-levelled DWT to achieve the best results. According to experiments, best results were obtained by using 3leveled DWT. Therefore, this method developed by using 3-leveled DWT.
Step 3: Step 3: Extract features of EEG signals and low pass filter coefficients using 1D-OP. Fig. 4 The calculated F1-scores for each class where OP(.) represents 1D OP feature generation function and f 1 , f 2 , …, f 8 are features of the EEG signal and low-pass filter coefficients.
Step 4: Merge features to obtain 1024D feature set. Equation 13 represents feature fusion. fs where fs is feature set and conc(.) represents a merge function.
Step 5: Choose the most discriminative 128 features using NCA. Algorithm 2 demonstrates the used feature selection process. Algorithm 2. The pseudo-code of the NCA based feature reduction.
The classification abilities of the chosen features are evaluated in the experiments.
Step 6: Use kNN classifiers for classification of the selected features. The parameters of the used kNN classifier are given in Table 1. As seen in Table 1, the constant parameters of the classifier are given, and these parameters are utilized to evaluate this method and obtain comparisons.
As demonstrated in Fig. 4, this method was applied to an EEG signal, and the obtained components and feature vectors are shown.
Moreover, pseudocode of the presented model is shown in Algorithm 3. Algorithm 3. Pseudocode of the presented OP and NCA based model.

Experimental results
The proposed study uses the EEG dataset of Bonn University. This dataset is widely used in the literature. There are 500 EEG signals of 5 classes in this dataset [8]. The classes of the used dataset are called S, F, N, O, and Z. Each file consists of 4097 samples. The sampling rate of In this section, numerical computational time, results, confusion matrix, and comparisons are provided. We use MATLAB 2018a software and perform the simulation using a PC with 32 GB RAM, Intel Core i7-7700 CPU on Windows 10.1 operating system. We didn't use any graphical processing units or cores. The average execution time is listed in Table 2.
As seen in Table 2, the proposed method is a lightweight method because it has a short execution time. The execution time of the OP and NCA based methods for single EEG fragment was calculated as 71.42 millisecond (35.71/500). This situation is indicated that real-time systems can be constructed using the proposed method. As we know, the testing time of these is shorter than the training times. The time complexity of the presented OP and NCA based classification models were calculated in Table 3.
Accuracy was utilized as a main performance evaluation parameter. Specificity, sensitivity, and g-means are calculated to show the performance of this method clearly. The description of the parameters used is listed in Eqs. 22-25.
where Acc, FN, FP, TN, TP, Spe, Sen, and g − m are accuracy, false negative, false positive, true negative, true positive, specificity, sensitivity, and g-means respectively. 7 cases were defined in this work to obtain results and comparisons. Our experimental cases are ZS, ZF, OS, FS, NS, ZFS, and ZONFS. The explanation of these cases is listed in Table 4 [67]. The calculated accuracy rates according to experimental cases are demostrated in Table 5.
The best results for the fp and fn were achieved using KNN and SVM. The widely used cases are Z-S, Z-F, O-S, F-S, N-S, and Z-F-S in the literature. The comparative results are listed in Table 6.
In the literature, 1D local binary pattern (LBP) and 1D ternary pattern (TP) are used to EEG classification, and the variable studies were not given the results of the classification for Z-O-N-F-S classes recognition. 1D TP and LBP are used for comparison because these are textural feature extractor as 1D-OP. 1D-OP extracts a 128-dimensional feature set. The calculated best success rates are listed in Table 7.
The confusion matrices of the Z-O-N-F-S is given in Table 8. The geometric mean, unweighted average recall, unweighted average precision and F1score were also calculated for all five classes, and these results were given in Table 9.
The calculated F1 scores for each classes were also shown in Fig. 4. 10-fold cross validation was used to obtain testing accuracies. Fold by fold accuracies for the Z-O-N-F-S classification was denoted in Fig. 5.
Moreover, ROC curve of this result was also plotted and it was given in Fig. 6. The ROC curves of the best results for all 5 classes are demostrated in Fig. 6, and the average AUC value of the proposed method is computed as 0.976.

Discussion
In this paper, a novel stable EEG feature extraction method is proposed. We proposed a lightweight feature extraction network because the computational complexity was calculated   as O(nlogn). This method is similar to a deep network such as CNN. CNN uses a convolution operator, weight assignment, and weight updating methods. These methods (CNN like methods) have high computational complexity. Hence, the execution time of CNN is long. In this study, the proposed 1D-OTP is used as convolution and 1D-DWT is used as maximum pooling. In the feature reduction phase, NCA selector is chosen. There are no weight assignments and updating methods. Also, the comparisons apparently demonstrate that this method has high classification accuracy than 1D-CNN. In this work, a novel feature extraction method is presented using basic and effective methods. This paper clearly shows that patterns like 1D-OP can be used in deep networks instead of convolution operators. The discussions of this method are also given below.
-By using kNN classifier, high accuracy rates were yielded for seven cases.
-By using a traditional classifier (kNN), successful results were attained.
-NCA is used for feature selection and 128 features are selected.
-The separable features are extracted using this method. The statistical analyses of the extracted features are demostrated in Fig. 7. In Fig. 7, the blue box shows the range of the features; red lines represent the average value of the features; red stars are boundary values of these features. By using boxplot analysis, distributions and statistical attributes of the features are shown easily. Moreover, we applied t-test to extracted features. The calculated minimum p values were listed in Table 10. Table 10 denoted statistical strength of the generated features. Moreover, the calculated pvalues are visualized in Fig. 8.  Table 9 obviously show separation of the extracted feature sets. Therefore, the proposed method achieves high classification capability. -The experiments clearly illustrated that this method is achieved more successful results than 1D-CNN for all five classes case. -Comparisons were apparently illustrated that the proposed method has high classification ability and more successful than another state of art methods for ZF, OS, FS, NS, ZFS and ZONFS experimental cases (class recognition). -Comprehensive experimental results are given.
-Universal features were extracted from EEG signals using the proposed method.
-This method has a simple mathematical structure, and it can be applied to realworld problems, e.g., in mobile devices and cloud computing. The novel mobile applications can be presented by using this method, and this application can be used to diagnose epilepsy.
The advantages of this method are: -This method has a short execution time.
-The novel signal pattern is presented and achieved high success rates using this pattern.
-High classification accuracy was obtained using this method. -This method has wider availability. Because it has a short execution time and high classification capability. -By using seven cases, high classification accuracies were calculated. This situation obviously denoted that the presented 1D-OP based method has a general success.
The disadvantages and limitations of this method are summarized below. This method is only implemented on the EEG signal, and the used dataset is small because the Bonn EEG dataset consists of 500 EEG signals with 5 classes. The Bonn dataset is widely used in the literature for EEG classification. Therefore, this dataset is chosen. The used dataset is also homogeneous.

Conclusions and future works
The aim of this method is to classify EEG signals with a high accuracy rate. Multilevel DWT and a novel 1D-OP are used together. 1D-OP extracts 128 sizes of features from each signal.  Three-level DWT is utilized in this paper. Original signal and seven low pass filter coefficients are utilized to extract features. In the feature fusion phase, the extracted features with a size of 128 for each component (original signal and low pass filter coefficients) are concatenated and 1024 sizes of the feature are obtained. After the feature selection, 128 features are obtained and these features are feed kNN classifier. Seven experimental cases were selected from Bonn EEG dataset. 99.5%, 100%, 100.0%, 99.0%, 100.0%, 99.3% and 96.0% accuracies were calculated on ZS, ZF, OS, FS, NS, ZFS and ZONFS cases consecutively. The calculated accuracy for ZONFS is 7.3% higher than the best result of the others. These results and comparison demonstrated the effectuality of this method. Therefore, the goal of research has been met, and this method can be utilized for automatically and mobile recognizing epilepsy attacks. Moreover, this model uses basic methods/functions to classify EEG signals. Therefore, this model is ready to use on the medical centers.
In future works, real-time applications can be implemented by using the proposed. IoT and cloud-based EEG based systems will be constructed using this system. Bigger datasets can be collected to create a successful model. Moreover, as we know that, deep learning methods have high computational complexity. The novel deep learning methods can be proposed using the proposed method and novel 1D pattern like the proposed octal pattern.

Declarations
Conflict of interest The authors declare no conflict of interest.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.