Analysis of Epileptic iEEG Data by Applying Convolutional Neural Networks to Low-Frequency Scalograms

In this paper, Convolutional Neural Networks (CNN) method was applied to low frequency scalograms in order to contribute to the development of diagnostic and early diagnosis systems of epileptic intracranial EEG (iEEG) signals of brain dynamics at preictal, ictal, and postictal states, and to achieve results that will be the basis for determining the pathological conditions of iEEG signals. As part of this study, iEEG data obtained from epileptic subjects were first decomposed into their subbands by discrete wavelet transformation, and then Shannon entropy was applied to these five subbands (delta, theta, alpha, beta, and gamma). The results obtained made us observe that the delta subband entropy value is lower than other subband entropy values. A low entropy value means that the data is less chaotic. A low degree of chaos means better predictability. Within this context, scalogram images of low-frequency delta subband were obtained at preictal, ictal, and postictal stages and treated with the CNN method, and consequently, a 93.33% accuracy rate was obtained.


I. INTRODUCTION
Organs in the human body produce bioelectric signals when they function. Processing and analysis of these signals are as important as their perception. As we study the parameters taken from the human body, more information about the mechanics of the functioning of organs is reached. When we analyze these parameters, abnormal functioning of the organs can be observed as well as their normal functioning. This, in turn, allows the development of new techniques for diagnosis and treatment. The brain is the central decision and governing body of man. Most of the neural activity takes place in this organ. As much as we understand the activities in the brain, concepts such as consciousness, memory, and intelligence are better understood and interpreted. Within this context, the importance of the brain is increasing every day. Electroencephalogram (EEG) refers to the measurement of signals from the skull formed due to the activation of neurons in the brain. iEEG is a type of EEG, but iEEG refers to measurement directly from the surface of the brain. Since this is a multi-channel measurement, it leads to an even more precise perception of information reaching the brain's surface. However, this means a data crowd, as more parameters are generated.
In 1875, Caton discovered that the brain showed spontaneous and continuous activity through studies in the rabbit brain. Hans Berger made the first recordings of the electrical field in the human brain in 1924, and he called this record EEG and suggested that EEG changes in some diseases [1]. This study is considered the beginning of the evaluation of the brain by signals.
The cerebral cortex performs its functions thanks to the large number of cells it contains. Either micro or macro electrodes are used to record and observe the behavior of neuron groups. Single-cell responses are recorded with microelectrodes. This method, which is challenging and time-consuming, is applied chiefly to experimental animals. The total activity of crowded cell groups is recorded with macro electrodes. Electrical records obtained from the brain's surface (cortex) and the outer surface of the head (scalp) show that the brain has a continuous electrical activity. Both the severity of electrical activity and the patterns it contains are primarily determined by changes in the level of brain arousal in sleep-wake states and brain diseases such as epilepsy and even in some psychoses. The oscillations in these electrical potentials are called "brain waves", and the entire resulting record is called an electroencephalogram (EEG) [2]. EEG is one of the most common methods used in brain research and diseases.
The frequency of EEG waves is fundamental, and they contain important information. These signals of the brain organ provide information about the functions of the brain organ. In order to use this information, Signal Processors conduct a wide range of research. Some pathological symptoms may go unnoticed in the time zone. Neurologists often make diagnoses based on the time zone. Recently, computers have been recording these signals, and the development of spectral analysis methods has made it possible to use frequency components to find these pathological symptoms [3].
The frequencies of EEG signals and the phase differences of EEG signals from various brain points provide important information about the human brain. The amplitude of EEGs detected on the head varies from 1-100µV from top to top, and the frequency band is approximately within the range of 0.5-100 Hz.
In order to obtain meaningful information from EEG signals, relatively long-term measurement and recording are required because EEG signals show much frequency, phase, and amplitude information depending on brain activity.
Since EEG contains information about brain activity, and the brain is also the central decision organ of a person, its analysis is of particular importance. EEG continues to be an indispensable method for detecting pathological conditions and anomalies and studying the brain activity of healthy individuals. As the number of channels increases, more precise measurements can be obtained through a thin section. However, as the number of data and parameters increases, processing and analysis become difficult.
Epilepsy is a brain-focused disease. Seizures are just one form of epilepsy being noticed in the outside world. Additionally, the forms of seizures can also be very different. A seizure of epilepsy is a sudden paroxysmal reaction of a focal or generalized character of the brain caused by increased excitability (neuronal hyperexcitability) of specific neurons in the central nervous system due to various causes [4]. Epilepsy is a chronic disorder characterized by recurrent seizures. However, patients who have had seizures due to the effects of drugs such as antipsychotics or antidepressants, or patients who have had seizures due to temporary changes in cerebral function caused by different forms of organic brain syndromes, are not considered epileptic patients [5]. Epileptic seizures can occur in different ways.
Epileptic seizures are observed when a large group of neurons discharge together (synchronously) and abnormally. The synchronous discharge causes stereotypical, involuntary, and sudden temporary seizure behaviors, and these changes deeply affect the life of the epileptic patient. Abnormal cell discharge can occur due to trauma, lack of oxygen, tumors, infection, and metabolic disorders. However, it is impossible to find any cause in about half of epileptic patients [6].
Having information in enormous size that contains many parameters makes it difficult to interpret and evaluate this information. For this purpose, constantly evolving mathematical models are used. One of the current and constantly evolving models and the most common is artificial neural networks. Artificial neural networks (ANN) are the first to come to mind when we consider machine learning, and Convolutional Neural Networks (CNN) is the first to come to mind when it comes to deep learning. After determining the attributes in the conventional classification method, we proceed to the classification phase in ANN. In CNN, attribute identification and classification phases are performed in the same model. The ANN model is preferred for single-channel data, while the CNN model is preferred for multi-channel signals. The most significant advantage of CNN (and deep learning) is that they can automatically learn the necessary and appropriate features on their own.
In the Convolutional Neural Networks method, one of the deep learning methods, feature extraction, and classification stages are in the same model. In the traditional approach, attribute extraction methods are applied to the data first, and then the classification phase is started with CNN. Several recent studies on CNN and EEG signals in the literature are presented below.
Hajinoroozi et al. (2016) turned to cognitive state estimation of driving performance using the CNN model with EEG content [7]. Shirrmeister et al. (2017) applied CNN model to EEG signals. It can be said that this study was successful in opening new windows for innovative visualization and EEG-based brain mapping [8]. In their study, Acharya et al. (2017) used the deep CNN model for automatic detection and diagnosis of seizure using EEG signals. Since EEG signals are widely used to diagnose epilepsy, and the CNN method is also considered and preferred among current modern mathematical methods, they conducted such a study. 88.67% accuracy rate was captured in this study [9]. Li et al. (2017) sought to recognize human emotion with EEG in their work entitled, "Human emotion recognition with electroencephalographic multidimensional features by hybrid deep neural networks." Images obtained by EEG were classified and analyzed by CNN [10]. Lawhern et al. (2018), in their study, "A compact CNN for EEG-based brain-computer interfaces," declassified EEG signals using the CNN model. The CNN model receives raw signals and automatically maps the feature, and this stage also includes the classification phase [11]. Cloostermans et al. (2018) found focal epileptic discharges using EEG data with the CNN Model [12]. Zhou et al. (2018) achieved interictal, preictal, and ictal states using the CNN method and the frequency domain with the highest accuracy rate of 96.7% with iEEG signals and the highest accuracy rate of 97.5% with EEG signals [13].
Hussein et al. (2019) applied a deep long short time memory (LSTM) network to epileptic attacks first, and the values obtained from this were claimed to achieve 100% accuracy with deep learning [14]. Hu et al. (2019) decomposed the 18-channel epileptic EEG data preictal phase into sub-bands and removed features with CNN and progressed with the classification path using SVM. In this study, they achieved an accuracy rate of 86.25% [15]. Gao et al. (2019) achieved an accuracy rate of 99.26% by applying approximate entropy and CNN on epileptic EEG data received from the University of Bonn, and they achieved an accuracy rate of 99.26%. Only a 92% accuracy rate was captured with approximate entropy [16]. Wei et al. (2019) detected 90.57% attacks by applying CNN, a combination of decreasing and increasing sequences, and data increase methods to epileptic EEG signals [17]. Türk and Özerdem (2019) applied CNN by dividing epileptic EEG data received from the University of Bonn into their sub-bands and achieved an accuracy rate of 99.5% in binary comparison, 99% in triple comparison, 91.5% in quadruple comparison, and 93.6% in quintuple comparison [18]. Emami et al. (2019) claimed that converting long-recorded epileptic EEG time signals to short-recorded EEG signals and obtaining their images detected 74% epileptic seizures based on seconds and 100% epileptic seizures based on minutes with CNN [19]. Abiyev et al. (2020), applied CNN to EEG data received from the University of Bonn and achieved an accuracy rate of 98.67% [20]. Raghu et al. (2020) applied the CNN method by taking 19-channel epileptic EEG signals spectrogram images. By applying two different methods, they achieved an accuracy rate of 82.85% in one and 88.30% in the other [21]. Gao et al. (2020) claimed that they exceeded an accuracy rate of more than 90% by applying seizure states of epileptic EEG data to the interictal stage, 30 minutes before the seizure, 10 minutes before the seizure, and using CNN [22].
Prathaban and Balasubramanian (2021) stated that they achieved 98% accuracy by applying 3-D optimized CNN to preictal, interictal, and ictal EEG signal data [23]. Yildiz et al. (2021) treated spectrogram and scalogram images of normal, interictal, and ictal EEG data using the CNN method and stated that they captured 100% accuracy [24].
It is seen that CNN is heavily applied to scalp or intracranial EEG data from epileptic patients when the recent studies [25][26][27][28][29][30][31][32][33] on epilepsy detection are reviewed. In this study, by using CNN, one of the deep learning methods, we aimed to achieve more successful results in the analysis of multi-channel iEEG data. Since the attribute and classification stages are in the same model when using deep learning methods, there is no need to create an attribute vector outside the model. This can lead us to conclusions with fewer mathematical models and/or parameters.
Preictal stage is important for detecting epileptic seizures, and ictal and postictal stages are important whether the situation is an epileptic seizure or not. Because epileptic seizures can be confused with pseudo epileptic seizure, nonepileptic events including narcolepsy, eclampsia, convulsive syncope, arrhythmias, meningitis, migraine etc [34].
This paper is organized as follows. iEEG database, decomposing of iEEG into subbands, iEEG preprocessing, its entropy, and CNN are described in Section 2. Results and Discussion are given in section 3. And finally, Conclusion and Future work are given in section 4.

