ESTIMATION OF PAIN THRESHOLD FROM EEG SIGNALS OF SUBJECTS IN PHYSICAL THERAPY USING LONG-SHORT-TERM MEMORY DEEP LEARNING MODEL

: Pain is a natural stimulation to protect the whole body. An overreaction to pain can damage the tissues. Therefore, it is important to know the angle at which pain is felt when routinely measuring joint range of motion during the first examination. Detection of pain with the change in characteristics of electroencephalogram signals at the moments when pain occurs is the novelty of this study. The characteristics of the signal with power band changes were obtained by frequency analysis of the electroencephalogram signals. Pain was detected by classifying these characteristics with the Long Short Term Memory deep learning model. Validation of the model was performed with records obtained from 43 volunteer subjects with a 14-channel wireless Emotive brand electroencephalogram device. 96.1% success in binary classification as with pain or without pain and 89.6% success in multi-class classification as with high pain, low pain and without pain was achieved. This success is a quality that can support specialists in diagnosis and treatment by determining the threshold where pain occurs during the first physical therapy examination from the electroencephalogram signals. 14-channel EEG device at various shoulder openings. Labeling was done by obtaining information from the subject whether there was pain or not in the shoulder span. Welch method, periodogram estimation method (PEM) and Multitaper frequency analysis method were used to obtain the features of the labelled signals. Feature vectors containing power spectral density values between 1-49Hz were obtained by these methods. Feature vectors were trained with the Long-Short Term Memory (LSTM) deep learning model. The highest test success was achieved with the LSTM model, which was trained with the feature vectors obtained by the Welch method. The success rate was 96.1% in binary classification and 89.6% success in multi-class classification.


INTRODUCTION
Physical therapy and rehabilitation is a medical specialty that helps treat subjects whose mobility and functional abilities are lost or weakened (Veerbeek et al., 2014). One of the areas of interest of this specialty is shoulder pain. When a subject with shoulder pain goes to physical therapy, joint range of motion (ROM) measurement is performed at the first examination. Joints are moved with ROM and it is checked whether there is any restriction in the subjects' joints. Pain occurs in the subjects at certain angles in ROM measurement.
Pain is a return mechanism from physical or mental injury. Excessive pain causes tissue damage (Kim et al., 2004). If a subject intentionally or unintentionally forces himself more than necessary during the ROM measurement in physical therapy, it may cause tissue damage due to pain. Determining the pain threshold in the measurement of ROM in subjects in physiotherapy treatments will help prevent tissue damage in the subject and find the angle of pain for the physiotherapist. The aim of the study is to determine the angle at which pain occurs from electroencephalogram signals. When a person feels pain, there is a temporal-parietal decrease in the alpha power band of electroencephalography (EEG) signals and the activation of brain areas associated with pain is indexed (Schulz et al., 2015). These increases and decreases in Power Spectral Density (PSD) values can be measured by EEG signals . Studies are carried out with EEG signals. In these studies, it has been proven by finding increasing power amplitudes in alpha and theta signals when pain occurs in humans (Kisler et al., 2020). In another study, it was proved that the gamma signal in the brain is related to pain (Gross et al., 2007). In line with these studies, brain signals are needed to find the pain. Pain can be detected digitally by training brain signals with artificial intelligence (Vanneste et al., 2018).
In this study, EEG signals were recorded with Emotive 14-channel EEG device at various shoulder openings. Labeling was done by obtaining information from the subject whether there was pain or not in the shoulder span. Welch method, periodogram estimation method (PEM) and Multitaper frequency analysis method were used to obtain the features of the labelled signals. Feature vectors containing power spectral density values between 1-49Hz were obtained by these methods. Feature vectors were trained with the Long-Short Term Memory (LSTM) deep learning model. The highest test success was achieved with the LSTM model, which was trained with the feature vectors obtained by the Welch method. The success rate was 96.1% in binary classification and 89.6% success in multi-class classification.
The main contributions of this study are as follows. 1. In physiotherapy treatments, determining the pain threshold in the measurement of ROM in subjects will be helpful in preventing the tissue damage that occurs when the subject strains himself, and finding the angle of pain for the physiotherapist. 2. The change caused by pain in the brain signals with EEG can be noticed in the computer environment and the presence of pain can be predicted. 3. Determination of the pain threshold from EEG can support the experts in this field in preventing tissue damage, diagnosis and treatment. The rest of the paper is organized as follows: A brief state of art of the proposed method is given in Sect. 2. The material and methods about the proposed pain detection method is described in Sect. 3. Findings and discussion of the proposed approach are presented in Sect. 4. Finally, Sect. 5 concludes the paper.

