Quantification of Pain using EEG and Fuzzy Logic Amit Kumar1, Amod Kumar2 and Kanika Sharma3 1,2,3 Department of Electronics and Communications Engineering, NITTTR Chandigarh (India Abstract This paper aims to quantify and calculate the pain level of the volunteers experienced during cold pressure test with the help of electroencephalogram (EEG). The experiment was done on 20 volunteers having age group of 20 to 60 years. The EEG of 20 people was taken in normal (No Pain) condition and in Pain state. The pain was induced by cold pressure test. The acquired EEG contains noise and other artifacts which were removed with the help of filters. Various features of EEG signal were extracted. Three features viz. amplitude (RMS value), Power Spectral Density (PSD), and Higuchi fractal Dimension (HDF) responded well to pain and had the ability to separate pain and non-pain signals efficiently. These three parameters were fed as input to a fuzzy inference system (FIS). Fuzzy rules were made very carefully after experimentation at different pain levels. The output of FIS is the pain index ranging from 0 to 10, where 0 is for No Pain, 5 is for Medium Pain, and 10 is for High Pain. Keywords Pain estimation, EEG, Power Spectral Density (PSD), Higuchi Fractal Dimension (HDF), Fuzzy Logic, Fuzzy Inference System (FIS) 1. Introduction The estimation of pain is a major problem for the physicians since many years. It is very difficult to assess the pain level of deaf, children, patients in ICU, paralyzed patients, semi anaesthetized patient, and patients who can’t communicate due to some injuries or suffer from mental health problem. Generally, automated pain intensity detection is very beneficial for low Glasgow comma scale (GCS) for measurement of consciousness level [1].For patients who cannot communicate about their pain level with physician, there is urgent need of pain detection device so that doctors can treat their patient with the right amount of dose [2]. During surgery, analgesic drug is given to the patient to alleviate pain. But in some cases, surgery takes long time and the patient does feel pain but he cannot speak out because he is paralyzed. With the help of pain detection device, physician can easily monitor patient’s pain level and accordingly, analgesic drug can be given whenever required [3]. Similarly, children or patients with mental problem are also not able to tell how much pain they are feeling [4]. Then there are some criminals who try to fake pain in court to escape hearing of their case. ICU patients are given sedatives to tolerate the pain level for their comfort [5] [6] but there is no pain detection device to measure their pain. The pain is the unpleasant sensation to body due to inflammation or tissue damage [7].1It can be detected by many methods. First method for pain detection is by verbal communication to the patient [8]. We can ask the patient about the grade of his pain i.e. very high pain, low pain, or having no pain at all. But this method fails when the patient is deaf, ICU patient, or children etc. who cannot communicate. Second method of pain detection is by heart rate variability. It can be done with the help of electrocardiogram (ECG). When the patient feels pain, it causes variation in the heart rate; this variation is calculated with the help of the ECG and thus, pain can be detected [9] [10]. But problem with this method of pain detection is that the heart rate is a fragile parameter, ready to undergo change International Conference on Emerging Technologies: AI, IoT, and CPS for Science & Technology Applications, September 06–07, 2021, NITTTR Chandigarh, India EMAIL: amit.jngec123@gmail.com (A. 1); csioamod@yahoo.com (A. 2); kanikasharma80@yahoo.com (A. 3) ORCID: 0000-0002-9212-0266 (A. 1); ©2021 Copyright for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY 4.0). CEUR Workshop Proceedings (CEUR-WS.org) on the slight pretext. It cannot be relied upon for diagnosing any non-cardiac event. Third method of pain detection is by analyzing facial expressions [11]. But problem with this method is that there are some patients who are in coma or ICU and are not able to give expressions [12]. One of the most effective methods of pain detection is EEG based. Whenever patients feel pain, its sensation goes directly to brain. The brain signals are reflected in EEG. In this work, pain was induced in volunteers and EEG signals were acquired. It was filtered using low pass filter to remove noise and other artifacts [13]. Various time-domain and frequency-domain features were extracted. Their efficacy was evaluated vis-à-vis pain sensation [14] [15]. Those parameters which showed excellent correlation with pain were selected to estimate the pain index. These parameters, being imprecise in value, were given to a fuzzy inference system whose output was a crisp number corresponding to Pain Index. In place of fuzzy logic we can use KNN (K- Nearest Neighbors), SBS (Sequential Back Selection), SVM (Support Vector Machine) [16], and Neural Network techniques as a classifier. However, Fuzzy Logic classifier is easy and efficient method of EEG signal classification [13]. 2. Material and Method In the experiment, 20 volunteers in the age group of 20 to 60 years (male +female) were included. These volunteers were teetotaler and non-smoking. The weight of volunteer ranges from 45 to 80 Kg, the experiment was performed on 32 channel EEG machine (Recorders and Medicare System, Chandigarh, India). The data format was 24 bit and sampling rate was 1024 samples/sec. There were 8 electrodes which were placed at different position of brain viz. Fp1, Fp2, C3, C4, P3, P4, Ground, and Reference. These EEG electrodes were in the shape of cup and made up of silver (Ag) and silver chloride (AgCl) [17]. The EEG was taken using EEG machine and analyzed on AD Instrument Lab Chart. The EEG of volunteers was taken first in normal state i.e. No Pain condition. Then EEG of patient is taken in Pain state. The pain is produced by using cold pressure method [18]. In this test, ice cube of size 4.5 × 3 × 1.8 cubic centimeters were added to 3 liter water baths and right hand of volunteer was dipped into it to generate pain. With the passage of time, the volunteer felt pain and thus EEG in pain condition was recorded. This process was repeated for every volunteer [14].During this, they were asked the pain level verbally which was marked so that later EEG signals at different level can be recognized. The schematic of the signal processing is shown in Figure 1. The flowchart appears in Figure 2. Figure1: The schematic of signal processing. • EEG in Pain and Non Pain condition: The EEG of every volunteer is taken in Pain and No- Pain condition. For inducing pain, the cold pressure method is used. • Artifact removal and Filtering of EEG signal: Raw EEG recorded with the help of the EEG machine setup contains noise and other artifacts due to eye blinking, 50-60 Hz electrostatic interference, muscle contraction or expansion etc. To get clean EEG signal, these unwanted signals must be removed. Raw EEG signal was passed through a notch filter of 50 Hz and a low pass filter with a cut-off frequency of 70 Hz. This reduced electrostatic interference and noise significantly. If EEG signal is badly affected then adaptive filtering can also be used [19]. Figure 2: Flowchart of operation. • Feature Extraction: The EEG data was divided into epochs of 4seconds each. Various parameters were calculated for these epochs. Linear discriminant analysis was applied to identify parameters which were highly related to pain. Table 1 gives the list of these parameters. Table 1 Calculated EEG parameters S.No. Calculated Comments Parameter 1 RMS Value Root mean square value of every epoch 2 Power Spectral Measure of signal irregularities in frequency domain Density 3 Higuchi Fractal Calculation of fractal dimension of a time series directly in Dimension time domain The method of calculation of above parameters is given below: 1. RMS value: RMS is the Root Mean Square value of signal. It can be calculated as: 1 RMS = ∑ N i xi2 (1) where, N = the number of measurements and xi = the sample amplitude value. 2. Power Spectral Density: Spectral Density (PSD) describes the distribution of the signal power with frequency. The significant frequency components of signal which can be considered for further study is decided by its Power Spectral Density (PSD). It is determined by using Welch’s method. In this method first periodogram is calculated and then PSD is calculated by taking average of periodogram as described below in equation 4 and 5. 1 Periodogram = |𝐹𝐹𝐹𝐹𝐹𝐹|2 (2) 𝑀𝑀𝑀𝑀 Where, U is the normalization factor and M is the window hop size. Welch’s estimate of PSD is given as: Power Spectral Density (PSD) = S(f)= average (Periodogram) (3) 3. Higuchi Fractal Dimension (HFD): In 1988, Higuchi published a research paper on nonlinear measurement of magnetic field change which was based on fractal theory [16]. However, this method is sensitive to noise and other random signals. Therefore, for getting good results, artifacts and other noise random signals must be removed efficiently from EEG signal. The various steps for determination of HFD of a time series x(1), x(2), ……. x(N) are: Step 1: The new time series is generated by using the equation: 𝑘𝑘 𝑁𝑁−𝑚𝑚 𝑥𝑥𝑚𝑚 = �𝑥𝑥(𝑚𝑚), 𝑥𝑥(𝑚𝑚 + 𝑘𝑘), 𝑥𝑥(𝑚𝑚 + 2𝑘𝑘). . . . . . . . 𝑥𝑥(𝑚𝑚 + � �)𝑘𝑘� (4) 𝑘𝑘 m = 1, 2, 3, 4….k where, m is the initial time and k is the initial time interval respectively.In this way, there will be k new time series. Step 2: Calculate average length of each new time series Lm (k ) which can be calculated as:   N − m    1   k      N − 1  Lm (k ) =  ∑ x(m + ik ) − x(m + (i − 1)k )   (5) k  i =1  N − m    k     k    This process is repeated for almost all values of k from 1 to k max . N is the number of samples. In some research papers, it was taken as 11 or 17 or 25 but in this study the value of Kmax is taken 6and N ≥125 because at this value accurate and faster algorithm for fractal dimension is obtained [20]. Step 3: The mean length of the actual time series is calculated as the average of Lm (k ) by the equation: Mean length=Average [ Lm (k ) ] (6) The Fractal dimension of the signal is obtained as the slope of the curve ln(Mean length) vs. ln(1/k) by using the polynomial curve fitting method [21]. • Classification of pain Once all the above features are calculated for various EEG epochs, the next step is to feed these parameters as input to the classifier. There are many classifiers available viz. KNN, SBS (Sequential Backward Search), SVM (Sequential Vector Machine), Neural Networks, Fuzzy Inference System (FIS), and PKSVM (Polynomial Kernel Support Vector Machine)) etc [22]. All these classifiers except Fuzzy Inference System need large amount of data. As we have EEG data of only 20 patients so we made use of Fuzzy Inference System (FIS). FIS is easy to use and gives reliable and accurate results. In this work, “Mamdani” type of FIS is used with trapezoidal (trapmf) membership functions. The FIS containing three inputs viz. RMS, Power Spectral Density and Higuchi Fractal Dimension is schematically shown in Figure 3. All these inputs are processed by the fuzzy rule set mentioned in Table 2. Figure 3: Fuzzy Inference System with Input, Mamdani, and Output state. The design of rules was done as follows: Rule 1: If two or more input parameters show a high pain value then it is considered as high pain. Rule 2: If two or more input parameters show a medium pain value then it is considered as medium pain. Rule 3: If two or more input parameters show a low pain value then it is considered as low pain. Rule 4: If all parameters show different pain levels then it is taken as medium pain. It must be kept in mind that the RMS and Power Spectral Density are directly correlated with pain level while HFD is inversely correlated with pain. Table 2 The rule base used in fuzzy inference system (FIS).Calculated EEG parameters. Rule RMS Value Power Higuchi Output No. Spectral Fractal Pain Density Dimension Index (PSD) (HFD) 1 Low RMS Low PSD Low HFD Low Pain 2 Medium RMS Low PSD Low HFD Medium Pain 3 High RMS Low PSD Low HFD High Pain 4 Low RMS Medium PSD Low HFD Medium Pain 5 Medium RMS Medium PSD Low HFD Medium Pain 6 High RMS Medium PSD Low HFD High Pain 7 Low RMS High PSD Low HFD High Pain 8 Medium RMS High PSD Low HFD Medium Pain 9 High RMS High PSD Low HFD High Pain 10 Low RMS Low PSD Medium HFD Low Pain 11 Medium RMS Low PSD Medium HFD Medium Pain 12 High RMS Low PSD Medium HFD Medium Pain 13 Low RMS Medium PSD Medium HFD Medium Pain 14 Medium RMS Medium PSD Medium HFD Medium Pain 15 High RMS Medium PSD Medium HFD Medium Pain 16 Low RMS High PSD Medium HFD Medium Pain 17 Medium RMS High PSD Medium HFD Medium Pain 18 High RMS High PSD Medium HFD High Pain 19 Low RMS Low PSD High HFD Low Pain 20 Medium RMS Low PSD High HFD Low Pain 21 High RMS Low PSD High HFD Low Pain 22 Low RMS Medium PSD High HFD Low Pain 23 Medium RMS Medium PSD High HFD Medium Pain 24 High RMS Medium PSD High HFD Medium Pain 25 Low RMS High PSD High HFD Low Pain 26 Medium RMS High PSD High HFD Medium Pain 27 High RMS High PSD High HFD Low Pain There are a total of 27 rules that were made to quantify the pain level of the patient. IF part of the rule is the premise and THEN part is the consequent. Membership functions for RMS value are shown in Figure 4 with Low, medium, and high values ranging from 0.05 to 0.15, 0.14 to 0.25, and 0.23 to 0.5 respectively. Figure 5 shows the membership functions for PSD having low, medium, and high value of PSD ranging from 0.001 to 0.014, 0.015 to 0.02, and 0.02 to 0.08 respectively. Figure 6 shows the low, medium, and high value of HFD ranging from 1.25 to 1.4, 1.38 to 1.48, and 1.45 to 1.6 respectively. These values are taken based on the experiment done and parameters calculated. Figure 7 shows the membership functions of the output i.e. the Pain Index. The crisp Pain Index shows the pain in the range 0 to 10, 0 for the No Pain, and 10 for High Pain (extreme). Figure 8 shows Pain rating scale Figure 4: Membership functions for RMS value Figure 5: Membership functions for PSD Figure 6: Membership functions for HFD Figure 7: Membership functions for Pain Index Figure 8: Pain rating scale. • Verification of Result After processing the inputs and defuzzyfying the output, crisp value of “Pain Index” is obtained. The Pain Index has a range of values from 0 to 10. Output 0 is for Low Pain, 5 is for Medium Pain, and 10 is for High Pain. The result obtained can be verified by comparing calculated result to the actual verbal pain estimation. 3. Result and Discussion The raw EEG is obtained by using EEG machine. The electrostatic noise is removed by passing it through a notch filter of 50 Hz as can be seen in Figure 9. Figure 9: Raw and notch-filtered EEG signal. Figure10: EEG signal after passing through LPF Passing signal through a low pass filter, clean EEG output is obtained which is shown in Figure 10. All the parameters viz. RMS value, PSD, and HFD were calculated in both pain and no-pain states. All these parameters are shown below in Figure 11-13. Figure 11: RMS value of one of volunteer EEG. Figure12: PSD of one of the volunteer’s EEG Figure 11 shows the typical RMS values of the EEG signal. The hard line shows Pain Condition and dotted line shows Normal or No-Pain state. The maximum value achieved is 0.5 (High Pain) and lowest value achieved is 0.05 (Low Pain). It can be seen that RMS parameter of EEG has great ability to separate the Pain and No-Pain signals from each other. Low values show low pain while high values show the high pain states. Figure12 shows the PSD of one of the volunteers. The continuous line shows the Pain Condition and dotted line shows the Normal or No-Pain Condition. The maximum achieved value of PSD is 0.08 corresponding to Normal or No-Pain Condition and 0.001 for High Pain condition. Figure 13 shows HFD parameter values of the EEG. The hard line) shows the Pain condition of the volunteer and dotted line shows the Non Pain or Normal Condition of the patient. It is clear that Pain and No-Pain signals are clearly separated by HFD parameter. In this case, the lowest value obtained is 1.25 (High Pain) while highest value is 1.6 (Low Pain).One caution that must be kept in mind is that Higuchi’s method only works at very low noise. Large noise signals may not give desired results. However, it is considered one of the best parameters for the analysis of biomedical signals. Based on the above-mentioned parameters, a fuzzy rule base was made. All these input parameters are given to FIS. The FIS processes them on the basis of fuzzy rule base. Figure 13: HFD of one of the volunteer’s EEG. The fuzzy rule check is shown in Figure 14. The output Pain Index has three ranges- High Pain, Medium Pain, and Low Pain. In Figure14, when RMS parameter has a value of 0.392 (High Value), PSD has a value of 0.01966 (Medium value) and HFD has a value of 1.31(Low value), the firing of rules and the resulting defuzzified output can be seen. After defuzzification was done by the Centroid Method, the crisp output Pain Index obtained is 8 (High Pain). The output obtained for the FIS was got confirmed by patients at different levels of pain. Figure 14: Fuzzy Rule check for output Pain Index. 4. Conclusion At present, there is no scientifically proven pain estimation technique. By conventional methods, pain of a patient is not determined with accuracy and still there are some irregularities and limitations in these methods. The EEG based method is very promising for the pain detection. High accuracy is achieved by this technique because the extracted pain defining parameters are highly sensitive to pain. One point to be kept in mind is that to achieve high accuracy, noise and artifacts must be removed to the maximum possible extent from the EEG signal. Fuzzy inferencing is probably the best classification technique when the data is limited. In fact, more accurate classification techniques like neural networks or tree based methods would not achieve better results here because there is no Gold standard method available for pain measurement which can help learning of these classification methods. Impreciseness of the pain scale having rating from 0- 10 from no pain to high pain goes well with Fuzzy inferencing. The designed system can be used in Operation Theatre (OT) so that underdose or overdose of analgesic dose can be avoided. It may also be used by the physicians to diagnose and treat diseases associated with pain. Subjects with chronic pain should be separately investigated since EEG recording in the non-pain state is not accessible in such cases. Further work is required in this area to investigate the efficacy of the technique in case of different pain sources. Before testing the system clinically, it must be evaluated by simulating pain externally through different methods e.g. with the help of a pin, by giving thermal or mechanical stress to the human body, etc. 5. Acknowledgment The authors would like to thank Director, National Institute of Technical Teachers Training and Research Chandigarh, India for his inspiration and support throughout this research work. 6. References [1] Wright, “An update of systemic analgesics in children,” Anaesthesia & Intensive Care Medicine, 2019. [2] Sourav Dey Roy, Mrinal Kanti Bhowmik, Priya Saha, Anjan Kumar Ghosh, “An Approach for Automatic Pain Detection through Facial Expression”, 7th International Conference on Intelligent Human-Computer Interaction, IHCI 2015, Procedia Computer Science, Vol. 84, pp. 99 – 106, 2016. [3] Patrick Lucey, Jeffrey Cohn, Simon Lucey, Iain Matthews, Sridhar, Kenneth M. Prkachin, “Automatically Detecting Pain Using Facial Actions”, 3rd International Conference on Affective Computing and Intelligent Interaction and Workshops, IEEE, 2009. [4] Panagiotis A. Bonotis; Dimosthenis C. Tsouros; Panagiotis N. Smyrlis; Alexandros T. Tzallas; Nikolaos Giannakeas; Evripidis Glavas, Markos G. Tsipouras,“Automated Assessment of Pain Intensity based on EEG Signal Analysis Panagiotis”, IEEE 19th International Conference on Bioinformatics and Bioengineering (BIBE),2019. [5] Sunil Belur Nagaraj, Lauren M McClain, Emily J Boyle, David W Zhou, Sowmya M Ramaswamy, Siddharth Biswal, Oluwaseun Akeju, Patrick L Purdon, and M Brandon Westover, “Electroencephalogram based Detection of Deep Sedation in ICU Patients Using Atomic Decomposition”, IEEE Transactions on Biomedical Engineering, 2018. [6] J. W. Devlin, “The pharmacology of oversedation in mechanically ventilated adults,” Current opinion in critical care, vol. 14, no. 4, pp. 403–407, 2008. [7] "The need of taxonomy", International Association for the Study of Pain, Vol. 6 (3): 24, PMID 460931. [8] Pranti Dutta I and Nachamai M,“Facial Pain Expression Recognition in Real-Time Videos”, Hindawi Journal of Healthcare Engineering, Article ID 7961427, 23 pages, 2018. [9] Jeffrey Tadashi Sakamoto, Nan Liu, Zhi Xiong Koh, Dagang Guo, Micah Liam Arthur Heldeweg, Janson Cheng Ji Ng, Marcus Eng Hock Ong, “Integrating heart rate variability, vital signs, electrocardiogram, and troponin to triage chest pain patients in the ED”, The American Journal of Emergency Medicine, Volume 36, Issue 2, Pages 185-192,February 2018. [10] Nan Liu, Dagang Guo, Zhi Xiong Koh, Andrew Fu Wah Ho, Feng Xie, Takashi Tagami, Jeffrey Tadashi Sakamoto, Pin Pin Pek , Bibhas Chakraborty, Swee Han Lim, Jack Wei Chieh Tan, Marcus Eng Hock Ong,“Heart rate n-variability (HRnV) and its application to risk stratification of chest pain patients in the emergency department”, BMC Cardiovascular Disorders, 20:168,2020. [11] M. Omidyeganeh, A. Javadtalab, O.S. Shirm, “Intelligent driver drowsiness detection through fusion of yawning and eye closure”,IEEE International Conference on Virtual Environments Human-Computer Interfaces and Measurement Systems, Ottawa, Canada, 2011. [12] J.F. Cohn, Z. Ambadar, P. Ekman, “Observer-based measurement of facial expression with the facial action coding system”, in: J.A. Coan, J.B. Allen (Eds.), The Handbook of Emotion Elicitation and Assessment, Oxford University Press Series in Affective Science, Oxford University Press, New York, NY, pp. 203–221, 2007. [13] Sanjeev Kumar, Amod Kumar, AnjanTrikha, Sneh Anand,“Electroencephalogram based Quantitative Estimation of Pain for Balanced Anaesthesia”, ELSEVIER Measurement, Vol. 59, pp. 296-301, 2015. [14] Sanjeev Kumar, Amod Kumar, AnjanTrikha, Sneh Anand, Prashanth Gantla, “Higuchi fractal dimension as a measure of analgesia”, International Journal of Medical Engineering and Informatics, Vol. 4, No. 1, pp. 66-72, 2012. [15] SrdjanKesić, Sladjana Z. Spasić, “Application of Higuchi's fractal dimension from basic to clinical neurophysiology: A review”, Computer Methods and Programs in Biomedicine, Vol. 133, pp. 55-70, 2016. [16] Raja Majid Mehmood, Hyo Jong Lee, “Emotion Classification of EEG Brain Signal Using SVM and KNN”, IEEE. ISBN: 978-1-4799-7079-7, 2015. [17] Sinclair C.M., Gasper M.C., Blum A.S., “Basic Electronics in Clinical Neurophysiology”, In: Blum A.S., Rutkove S.B., editors. The Clinical Neurophysiology Primer. Humana Press; Totowa, NJ, USA, pp. 3–18, 2007. [18] Guillaume Lamotte, Christopher J. Boes, Phillip A. Low &Elizabeth A. Coon, “The expanding role of the cold pressor test: a brief history”, Clinical Autonomic Research volume 31, pp. 153– 155, 2021. [19] He P., Wilson G., Russell C., Gerschutz M., “Removal of Ocular Artifacts from EEG: A Comparison of Adaptive Filtering Method and Regression Method Using Simulated Data”, Proceedings of the IEEE 27th Annual Conference on Engineering in Medicine and Biology; Shanghai, China, 17–18 January 2006. [20] A. Accardo, M. Affinito, M. Carrozzi, F. Bouquet, “Use of the fractal dimension for the analysis of electroencephalographic time series”,Biology and Cybernetics, Vol. 77 (5), pp. 339– 350,1997. [21] MontriPhothisonothai and Masahiro Nakagawa, “Fractal-Based EEG Data Analysis of Body Parts Movement Imagery Tasks”, Journal of Physiology Science, Vol. 57, No. 4, pp. 217–226, 2007. [22] PradkijPanavaranan, Yodchanan Wongsawat, “EEG-based Pain Estimation via Fuzzy Logic and Polynomial Kernel Support Vector Machine (KSVM)”, Biomedical Engineering International Conference (BMEiCON-2013), 2013.