Abstract-Epileptic seizure is considered as one of the severe disorder of the nervous system. The quality of life hampered those have this disorder. An appropriate system which can detect the epilepsy will leverage the quality of life for the affected person. This paper mainly focuses on the development of a novel method to detect real-time epileptic seizure based on lightweight device such as 'Emotiv Epoc'. Weighted Permutation Entropy (WPE) value was computed to segment and extract the features. A threshold based algorithm which optimizes the battery consumption of the epoc device has also been proposed. # I. Introduction pilepsy is one of the most common disorders of the nervous system and affects people of all ages, races and ethnic backgrounds. Epileptic seizures are characterized by an unpredictable occurrence pattern and transient dysfunctions of the central nervous system, due to excessive and synchronous abnormal neuronal activity in the cortex [1]. This activity could include several neurons of different locations and sizes. The clinical symptoms of epileptic seizures might affect the motor, sensory, and automatic functions of the body along with the consciousness, cognition, and memory of the patient [2]. To diagnosis of epilepsy, EEG signal interpretation is considered as the most prominent testing tools due to painless, at a reasonable cost, and efficient temporal resolution of long-term monitoring [3]. However for long EEG recording the visual interpretation becomes an expensive, intensive and tedious errorprone exercise and also result can be vary from different neurophysiologists in same recording [4]. In a conventional system, EEG recording used to be conducted in well equipped hospitals which required equipments are at least bulky, expensive, and require professional setup and configuration. The development of several sophisticated, lightweight and accurate EEG recording devices with wireless transmission like 'Emotiv Epoc' [15] becomes more practical for epileptic patients, offer movement freedom and lowering the infection risks due to percutaneous plugs. The availability of such kind of devices open the door for smartphone based epilepsy care. Today the smartphone has the strong processing capability with high speed wireless connectivity and being extensively used even in low and middle income countries and possible to capture the seizure event and it may serve like a physician having witnessed the event. Now there arises some question such as whether it will satisfy the physician expectation or not, how faster it will give the result against the physician. In this paper we mainly focus on real-time EEG signal processing for epilepsy monitoring. Here we have designed and developed a novel method for preprocessing and classification step which is suitable for real-time epilepsy detection. Our classification algorithm is based on unsupervised learning and it needs to calibrate the system before running the detection. We also propose a method to optimize the power consumption of the portable device using motion detection algorithm. The rest of this paper is organized as follows. Section 2 discusses the review of prior work related to the use of smartphone. Section 3 details the EEG processing pipeline for our approach and its components. Section 4 presents the experimental discussion and the power optimization algorithm, followed by the conclusion in Section 5. # II. Related Work Many researches were done by using offline data form laboratory to improve the feature extraction and classification module. However, a very few real-time work was done with the live EEG data using lightweight devices. In [4], they have evaluated the presently available applications of mobile phones in the day to day care of epileptic patients as a diagnostic, prognostic and therapeutic tool. Currently a variety of apps like the 'epilepsy society app' or 'my epilepsy diary' or 'epilepsy vault' are available in the market which can be used as seizure diaries allowing the patient or the caregiver to record the basic information regarding epilepsy and its management thus increasing awareness regarding the illness. Some sensor based devices such as 'Epdetect' or 'Smartmonitor's Smartwatch' which can be used to detect a seizure in progress by using inbuilt gyroscopic sensors, accelerometers and GPS modules for detecting a seizure and locale of seizure. César et al. [5] showed the multi-centre quasiprospective assessment and evaluation of seizure prediction performance on a long-term EEG recording of 278 patients suffering from pharmaco-resistant partial epilepsy, also known as refractory epilepsy. They explained that computational intelligence techniques showed a high potential for seizure prediction. Sang-Hong Lee et al. [6] proposed new combined methods to classify normal and epileptic seizure EEG signals using wavelet transform (WT), phase-space reconstruction (PSR), and Euclidean distance (ED) based on a neural network with weighted fuzzy membership functions (NEWFM). From 24 initial extracted features, 4 minimum features with the highest accuracy were selected using a non-overlap area distribution measurement method supported by the NEWFM and this resulted in performance sensitivity, specificity, and accuracy of 96.33%, 100%, and 98.17%, respectively. An efficient feature extraction method was proposed by computing the spectral power of Hjorth's mobility components, which were effectively estimated by differentiating EEG signals in real-time [7]. They used five epileptic patients EEG data and resulted in a detection rate of 99.46% between interictal and epileptic EEG signals and 99.78% between normal and epileptic EEG signals. Their results suggest that the spectral features of Hjorth's mobility components in EEG signals can represent seizure activity and may pave the way for developing a fast and reliable epileptic seizure detection method. Noha S. Tawfik et al. [8] introduced a new automated seizure detection model that integrates Weighted Permutation Entropy (WPE) and a Support Vector Machine (SVM) classifier model to enhance the sensitivity and precision of the detection process. The WPE algorithm relies on the ordinal pattern of the time series along with the amplitudes of its sample points. They implemented and tested on hundreds real EEG signals and the performance is compared based on sensitivity, specificity and accuracy. They did various experiments in different scenarios including healthy with eyes open, healthy with eyes closed, epileptic patients during no-seizure state from two different location of the brain. Their results claimed outstanding performance and revealed promising results in terms of discrimination of seizure and seizure free segments with manifests high robustness against noise sources. In [9], the authors proposed the new features based on the phase space representation (PSR) for classification of epileptic seizure and seizure-free EEG signals. First of all EEG signals were decomposed using empirical mode decomposition (EMD) and then phase space reconstructed for obtained intrinsic mode functions (IMFs). They proposed new features based on the 2D and 3D PSRs of IMFs for classification of epileptic seizure and seizure-free EEG signals. Least squares support vector machine (LS-SVM) employed for classification of epileptic seizure and seizure-free EEG signals, and evaluated its classification performance using different kernels namely, radial basis function (RBF), Mexican hat wavelet and Morlet wavelet kernels. In this work we designed and developed a realtime EEG signal processing using Weighted Permutation Entropy based segmentation and select optimum features from time domain and frequency domain and applied the unsupervised machine learning technique to detect the epileptic seizure. We also proposed a threshold based algorithm to optimize the power consumption of the light weight weight device as Emotiv epoc. # III. Materials and Methods In our study we used CHB-MIT scalp EEG dataset which is publicly available in online [14]. This database was collected at the Children's Hospital Boston, consists of EEG recordings from pediatric subjects with intractable seizures. Subjects were monitored for up to several days following withdrawal of anti-seizure medication in order to characterize their seizures and assess their candidacy for surgical intervention. The EEG data were recorded with respect to the international standard 10-20 system. Such recordings were collected from 24 patient subjects where 5 males-aged 3 to 22, 17 females-aged 1.5 to 19 and 1 unknown. All EEG recordings were sampled at 256 Hz with 16-bit resolution. Most files contain 23 EEG signals (24 or 26 in a few cases). In general, the dataset consisted of 916 h of continuously recorded EEG and 198 seizures. All recordings of every patient were divided into 1 h length. According to the annotation files accompanying the dataset, the duration of a seizure was at least 9 s in every EEG recording while the longest seizure was about 190 s long. In this study, we took total 8 minutes where 240 s before the seizure onset for the pre-ictal state and 240 s after the seizure onset for the ictal and post-ictal states from every EEG recoding including 23 channels (figure 2(a)). The whole procedure is shown in figure 1. # a) Preprocessing To reduce the computational cost and optimize the memory, firstly we resample the EEG raw data from higher frequency to a smaller frequency 128Hz. Band pass filter and notch filter has been applied to remove the artifacts. First of all we applied low pass filter with 0.1Hz and then followed by high pass filter with 60 Hz frequency. The power line interference has been eliminated by using 50Hz notch filter. This filter has been designed according to [10], the quality factor! is calculated by (1) Here frequency f 0 at 50 Hz while the cutoff frequencies f 1 and f 2 at 49 Hz and 51 Hz, respectively. As the filtered signal still nonstationary so we segment the signal using Weighted Permutation Entropy (WPE) value which has been calculated according to [8,11]. The probability distribution of each pattern with weight ? can be represented as: (2) here is the arithmetic mean of sequence given by: (4) WPE is then computed as: (5) We then obtain individual epochs by extracting the EEG signals in a time window [V,,V-] around each event marker and this WPE value is calculated for each window; any change in the dynamics of the system will be reflected in the variation of WPE with respect to moving window. The window length VW should be greater than N! for a reliable estimation of WPE (Figure 2 The approach to epileptic feature extraction was based on mobility, Fourier transform and wavelet transform. Twenty-five time-domain features were computed for all the selected electrodes, using consecutive 5 s windows without overlap. For generating time-varying spectral features of the differentiated EEG signals, we applied Short-time Fourier transform (STFT). In the STFT analysis, the parameters of the sliding window were optimized, including the window size and the step size. Then we extracted the averaged powers ranging from 2 to 55 Hz with 2-Hz frequency resolution. For each frequency-bin, we calculated the ratio of the averaged power of differentiated signals to that of the original signals. Those calculated ratios of all frequency-bins were constructed as a feature vector into classifiers. A discrete wavelet transform (DWT) was utilized to facilitate efficient time-frequency analysis. The segmented signal is decomposed into a set of coefficients describing the frequency content at given times. According to [12], the DWT can be defined as: (6) (7) where is a smoothing operator, is the digital signal is the integral set, and and are coefficients for the corresponding low-pass and highpass filters. As the filtered signal at level i is downsampled, so we reduce the length of the signal at level i ? 1 by a factor of two and generating the detail ( ) and approximation coefficients ( ) at level i. In our work, using Daubechies 4 (DB4) we produced wavelet coefficients, including detail and approximation coefficients at levels 1-4. # c) Classification For real time scenario, there is no way to first label or train the data while analyzing live EEG. So we adopted unsupervised classification techniques. That is, these techniques only depend on the information contained in the EEG data. Considering the flexibility of the computation we used K-means clustering technique which partitions the objects into K mutually exclusive clusters, such that objects within each cluster are as close to each other as possible, and as far from objects in other clusters as possible [10,16]. Grouping similar components of a signal enables physicians to localize seizure states quickly. The K-means algorithm minimizes the within-cluster sum of squares by Lloyd iteration to make the data to the same cluster more compact and dependent: (8) (9) The central point of a cluster is recomputed as: (10) The overall k-means algorithm summarized as: 1. Initialization a. Define the number of clusters (k) b. Designate a cluster center for each cluster, typically chosen from the available data pints 2. Assign each remaining data pint to the closet cluster centre. That data point is now a member of that cluster. 3. Calculate the new cluster centre from equation (10). 4. Calculate the sum of within-cluster sum of squares from equation (8). If this value has not significantly changed over a certain number of iterations, stop the iterations. Otherwise, go back to step 2. # IV. Experimental Results We have divided the data as healthy (N), interictal (I) and epileptic (E). According to section 3 we have preprocessed and extracted features. These extracted features then fed to the k-means clustering algorithm and we analyzed the results. Our results showed 97.6 % accuracy. Figure 4 showed the different error rate after applying k-means clustering technique. The statistical measurement showed in Table 1. Y -Z D [ = ? ] Y -Z^( D [ ? 2 >', à- Z D [ = b ] ]?d Y -Z^( D [ ? 2 >', ?- Z a -Z D [ , `? e ? ] b ] d i a i f = g(D > , h 3 ) i3 3<, ] ><, g D > , h 3 = (D > ? h 3 ) - ] 3<, h 3 = , i3 D j?i k The Euclidean distance between the ith data point and the jth centroid is defined as follows: Emotiv Epoc device has limited battery life. We have developed a threshold based algorithm which will optimize the battery life (Figure : 3). In this case, user first needs to place his/her smartphone in arm using an arm hand. Then we will use the inbuilt motion sensor to check the frequency of the body movement. If the frequency movement fall under 2-5 Hz then we consider it as an ongoing seizure and we turn on the epoc device for 10 minutes. After 10 minutes the device will turn to sleep mode and send an acknowledgement to smartphone. So the smartphone is again becoming sensing mode and checking the body movement as described above. # V. Conclusion Monitoring of epilepsy is considered a very challenging activity which requires a set of technical and essential processes including continuous acquisition of EEG signals, pre-processing, feature extraction and selection, seizures detection and classification and continuous visualization of the obtained results. The main contribution of this article lies in developing and implementing an automatic, efficient and scalable approach to monitor the unpredictable occurrence of epileptic seizures in a reasonable time. Our experimental results showed the feasibility to apply our technique in lightweight device such as Emotiv epoc. ![Towards Automated Epileptic Seizure Detection for Lightweight Devices through EEG Signal Processing Noor Mohammad ? , Shamim Ara ? , Mst Rafiatul Jannat ? & Ding Shifang ?*](image-2.png "K") ![Towards Automated Epileptic Seizure Detection for Lightweight Devices through EEG Signal Processing](image-3.png "K") 1![Figure 1: Flow diagram of this work.](image-4.png "Figure 1 :") ![(b)).](image-5.png "") 1Towards Automated Epileptic Seizure Detection for Lightweight Devices through EEG SignalProcessingD D D D ) K(PrecisionRecallF-MeasureROC AreaClass0.980.9850.9830.999N0.970.970.970.997I0.980.970.9750.999E © 2017 Global Journals Inc. (US) Volume XVII Issue 1 Version I © 2017 Global Journals Inc. (US) Year 2017 © 2017 Global Journals (US) Volume XVII Issue 1 Version I © 2017 Global Journals Inc. (US) Year 2017 * Incidence of epilepsy: A systematic review and meta-analysis ANgugi SKariuki CBottomley IKleinschmidt JSander CNewton Neurology 77 10 2011 * Epilepsy Management at Primary Health Level in rural China: WHO/ILAE/IBE, Demonstration Project * Analysis of EEG signals under flash stimulation for migraine and epileptic patients SAkben ASubasi DTuncel Medical Systems 35 2011 * Man Mohan Mehndiratta, Application of mobile phones in epilepsy care Lakshmi Narasimhan Ranganathan BalasubramanianSomasundaram Aadhimoolam Chinnadurai BhanuSamivel Kesavamurthy International Journal of Epilepsy 2213-6320 2 1 January-June 2015 * Epileptic seizure predictors based on computational intelligence techniques: A comparative study with 278 patients BrunoCésar Alexandre Teixeira MojtabaDireito MichelLeBandarabadi MarioVan Quyen BjoernValderrama AndreasSchelter VincentSchulze-Bonhage FranciscoNavarro AntónioSales Dourado Computer Methods and Programs in Biomedicine 0169- 2607 114 3 May 2014 * Classification of normal and epileptic seizure EEG signals using wavelet transform, phase-space reconstruction, and Euclidean distance Sang-HongLee JoonSLim Jae-KwonKim JunggiYang YounghoLee Computer Methods and Programs in Biomedicine 0169-2607 116 1 August 2014 * An efficient detection of epileptic seizure by differentiation and spectral analysis of electroencephalograms Jae-HwanKang Yoon GiChung Sung-PhilKim Computers in Biology and Medicine 0010-4825 66 1 November 2015 * A hybrid automated detection of epileptic seizures in EEG records SNoha Tawfik MSherin MohamedYoussef Kholief Computers & Electrical Engineering 0045-7906 28 September 2015 * Classification of epileptic seizures in EEG signals based on phase space representation of intrinsic mode functions, Expert Systems with Applications RajeevSharma RamBilasPachori 15 February 2015 42 * An automatic mobile-health based approach for EEG epileptic seizures detection, Expert Systems with Applications MohamedEl Menshawy AbdelghaniBenharref MohamedSerhani 15 November 2015 42 * Weighted permutation entropy: a complexity measure for time series incorporating amplitude information BFadlallah BChen AKeil JPrincipe Phys Rev 87 2013 * Zero crossings of a wavelet transform SMallat IEEE Trans. Inf. Theory 37 4 1991 * Wavelet basis functions in biomedical signal processing JRafiee MARafiee NPrause MPSchoen Expert Syst. Appl 38 2011 * Application of Machine Learning to Epileptic Seizure Onset Detection and Treatment AliShoeb September 2009 Massachusetts Institute of Technology PhD Thesis * Emotiv EPOC / EPOC+ * Unsupervised Classification of Epileptic EEG Signals with Multi Scale K-Means Algorithm, Brain and Health Informatics GuohunZhu YanLi (Peng ShuaifangPaul) Wen NingWang Zhong 10.1007/978-3-319-02753-1_16 October 29-31, 2013 8211 * Copyright Holder Springer International Publishing Switzerland