RELATED WORKS
There have been many studies conducted in recent years. In these studies, the emergence of situations with pain from EEG signals was examined. Especially by monitoring the changes in the signals, the determination of the period in which the pain occurred from the EEG scans could be followed in relation to the power change in the signals. Panavaranan et al. (2013) performed acute heat stimulation pain assessment of EEG signals using fuzzy logic and polynomial kernel function support vector machine. In this study, thermal pads were applied to 9 healthy people to cause pain. The thermal pad is created around 50 degrees. The created pain was taken from the brain by EEG. The power spectrum of the data is taken with fast Fourier transform (FFT). The core support vector machines (SVM) was used to estimate the pain level of the power spectrum data and a success rate of 73.3% was achieved (Panavaranan et al., 2013). Chen et al. (2017) applied a neural decoding approach to determine the onset of acute thermal pain in awake rats based on neural brain activity in the primary somatosensory cortex and anterior cingulate cortex. Their methods achieved 85.4% performance in sensitivity and specificity (Chen et al., 2017).
Nurhan et al. (2017) investigated whether music classification could be a computer interface. In this study, 3 different people are asked to make 7 different movements. These movements were made to stand still, solve mathematical operations, dream of moving right hand and left hand, animation of letters. A classical and rock music listening movement. They achieved 100% success from these data classified with artificial intelligence (Nurhan et al., 2017).
Camfferman et al. (2017) investigated on subjects with chronic pain, and investigated that pain intensity was associated with alpha wave band and theta wave band. Provided waking EEG data of 103 people with chronic pain. Their findings revealed that decreases in alpha bandwidth power affected chronic pain intensity but not theta bandwidth (Camfferman et al., 2017).
In the study conducted by Cao et al. (2018) resting state was discovered on EEG before migraine attacks. The aim of the study is to determine the pain in the stomach with EEG. Using the prefrontal electroencephalogram complexity with the support vector machine classification model, the highest accuracy was determined as 76% in classifying interracial and parietal phases In the study by Cao et al. (2020) frequency domain analysis in sudden pain was aimed with EEG. As a data set, 29 healthy participants, consisting of 17 men and 12 women, between the ages of 20 and 30, were subjected to pain to the extent that they could withstand the laser. The experiment lasted for 3 minutes, 1.5 minutes without pain and the other 1.5 minutes painful. When the pain experienced by the participants were compared with the pain signals appearing on the EEG, an accuracy of 84.3% was achieved (Cao et al., 2020).
In another study, the DFB-based ConvNets model proposed by Yu et al. (2020) can classify three tonic pain classes. These are No Pain, Moderate Pain, and Severe Pain. First, the proposed method uses various frequency band-based inputs to learn temporal representations from different frequency bands of the Electroencephalogram (EEG), which is expected to have more discriminating power. The derived features are then combined to form a feature vector that is fed into a fully connected network to perform the classification task. The experimental results show that the method proposed by the authors distinguishes the tonic cold pain states with 91.37% success (Yu et al., 2020).

MATERIAL AND METHODS
The method developed consists of 3 main stages. It is shown in Figure 1. First, the range of motion is measured on the subject's aching shoulder. The subject's brain signals are obtained at each situation which are with high and low pain and without pain. Then, EEG signals from 14 channels are divided into 3-second segments. The PSD values are calculated by PEM, Welch and Multitaper methods for each segment. At the last stage, the feature vectors that include PSDs of EEG signals are classified by the LSTM model.

Acquisition of Brain Signals
EEG records in this study Simav Assoc. İsmail KARAKUYU was taken from the volunteers who applied to the State Hospital. EEG data of 43 volunteer subjects, 9 females and 34 males, aged 18-50 with shoulder pain complaints were used for the dataset of the study. Under the supervision of an expert, EEGs were taken on the subjects at the first examination at different angles of joint movements. These data are labeled as painful, less painful and very painful by the specialist. Clinical ethics consent was obtained from the Clinical Research Ethics Committee of Kütahya Health Sciences Institute with the decision dated 30.09.2020 and numbered 2020-05 / 06. Placement of EEG electrodes on the heads of selected volunteers was made according to the International 10/20 system electrode placement. EEG data were recorded according to this location. Figure 2 shows the international 10/20 system electrode placement. The aim of this system is to divide the head from length to length into intervals of 10% or 20% of the distances of the bones in the head. A line system is prepared with this section and electrodes are placed at the intersections of this system (Hu et al., 2020). In this order, EEG electrodes are placed on the volunteer's head. EEG signals are obtained by the voltage difference between these electrodes.