A. iEEG DATABASE
The CNN model's input data consists of epileptic iEEG data taken from 16 patients with a sampling frequency of 512 Hz. The first part of this data consists of 180 seconds of preictal, the middle part consists of ictal with periods ranging from 13 seconds to 154 seconds, and the last part consists of 180 seconds of the postictal stage. All epileptic EEG data were divided into preictal, ictal, and postictal segments, and subbands of each were taken, and scalogram images were obtained. Because the entropy values of divisions and delta subbands are close, scalogram images of the delta subband of each division were obtained and used as input parameters of the CNN model. 80% of the data obtained was used for training and 20% as test data.
In this paper, epileptic iEEG data of 16 patients was used in the Sleep-Wake-Epilepsy Center of the Department of Neurology at Inselspital Bern University [35]. iEEG signals were recorded intracranially by strip, grid, and depth electrodes (all manufactured by AD-TECH, Wisconsin, USA), using a Nicolet One recording system with a C64 amplifier (VIASYS Healthcare Inc., Madison, Wisconsin, USA). An extracranial electrode, localized between 10/20 positions Fz and Cz, was used as a reference for signal recording. Forward and backward filtering was applied to minimize phase distortions. All the iEEG recordings were visually inspected by an EEG board-certified experienced epileptologist for seizure identification and exclusion of channels continuously corrupted by artifacts. After 16-bit analog-to-digital conversion, the data was digitally decoded from 0.5 to 150 Hz using a fourth-order Butterworth filter before analysis and written to CD at 512 Hz. Each track consists of a 3-minute preictal segment (i.e., just before the onset of the seizure), ictal segments (between 13 seconds and 154 seconds), and a 3-minute postictal period (i.e., just after the end of the seizure). Patient codes, number of channels, patient age, hemisphere, syndrome, and seizure duration for each patient are shown in Table 1. It is marked as frontal lobe epilepsy: FLE, temporal lobe epilepsy: TLE, parietal lobe epilepsy: PLE.

B. DECOMPOSITION OF iEEG INTO SUBBANDS
iEEG data is decomposed into its subbands by discrete wavelet analysis. Discrete wavelet analysis is of great importance in the feature extraction of non-stationary signals and is a method that provides integrated time-frequency information of the signal. Wavelet analysis is preferred to decompose the signal into certain sub-spectral bands and focus on these bands. As shown schematically in Figure 1, the signal is passed repeatedly through a low-and high-pass filter. Sub-bands filtered through the low-pass filter constitute "approximate coefficients", while sub-bands filtered through the high-pass filter constitute "detail coefficients" [36]. The diagram in Figure 1 is specifically designed for iEEG sub-bands. Approximate coefficients of iEEG signals are expressed as (cA), and detail coefficients are expressed as (cD). The iEEG signal (0-60 Hz) is decomposed into five sub-bands after passing through the band-pass filter. These are taken respectively as, delta = cA4= (0-4 Hz), theta=cD4= (4-8 Hz), alpha=cDA4= (8-12 Hz), beta = cD2+ cDD4= (12-30 Hz) and gamma = cD1=(30-60 Hz). Since discrete wavelet analysis is a common method for analyzing brain signals in the literature [37], we preferred to include this method in our study.

C. iEEG PREPROCESSING
The phases of the iEEG signal which will be applied to the input of the CNN model are shown in Figure 2. Primarily epileptic iEEG data is divided into preictal, ictal, and postictal segments. Then these stages are decomposed into subbands. Later, entropy values of subbands were found. It has been observed that the lowest entropy values belong to delta subbands (Table 2). Finally, 224x224 pixels scalogram images of delta subbands were created.