Figure 2:
International 10/20 system electrode placement (Homan et al., 2018) In our study, a 14-channels Emotiv Epoc EEG device was used. In addition to the 14 channels of the device, there are 2 reference electrodes placed at the P3 and P4 points and 2 more electrodes placed at the Common Mode Sense (CMS) and Driven Right Leg (DRL) points. The device has 18 electrodes in total. The purpose of the P3 and P4 electrodes is to allow the flow of low electrical current that the other electrodes of the device can measure. CMS and DRL electrodes placed behind the ears have a grounding effect. These 4 electrodes cannot be used to acquire the EEG signal. Accordingly, the Epoc device has exactly 14 separate EEG channels. The Epoc device can provide raw EEG data with a sampling frequency of 128 Hz and a resolution of 0.5128 micro Volts (Emotive Epoc, 2014). In this study, dual classification and multi-class classification were made with ROM measurement routinely performed during the first examination for subjects who came to the physical therapy unit for shoulder pain. For dual classification, whether the subject had pain or not was determined from the EEG signals. In multi-class classification, it was determined from the EEG signals that the subject did not have pain, was present, and was more. The experimental protocol is as follows.
In binary classification; Figure 3a as shown in the section between 0-10 seconds, the subject is painless. Figure 3b as shown in the section, the subject is painful between 10-20 seconds.
In multi-class classification; Figure 3a as shown in the section between 0-10 seconds, the subject is painless. Figure 3b as shown in the section, the subject is painful between 10-20 seconds. Figure 3c as shown in the section, the subject is very painful between 20-30 seconds.  Table 1 shows the data sets allocated for LSTM learning, LSTM validation, and LSTM testing. There are 904 data sets in total for binary classification. 452 of these data sets consist of painless data sets obtained between 0-10 seconds of the experiment, and 452 of them consist of painful data sets obtained between 10-20 seconds of the experiment. Three classifications were performed in multi-class classifications. The total data set is 1014. 338 of these data sets consist of painless data sets obtained between 0-10 seconds of the experiment, the other 338 from painful data sets obtained between 10-20 seconds of the experiment, and the other 338 from very painful data sets obtained between 20-30 seconds of the experiment. 60% of these data sets were taken and LSTM was trained. For the accuracy and testing of LSTM, 20% of the data sets not provided in education were given to LSTM. Different data sets were given to the training, verification and testing of LSTM not to memorize. Figure 4 shows the graph of the first state of the EEG signal taken from the subject. In fact, since the EEG device used in the study has 14 channels, there should be 13 more than the above signal, but in this study, the average of 14 channels was taken and made as a single channel. During the recording of the raw EEG signals, 30-second shots were taken from the subjects. Of these 30 seconds, 10 seconds are painless, 10 seconds are low pain, and the last 10 seconds are high pain.

Figure 4: Segmented 10 Seconds Raw EEG signal
On the graph, signals between 0 and 1280 are painless and normal, these signals are flat and smooth. At the signals between 1280 and 2560, the subject feels pain by applying ROM movement. These signals show a little wave. Between 2560-3727, a lot of pain was applied to the subject.

Extraction of Power Spectral Densities from EEG signals
Three different power spectrum methods were applied to the signals obtained in the two classifications. In this way, the attributes of the signals come out. In order to calculate the power spectral density of the EEG signal using the Welch method, the EEG signal should be divided into frames such as 64, 128 and 256 to be the power of 2. Thus, its variance is reduced.
The representation of the power spectral density of the Welch method is given by the formula in Equation1. (1) In Equation 1, L indicates the length of the sign (Özmen et al., 2015). A 1014x49 feature matrix was created with the Welch method, which was first applied from PSD. 3 distinctive features of these features are shown in Figure 5 below.