D. ENTROPY
Entropy can be briefly described as a measure of the order/disorder of a system. It is a term used in thermodynamics as a measure of the disorder of a system. In this definition, what is tried to be meant with the phrase of the order/disorder is the distribution of the system's total energy between the existing grains. The entropy concept in communication theory began in the 1940s by Shannon's proposal [38]. Since then, the entropy technique has been widely used in many areas, including signal processing notably. From the point of view of signal processing, it is an appropriate tool for measuring the degree of disorder information of a non-stationary signal. If the signal is stationary, it has a low entropy value with a narrow spectrum in the frequency region. If the signal is not stationary, the frequency spectrum spreads to a wideband with a high entropy value [38]. The most used types of entropy computation in signal processing include the Shannon entropy technique.
Since brain signals fall into a group of non-stationary signals and the entropy technique is successfully applied to these signal types [39][40][41], there was a desire to use and develop this method. The entropy technique is described below.
The entropy of a system can be calculated using the Shannon entropy [42] Pj in equation (1) is a probability function and represents normalized energy in this study. The entropy value (S) obtained here is the measure of the disorder of the system. It is believed that this criterion offers general information about the system.

E. SCALOGRAMS
In general, scalogram can be defined as absolute values of continuous wavelet coefficients. Also, scalogram images have two axes as frequency and time. All the scalogram images were obtained in MATLAB software as 224x224 pixels. 3300 scalogram images were used in the study. %80 of the images (2640) were used for training and %20 of the images (660) were used for test. In addition, %20 of the training images (528) were used for validation. The scalogram images are RGB images (3 channels as R, G, B) and the images dimensions are 224x224 pixels. Also, RESNET model needs 224x224x3 colored images.

F. CONVOLUTIONAL NEURAL NETWORKS
The basic layers of CNN model (Figure 3) are listed below and briefly described.

1) INPUT LAYER
The input layer is the first layer of CNN, and it is important to carefully select this layer in terms of dimensional and qualitative aspects for good performance. Raw epileptic iEEG data, primarily divided into preictal, ictal, and postictal segments, were divided into preictal, ictal, and postictal, respectively, to create an input layer parameter. Then these segments are decomposed into epochs that will form 224 samples (0.4375 seconds). These epochs were then decomposed into their subbands by Discrete Wavelet Transform in the MATLAB environment. Scalograms of the delta subband of the divisions decomposed to 5 subbands were taken, and applied as CNN input data.
2) CONVOLUTION LAYER By correlating at the convolution layer, on the one hand, the data size is reduced, and on the other hand, hidden properties in the data are revealed. In this layer, the properties in the input data are revealed, and the data is given an identity.

3) ACTIVATION LAYER
In this layer, a rectified linear unit (ReLU) is usually used. In this layer, negative values are drawn to zero, giving the network a non-linear structure and enabling the network to learn faster. In this study, ReLU was used as the activation layer.

4) POOLING LAYER
This layer determines features, and memorization is prevented by reducing size. Despite the usual usage in three ways as a minimum, maximum and average pooling, maximum pooling is preferred. In our study, maximum pooling was used as a pooling layer. 5) FULLY-CONNECTED LAYER In this layer, the property matrix formed in the convolution, activation, and pooling layers is translated into a vector matrix.

6) CLASSIFICATION LAYER
As the name suggests, classification is done in this layer. Although different classifiers are used here, softmax is more preferred. The classifier classifies the items to be classified by giving values between 0-1. The best estimate of the network is the value that is close to 1. In this study, softmax and iEEG data were divided into three main classes: preictal, ictal, and postictal.

III. RESULTS AND DISCUSSION
In this study, iEEG data was divided into three classes: preictal, ictal, and postictal, using the multi-channel epileptic iEEG data that characterize epilepsy disease and by using the CNN model, which is a modern mathematical method. One channel of the 47-channel iEEG signal belonging to the epileptic patient10 is shown in Figure 4. This channel consists of a complete recording of 485 seconds. The first 180 seconds of this recording are preictal, the later 125 seconds are ictal, and the last 180 seconds are postictal. The first 180-second pre-seizure stage in Figure 4 is considered the preictal. After this stage, there were increases in amplitude, and it lasted for 125 seconds. This period of 125 seconds is the moment of seizure. This is defined as the ictal stage. After this stage, the amplitude began to decrease and returned to the previous value range. This stage at the end of the seizure is also considered a postictal stage. The duration of seizures experienced by patients is different from each other. The shortest seizure moment belongs to patient 1 and lasts for 13 seconds. Because of this, the seizure of patient 1 was taken as a reference. Since our sampling frequency is 512, the preictal, ictal, and postictal phases were taken as 13 seconds, corresponding to 13x512=6656 samples. In other words, all patients' preictal, ictal, and postictal stages were taken as 13 seconds, and iEEG segments were selected as 6656 samples, and each segment was decomposed into five subbands. Then, the Shannon entropy value of each subband is calculated (Table 2).
Shannon entropy values of the five subbands of iEEG belonging to epileptic patients are shown in Tablo 2. Das et al. (2019) [43] and Yatsenko et al. (2015) [44], used the correlation techniques in their studies. In this context, the correlation values of the subband entropy values in Table 2 were calculated according to the segment entropy values. It was determined that the delta subband correlation values were higher than the other subbands.
Since the delta subband shows more regular or less chaotic properties than other subbands, scalograms of delta subband were taken and applied to the CNN model. Less chaotic data means more predictability. As the degree of chaos increases, the level of predictability of data decreases.
A channel of the iEEG data of an epileptic patient (Patient10): a) preictal, b) ictal, and c) postictal time signals of size 125 seconds; d) preictal, e) ictal, and f) postictal scalogram graphs of the delta subband of size 224x224 pixels are shown in Figure 5. The Resnet50 CNN model used in the study is shown in Figure 6. CNN's input data was generated from a total of 3300 RGB colored scalograms of the preictal, ictal and postictal delta subband at 224x224 dimensions. In the CNN model in the study, Adam optimizer was used, categorical cross-entropy was preferred for loss, and learning rate was taken as 0.001. Input data was convoluted at the 5th degree in treating the network, and a 93.33% accuracy rate was achieved. The confusion matrix obtained from the CNN model is shown in Figure 7. It is marked as preictal: spry, ictal: siy, and postictal: spoy. The best estimate is preictal, and the worst estimate is postictal.  Figure 8 shows the accuracy and loss graphs of the CNN model. This study classified preictal, ictal, and postictal phases with delta subband scalogram images consisting of low frequency iEEG data. 93.33% accuracy rate was achieved in the classification.
Entropy is a chaotic quantity expressed as a measure of the disorder of the system. A low value means that the system is less chaotic, and a high value means that the system is more chaotic. Based on this property, epileptic iEEG data was decomposed into subbands, and the entropy value of each subband was found ( Table 2). In Table 2, it is seen that the delta subband entropy values of the patients were lower than the other subband entropy values. This means that delta subbands exhibit a more regular structure. The fact that the system (data) is regular means that it is more predictable. Based on this feature, instead of the scalogram of the segment, only the scalogram image of the delta subband was found in the MATLAB environment and given as CNN input data. The writing and lines on the horizontal and vertical axes in the scalogram images obtained in the MATLAB environment were cut off without being given to the CNN input. Thus, image errors were prevented. The 224x224x3 delta subband of a channel of iEEG data of an epileptic patient (Patient 10) is shown in Figure 5.  Classification accuracy rates of epileptic EEG signals by the CNN method in various studies are given in Table 3. In the classification of epileptic EEG data with CNN, normal, preictal, ictal, and interictal stages were classified (Table 3). However, in this study, the classification of the preictal, ictal and postictal stages was made, and the classification path was taken only with scalograms of the low-frequency delta subbands. Our result can be seen lower when it is compared to some of them. But, preictal, and postictal stages shows similarities so this can negatively affect the success rate.
The segment entropy and subband entropy values of 16 patients in Table 2 were statistically tested and the results were shown in Figure 9 and 10. One-way analysis of variance (ANOVA) test was used for comparison of means and p-values<0.0001 were considered significant. The six groups on the vertical axis in Figure 9 show the mean of 1: segment entropy, 2: delta entropy, 3: theta entropy, 4: alpha entropy, 5: beta entropy, and 6: gamma entropy, respectively, of 16 patients in Table 2. It is clearly seen that the delta entropy value and the segment entropy value are close to each other, but the other groups are different. The six groups on the horizontal axis in Figure 10 show the medians of 1: segment entropy, 2: delta entropy, 3: theta entropy, 4: alpha entropy, 5: beta entropy, and 6: gamma entropy, respectively, of 16 patients in Table 2. It is clearly seen that the delta entropy value is very close to the segment entropy value.
When Table 2 is examined, it is seen that the delta entropy values are close to the segment entropy values, and the entropy values of the other subbands are different from the segment entropy values. Since delta entropy values are close to segment entropy values, it can be appropriate to use only delta subbands of epileptic iEEG signals as in this study.
In this paper preictal, ictal and postictal periods of epileptic discharge were classified by using CNN, applied to scalogram images of lower frequency (delta) bands of iEEG data and it was seen that preictal was detected with higher accuracy (Figure 7). Also, the entropy parameter, which quantitatively determines the chaos (uncertainty), was used and it was seen that the delta subband entropy values were lower than the other subband entropy values ( Table 2).
In future studies, it is aimed to focus on preictal data by using low frequency (delta) iEEG data, and to predict the seizure with high accuracy before it starts by working on changes in the preictal phase by using long-term iEEG data.

IV. CONCLUSION AND FUTURE WORK
In this study, low-frequency epileptic iEEG data was used in the classification of preictal, ictal and postictal stages, and a high-performance result (93.33%) was obtained. In our study, preictal, ictal and postictal classification was achieved by applying CNN to delta subband scalogram images, which are only low-frequency subbands, and a successful result was obtained. Also, one of the results obtained from this study is that the delta subband entropy values are significantly lower than the other subband entropy values. This indicates that the delta subband irregularity is less than the others. In other words, delta subband of iEEG signal more regular and stable. Identifying the preictal, ictal, and post ictal stages is important from the viewpoints of life safety, and distinguish epileptic seizures from the other disorders, and diseases. Therefore, further, studies which can be done, are listed below.
• Changes in the preictal phase can be examined by using long-term epileptic iEEG recordings.

Conflicts of Interest:
The authors declare no conflict of interest.