Figure 5: Power spectral density chart with Welch method (with pain, Low pain and High pain)
The PEM is applied directly to EEG signals. This is because there is no assumption about the EEG signal. It is the most basic form of extraction of signals and power spectra . The spectral density of the PEM is calculated by Equation 2.
In Equation 2, φ(w) is the power spectrum density, N is the number of samples of the signal, y (t) is the spectrum of the signal, and in w the frequency with the power spectrum density. The 1014x49 matrix feature was created by the PEM applied from the power spectra. 3 distinctive features of these features have been selected and shown in Figure 6 below. In my Multitaper or Multiple Refined Estimation method, the filter set method is applied to the EEG signal, then a few filters are added and the average of this signal is taken (Das and Babadi, 2020). The spectral density of the Multitaper method is calculated by Equation 3.
In Equation 3, K is the number of filters to be used and ℎ − is the filter impulse. With the Multitaper method applied from the power spectra, the feature with a 1014x49 matrix was created. 3 distinctive features of these features have been selected and shown in Figure 7 below.

Figure 7:
Power spectral density graph with Multitaper method (with pain, Low pain and High pain)

Classification with LSTM Model
LSTM (Long-Short Term Memory) algorithm, one of the artificial intelligence methods, was used to classify the values of the PSDs. Since artificial neural networks are compared to biological neural networks, the information processing processes are the same. Information is processed through neurons and signals are transferred to each other. The transmitted signal has a weight and activation function (Saeedi et al., 2020). LSTM networks belong to the recurrent network architecture (Ertam, 2019). The LSTM deep learning model is used extensively in signal processing studies in recent years. Since LSTM has short and long term memory units, it shows more successful results in signal classification studies compared to other methods (Nath et al., 2020).
As seen in Figure 8, LSTM network architecture repeats its cycle each time and creates a network shape connected to each other. In this way, successful results are obtained in signal classification studies in LSTM (Kara, 2020).

FINDINGS and DISCUSSION
In this study, the features derived from the power spectrum methods of EEG signals were labelled according to their state and applied to the LSTM deep learning algorithm for classification. The presence of pain at the end of the training was determined from the EEG signals. It was evaluated whether the experiments made the accurate classification or not. In the test data with known labelled PSD values, the performance of the classification model is validated according to the sensitivity, specificity, sensitivity, accuracy rate, f1 score and Matthew's correlation coefficient (MCC). The f1 score and Matthews's correlation coefficient are a widely used measure for binary classification success in machine learning. The f1 score is basically the harmonic mean of the system's predicted rate and its true rate. The MCC is basically the correlation coefficient between the actual rate of the system and the predicted rate.
Three different power spectrum methods were applied to the signals obtained in binary and multi-class classifications. These power spectra; welch, PEM, Multitaper methods. The EEG records taken from the subject for the ROM measurement have been transferred to the computer environment. The EEG device recorded 128 data per second separately for 14 channels. The data obtained were divided into test, validation and training data and transferred to LSTM.
LSTM compared the results of the given training data with the test data and extracted the accuracy rate. Since the dual classification takes 20 seconds, an average of 2560 data were recorded from each volunteer subject. Since multi-class classification takes 30 seconds, an average of 3840 data were recorded from each volunteer subject. It is made like a single channel by taking the average of the channels. The maximum number of records that could be taken individually was recorded for 43 volunteer subjects. 3 different power spectrums of the data created by these records were taken, and matrices of 1x49 were obtained. For our first experiment, a total of 904 matrices of 1x49 were formed. 452 of these matrices are painless data and the other 452 are pain data as a result of ROM measurement. In the data transferred to LSTM, labeling was made as normal and painful. The hyper-parameter values obtained for the best classification performance were obtained as epoch number 50, iteration number 800, mini batch size 32, validation frequency 20, gradient threshold 1 and initial learn rate 0.5. In the first experiment, the success of the LSTM training result of the Welch applied data was 96.1225%, the test result success was 96.1326%, and the validation accuracy was 95.58%. In the second experiment, the success of the LSTM training result of the data on which the PEM was applied was 84.508%, the test result success was 81.7680%, and the validation accuracy was 81.22%. In the third experiment, the success of the LSTM training result of the Multitaper applied data was 73.8007%, the test result success was 76.2431%, and the validation accuracy was 73.48%.
For multi-class classification, a total of 1014 matrixes of 1x49 were formed. Of these matrices, 338 are painless data, the other 338 are pain caused by ROM measurement, and the last 338 are data that the volunteer subject felt a lot of pain as a result of ROM measurement. The data applied to the LSTM were labeled as normal, painful and very painful. LSTM Epoch number 50, iteration number 950, mini batch size 32, validation frequency 20, gradient threshold 1, initial learn rate 0.5. In the fourth experiment, the success of the LSTM training result of the Welch applied data was 91.4474%, the test result success was 89.6552%, and the validation accuracy was 86.70%. In the fifth experiment, the success of the LSTM training result of the data on which the PEM was applied was 64.3092%, the test result success was 61.0837%, and the validation accuracy was 61.58%. In the sixth experiment, the success of the LSTM training result of the Multitaper applied data was 60.69%, the test result success was 66.50%, and the validation accuracy was 62.56%.
In both classifications, better results were obtained in the welch method. After the Welch method, the best results were obtained with the PEM and the worst results were obtained with the Multitaper method. Better results were obtained in the first experiment than in the second experiment. This is because the classification number increases from 2 to 3. As a result of all experiments, the LSTM training and test success of the experiments is calculated according to the power spectrums in Figure 9.
PSD values tend to increase when pain occurs. The increase in pain intensity resulted in an increase in the strength measured in the signal. The headache of multiple classification of pain severity as low and high proved this result. The increase in signal strength with pain was measured by PEM, Welch and Multi taper methods. The results obtained in the measurements obtained by each method are presented in Table 2. The sensitivity, specificity, sensitivity, f1 score, Matthew's coefficient, and AUC of the power spectrum of the experiments are shown in Table 2. Welch-1, Periodogram-1, and Multitaper-1 shown in both are power spectra of binary classification. Welch-2, Periodogram-2, and Multitaper-2 are PSDs of multi-class classifications.

Figure 9: Training and test achievements of the six experiments
When we examine the training and test achievements of the power spectrum of the classifications in Figure 9, the most accurate results and the best estimation in both classifications were made with the welch method in 3 different power spectrums. When PSD change graphs are examined, pain and power change in EEG signals appear more clearly in the PSD values obtained by the Welch method. This is because there is not much difference in numerical size between the painless part and the very painful part. Since the interval is very clear in PEM and Multitaper methods, it cannot be clearly distinguished. In Table 2, the sensitivity, specificity, sensitivity, f1 score, Matthew's coefficient, and AUC of the PSD values of the experiments were calculated with the help of confusion matrices. The accuracy rate in classifications has been tested in accordance with the properties obtained with the confusion matrix. Sensitivity, specificity, sensitivity, f1 score, Matthew's coefficient ratio are directly proportional to LSTM training success and test success rates. In the first experiment, the sensitivity rate of the Welch method was lower than that of the PEM. This is due to the fact that, in the classification of the Welch method, both presumably and in reality, people with pain are less than those with all estimated pain. In multi-class classification, precision and sensitivity rates were given to express the test success of each class. When these ratios were examined, it was observed that the power values obtained by the Welch method were more successful in classification. It was proven in experiments that a more successful classification was achieved by applying the features obtained by the Welch method to the classifier containing LSTM cells in "low pain" and "high pain" classes.

CONCLUSION
In this article, we propose the feature extraction method by which PSD values are obtained by frequency analysis for pain recognition. Multi-channel EEG records of the EEG data set obtained from the subjects who applied to the hospital are used for comparison and the results of previous studies are compared with the recommended frequency analysis-based method. Pain is classified as binary and multi-class with the LSTM deep learning model, which is trained with 1-49Hz PSD values obtained by the PEM, Welch method and Multitaper method. Three different PSD methods were discussed in the study to measure the power level in the signal when pain occurs. These methods are PEM, which provides direct PSD acquisition of the signal, Welch method that enables PSD to be obtained with overlap, and Multitaper methods that allow PSD to be calculated by averaging many occurrences of the same event. In the experiments conducted, it was observed that the Welch method, which is the PSD method obtained with overlap, had very successful results. Especially in the distinction between high pain and low pain, the Welch method contributed to more successful results than other methods. The results show that the classification of PSD values obtained by the Welch method with LSTM shows that our method performs better in pain classification. 96.1% success in binary classification and 89.6% success in multi-class classification were obtained from the data of volunteers who applied to the hospital. Therefore, it is possible to analyze the pain by separating it from EEG signals.

CONFLICT OF INTEREST
The author(s) confirm that there is no known conflict of interest or common interest with any institution/organization or person.