An Algorithm To Measure The Stress Level From EEG, EMG and HRV Signals
An Algorithm To Measure The Stress Level From EEG, EMG and HRV Signals
net/publication/340400142
An Algorithm to Measure the Stress Level from EEG, EMG and HRV Signals
CITATIONS READS
0 282
4 authors, including:
Carlos A Almenara
Universidad Peruana de Ciencias Aplicadas (UPC)
48 PUBLICATIONS 188 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
The Breast Size Satisfaction Survey: An International, Collaborative Project View project
All content following this page was uploaded by Carlos A Almenara on 23 July 2020.
Abstract— This work proposes the analysis in time and Subhani et al. proposes for example an algorithm in [1]
frequency of EEG and EMG waves with the purpose of obtaining oriented to differentiate between a state of stress and a state
stress states in 5 levels. Due to the advance and evolution of of relaxation by analyzing brain waves in two channels. In
technology, it is possible to obtain low-cost brain-computer
this case, an accuracy of 93.4% was achieved. However, the
interfaces with greater ease in neurofeedback sessions, which, in
turn, helps to reduce stress levels in individuals and this requires a method is limited to discerning two states (stressed and
deeper analysis due to a scarce investigation. Different studies are relaxed) and does not allow results to be obtained at
limited to only obtaining binary results, that is to say, if an multiple levels.
individual is in a state of stress or not, but they do not present Similarly, the paper presented by Richer et al. in [2]
results in a scale of levels. We analyzed 6 EEG channels with a proposes an algorithm that analyzes the power of the
sampling frequency of 250 Hz following the 10-20 standard and 1 frequency bands of brain signals. However, they achieve an
EMG channel decomposed in the time and frequency domain
accuracy no greater than 83% by differentiating between a
obtaining parameters with the discrete wavelet transform and
energy per band. The parameters obtained from each signal were state of stress and a state of relaxation.
entered into a k-NN classifier. In the same way, for the validation, Amores et al., on the other hand, proposes in [3] a method
the stress level was established by the graphic analysis of the heart to detect the level of relaxation of an individual on several
rate variability following Baevsky's method, following with the scalesby the analysis of electroencephalogram waves (EEG).
measurement of the relaxation and stress of differents students However, they do not specify the precision of the proposed
while subjecting them to psychotechnical tests. The proposed method and use subjective relaxation perception methods
algorithm was able to differentiate in most cases and quantify the for the validation of the stress leve lof an individual.
states, reaching an accuracy level of 92%.
Wang et al. in [4] proposes an algorithm to differentiate
Keywords— EEG, EMG, HRV, stress, wavelet transform, k-NN, between a state of relaxation or meditation and a state of
Baevsky stress index. stress using a brain-computer interface. In this case, an
accuracy of 90.3% was achieved. However, like some of the
I. INTRODCTION above methods, it is limited to differentiating only two
states.
Stress in people is caused by work, studies, economic
Liu et al. on the other hand proposes in [5] a method to
problems and family problems among others, and it affects
detect between a state of attention or relaxation obtained by
their welbeing causing deterioration in mental and physical
brain waves of students. However, this study was less than
health of the individual.
80% accurate and is limited to only two states of mind.
For this reason, it is becoming increasingly necessary to
The studies conducted by Al-Shargie et al. in [6] and [7]
develop methods, procedures and technological tools to
propose a method for determining the stress level of an
quantify the level of stress of people, so that specialists,
individual quantified at multiple levels from EEG waves. In
through biofeedback sessions, can obtain more reliable
the first study, an accuracy of 86.3% was achieved by
information to achieve a more efficient control of the
differentiating three stress levels, and in the second study,
problem and thus achieve greater welbeing of the individual.
accuracy was improved to 94.79%. However, this method is
At present, the procedure used by specialist and
limited to an analysis with few levels to differentiate.
psychologists to determine a person's state of mind is
Karthikeyan et al. in [8] presents a novel algorithm to
carried out by means of perceptual tests that are subjective,
determine a person's stress level from electromyographic
since they depend on the experience of the specialist and the
(EMG) signals measured in the trapezium muscle,
willingness of the patient to collaborate. This method can
differentiating between four levels with an accuracy of
cause an erroneous diagnosis of the patient's condition and,
90.7%. However, the proposed method does not specify the
therefore, a treatment that does not generate improvement
procedure or the index used to measure the accuracy
and well-being.
obtained and only works with four levels of stress.
In the scientific literature several proposed methods have
Finally, the process carried out by Ahani et al. in [9] used
also been found with limitations in the precision and the lack
2 physiological signals to measure a person's stress level,
quantifitaction levels of the stress level.
obtaining an accuracy of 85% for 2 states and an accuracy of
78% when differentiating in multiple levels. This novel
method uses the analysis of EEG and breathing signals to module allows the simultaneous measurement of different types
determine the degree of stress presented by the person. of biomedical signals such as EEG, EMG and ECG; it also
However, the low accuracy of this method prevents a correct works with a resolution of 24 bits per sample or 0.02235 µV per
analysis for specialists and quantifies stress on a scale of level.
three levels at most. In the acquisition process, data was obtained from 20
The method proposed in this work presents the novelty volunteers in the age range of 20 to 30 years who practice
of using parameters extracted simultaneously from EEG and meditation at a basic, intermediate or advanced level. The
EMG signals in order to find the stress level of an individual process is based on a protocol that consists of closing the eyes
while meditating. The EMG signals are obtained from the for 15 minutes by adapting an upright posture while seated (see
involuntary movements of the left trapezium in order to Fig. 2). The meditation period is delimited by the use of a tingsha
detect the stress level on a five-level scale. In addition, in the at the beginning and at the end of the session. Because the
present work the five levels established by the stress index objective is to measure involuntary movements caused by stress
were used, extracted from the graphical analysis of the on the trapezium muscle, the patient is asked to avoid moving
variation of the cardiac pulse (HRV), which is an objective the arms. In addition, the measurement of the heart rate is also
measure to quantify the stress of an individual. affected by the movement, so this requirement is essential.
All this solves the subjectivity in obtaining the stress level, Data collection is performed (measuring brain signals)
which is obtained by traditional methods, such as surveys or following the international 10-20 standard at points Fp1, Fp2,
long term examinations. T6, T7, O1 and O2 with Ag-AgCl dry electrodes. The
The 2 types of signals are processed and analyzed offline reference and ground are placed at points A1 and A2 as shown
through the algorithm proposed in this paper. The algorithm in Fig. 3 [11].
extracts characteristic parameters from both signals and Frontal points are chosen because of their large variation in
then submits them to a classifier to obtain the stress level. beta waves which increase with a state of stress and relaxation
The computational tool developed can be used by specialists [9]. The temporal and occipital points represent great
variation of theta waves as shown in [9] and finally, alpha
in order to improve the effectiveness of their diagnoses and
waves are reflected with greater intensity in the temporal and
know if the method used is the right one.
occipital points as concluded in [12].
The results obtained were validated using the reference
stress level obtained from the HRV. The results show an
accuracy in the detection of the stress level of 92%.
(a)
From (1) the threshold 𝑇𝐸𝐸𝐺𝑖,𝑗 is determined for each For the elimination of the DC component and the baseline
sub-band resulting from the decomposition tree: wandering, the coefficients of the sub-band 7.0 were set to zero
i.e. 𝑤7,0 (𝑛) = 0. This sub-band corresponds to the frequency
range from 0 to 0.98 Hz.
𝑇𝐸𝐸𝐺𝑖,𝑗 = 𝛿𝑖,𝑗 √ln(𝑁𝑖,𝑗 ) (2) Then the signal is finally reconstructed with the
corresponding reconstruction tree [16].
Where 𝑁𝑖,𝑗 is the total number of samples from sub-band Subsequently, in order to reduce the noise, a threshold was
𝑖, 𝑗. applied to the sub-band coefficients of the second level 𝑤2,1 (𝑛)
Finally, the threshold coefficients are obtained from the since this corresponds to the frequency band in the range
following expression: [31.25Hz, 62.5Hz] and therefore contains the 60 Hz component
induced by the electrical network.
𝑣𝑖,𝑗 (𝑛); |𝑣𝑖,𝑗 (𝑛)| ≥ 𝑇𝐸𝐸𝐺𝑖,𝑗 The type of threshold chosen is soft obtained from the
𝑣 ′ 𝑖,𝑗 (𝑛) = { (3) following expression:
0;|𝑣𝑖,𝑗 (𝑛)| < 𝑇𝐸𝐸𝐺𝑖,𝑗
𝑤 ′ 𝑖,𝑗 (𝑛)
The coefficients 𝑣 ′ 𝑖,𝑗 (𝑛) other than zero are estimated to be
𝑠𝑖𝑔𝑛(𝑤𝑖,𝑗 (𝑛)) ∙ (|𝑤𝑖,𝑗 (𝑛)| − 𝑈𝑖,𝑗 ); 𝑤𝑖,𝑗 (𝑛) ≥ 𝑈𝑖,𝑗 (4)
free of noise and distortion. Therefore, they more reliably ={
0;𝑤𝑖,𝑗 (𝑛) < 𝑈𝑖,𝑗
reflect the characteristics of EEG signals.
It is important to note finally that the sub-band 𝑣5,0 (𝑛) was
In this case 𝑤′𝑖,𝑗 (𝑛) is the threshed wavelet coefficient,
not taken into account in all the processing that was applied
to the EEG signals. This is because this sub-band contains the 𝑤𝑖,𝑗 (𝑛) is the wavelet coefficient of the sub-band to be threshed
unwanted DC component that is present in the acquired EEG and 𝑈𝑖,𝑗 the value of the threshold.
signals. The threshold value is obtained from the rigorouse SURE
(rigrsure) algorithm which generates an adaptive threshold
based on the Stein risk estimation principle [17]. This method
D. EMG signal improvement was chosen because it gives the best results compared to other
Like the EEG signals, these signals have induction noise from types of thresholds [18].
the mains and a DC component. The wavelet denoising method
was also used to solve this problem.
In this case the decomposition tree to obtain the wavelets sub- E. EEG feature extraction
bands of interest is similar to the one shown in Fig. 5 with 7 The EEG classification parameters are obtained from the
levels of decomposition. normalized energies of the sub-bands using the following
The wavelet used in this case was the wavelet "coif5". expressions:
The wavelets coefficients of the resulting sub-bands are 𝜃𝑙
𝜃𝑙′ =
defined in this case as 𝑤𝑖,𝑗 (𝑛). 𝜃𝑙 + 𝛼𝑙 + 𝛽𝑙 (5)
𝛼𝑙 Russian astronauts before and after performing emotionally
𝛼𝑙′ =
𝜃𝑙 + 𝛼𝑙 + 𝛽𝑙 (6) demanding missions [20].
After the analysis of the HRV, the parameters explained in the
𝛽𝑙 previous points are obtained and stored in a matrix of the same
𝛽𝑙′ = (7) size as the vector of the level obtained by the stress index that
𝜃𝑙 + 𝛼𝑙 + 𝛽𝑙
are obtained in the same instants of time.
Once the parameters and the corresponding level are obtained,
In this case𝜃𝑙 , 𝛼𝑙 , and 𝛽𝑙 correspond to the energies of theta a k-NN classifier is used to determine the stress value from the
waves (𝑣5,1 (𝑛)), alpha (𝑣4,1 (𝑛)), and beta (𝑣3,1 (𝑛)) EEG and EMG signals.
respectively. The subscript 𝑙 indicates the position of the For each person, a classifier is trained so that the level obtained
measured EEG points: Fp1 (𝑙 = 1), Fp2 (𝑙 = 2), T6 (𝑙 = 3), T7 corresponds to the unique changes an individual present.
(𝑙 = 4), O1 (𝑙 = 5), and O2 (𝑙 = 6). This implies that the The 20 trained classifiers present an accuracy of 92% in the
parameter extraction procedure is applied on the EEG wave determination of the 5 levels. The levels that represented the
obtained from each of the 6 points. This resulted in a total of 18 greatest error are 1 and 5 because they are at the extremes of the
EEG parameters for classification. normal distribution. Figs. 6 and 7 show the stress index obtained
by the HRV analysis and the index obtained with the classifier
for one of the participants. It is observed that the index found by
F. EMG feature extraction the proposed method has a high correlation with Baevsky's
In this process, the 4-level decomposition proposed in [8] was reference index.
used as a reference. However, since this method uses a sampling
frequency of 500Hz which is twice the frequency used in the
present work (250Hz), we opted for a 2-level balanced tree
wavelet packets decomposition.
This decomposition verifies that the most important
information is in the range of 0 - 32.5 Hz.
To characterize the information located in that band, the
minimum, maximum, mean, standard deviation, power, energy
and entropy are extracted from the corresponding coefficients.
G. Classification
A k-NN classifier (k-nearest neighbors) is used in which 25
EEG and EMG parameters are introduced as inputs to obtain the
stress level. The order of the classifier with which the best result
was obtained in terms of precision was 3. The classifier was
trained following the mindfulness protocol. This protocol
establishes that the participant must meditate for 15 minutes in
a seated position with closed eyes. During this time, the left arm Fig. 6. Stress level obtained with HRV analysis.
should not be moved because the aim is to measure the
involuntary movements of the trapeium.
Together with the EEG and EMG electrodes, a pulse sensor
is placed on the index finger of the left arm to measure the
variability of the heart rate. As stated in [19], the minimum time
to obtain the stress level from the heart pulse is 100 seconds, so
we opted for a window that covers that time and consists of a
number of samples that is a power of two for optimization of the
algorithm. That is why a window of 32768 samples is chosen,
equivalent to 131 seconds with a sampling frequency of 250 Hz.
After obtaining the data with the OpenBCI software, the
generated file is analyzed and the features corresponding to each
signal is extracted. First, the cardiac pulse is analyzed and the
time between pulses is obtained. These values are stored to
obtain the variability of the HRV heart rate and then analyzed
graphically to obtain the Baevsky’s index (which will be
Fig. 7. Stress level obtained with the classifier.
explained in detail in the validation process). The use of this
index is due to the objectivity of the physiological signals as
opposed to the values obtained through perceptual tests. That is
why it has been used in studies to detect the presence of stress in
III. RESULTS To find the accuracy of the proposed algorithm, SVM and k-
The level of stress in people is reflected in signals from the NN classifiers were trained. In this case, a higher percentage of
sympathetic and parasympathetic nervous system that regulate accuracy was obtained with the k-NN classifiers, so this type of
the changes in the different bioelectric waves. classifier was chosen.
In this context, heart rate variability (HRV) is an important
reference measure as it directly reflects the level of stress from
the graphical analysis of the RR intervals of the ECG wave (time
period between R waves). Histograms with bin widths of 50 ms
and RR time periods of 0.4 and 1.3 seconds [21] are used for the
analysis. The relationship between height in percent and width
of the intervals establishes the stress index 𝑆𝐼 proposed by R. M.
Baevsky in [22]. This index is expressed as:
𝐴𝑀𝑜
𝑆𝐼 = (8)
2 × 𝑀𝑜 × 𝑀𝑥𝐷𝑀𝑛
Where 𝐴𝑀𝑜 is the amplitude of fashion in percent, 𝑀𝑜 is the Fig. 8. Accuracy percentage of each patient.
fashion expressed in seconds and 𝑀𝑥𝐷𝑀𝑛 is the range of the
interval of RR values expressed in seconds. All these values are The accuracy of the classifier is obtained from the following
obtained from the histogram of the RR periods [22]. expression:
For a normal state of rest the value of 𝑆𝐼 is between 50-150 𝑇𝑃 + 𝑇𝑁
𝐴𝑐𝑐 = (9)
c.u. (arbitrary units) [22]. 𝑇𝑃𝑂𝑃
Table II shows the range of stress index values for each level.
Each of them is associated with a state of the person's emotional Where 𝑇𝑃 is the number of true positives (representing the
state: state of relaxation (low level), normal state (normal level), number of hits), 𝑇𝑁 is the true negatives (representing the
state of medium emotional stress caused by a low mental or number of correct rejections of the classifier), 𝑇𝑃𝑂𝑃 is the total
physical load (moderate level), state of high stress caused by number of tests performed and 𝐴𝑐𝑐 is the accuracy of the stress
significant mental or physical loads (high level) and a state of level in the test. Since the confusion matrix is multivariable, then
very high stress caused by very high emotional or physical loads the true positives and negatives correspond to the diagonal
that could trigger illnesses if kept in that state for a prolonged where the predicted and expected values coincide. Finally, in
time (very high level) as specified by R. M. Baevsky in [23]. order to find the total accuracy of the classifier per person, the
average of the 5 levels is obtained.
TABLE II. STRESS INDEX (𝑆𝐼) INTERVALS Fig. 8 shows a graph of the accuracy obtained by each patient.
Level 𝑺𝑰 Note that an average percentage of 92% is obtained in the
Very High ≥500
accuracy of the classifier.
High 300 – 500
Moderated 150 – 300
In the cases in which the measurement presents a low
Normal 50 – 150 accuracy, it is due to the fact that the individual had some
Low ≤50 movement during the data acquisition.
Tables III, IV, V, VI and VII take as an example the confusion
matrices of 5 of the 20 participants. The columns represent the
To determine the stress level, HRV values are used as
expected values obtained from the HRV analysis and the rows
reference values. These values are then mapped to the 5 levels
represent the results obtained from the classifier with the EEG
shown in Table II. This involves moving from quantitative to
and EMG parameters. As it can be seen, the diagonal of
qualitative valuation.
coincidences is where the classification stress levels is applied
The process seeks to obtain objective values rather than using
correctly and the other cells represent the classification errors.
perception tests based on subjective interpretation. The analysis of the diagonal of coincidence in relation to the
The PulseSensor module, which emits an analog signal and a other cells shows the efficiency of the classifier used, for
green light to measure the variation of blood volume changes, example, if the great majority of values are in this diagonal, it
was used to measure the heart rate. This equipment was modified can be said that the method used can correctly predict the
with a thin layer of silicone on the conductive tracks of the green expected values.
LED, as the contact of the 5V signal with the skin interfered with As mentioned above, the diagonal of hits corresponds to the
the measurement of the other signals. true positives. The true negatives, in this case, are not present in
The sensor is placed on the index finger of the left hand and the matrix, since we want to find the accuracy of all levels.
immobilized with a velcro strap attached to the finger. The Therefore, the accuracy in the classification of the stress level in
sensor output is placed on an auxiliary analog input of the Cyton patients 4, 8, 12, 18 and 19 is 94%, 96%, 85%, 96% and 94%
with a resolution of 16 bits per sample. respectively.
• The validity of the classifier is tested with 30% of the
remaining data with Cohen's kappa index and accuracy.
Predicted
(k-NN)
Values
3 0 12 1415 19 0
4 0 0 15 310 14
Fig. 9. Kappa coefficient of each patient. 5 0 0 0 3 30
Cohen's kappa coefficient is another statistical measure that TABLE IV. CONFUSION MATRIX OF PARTICIPANT 8
represents the concordance between predicted and expected
Values obtained from HRV
values. The equation for finding the kappa coefficient is defined (Stress Index)
in (10). Where ∑𝑉𝐸 is the sum of the expected values of each 2 3 4 5
1
level, which is defined in (11), and 𝑘𝑎 is Cohen's Kappa 81 15 0 8 0
1
coefficient. The 𝑉𝐸 value is a measure of the expected number 2 4 310 38 2 0
Predicted
(k-NN)
of hits and is calculated in each of the cells of the hit diagonal.
Values
3 0 26 1667 32 0
In (11) it is defined as finding the expected value of hits for each
4 0 0 20 340 2
level, where ∑𝑅𝑜𝑤 is the sum of all the values in the row of the
5 0 0 0 1 53
cell of the level to be measured and ∑𝐶𝑜𝑙 corresponds to the sum
of the values of the column. In the same way as in the case of
TABLE V. CONFUSION MATRIX OF PARTICIPANT 12
accuracy, the kappa coefficient is calculated for each patient and
the values 0.89, 0.92, 0.67, 0.91 and 0.89 respectively are Values obtained from HRV
(Stress Index)
obtained. Fig. 9 shows a graph of the kappa coefficient for each
participant and obtains an average value of 0.83, which indicates 1 2 3 4 5
that the values predicted by the classifier have high concordance 1 18 8 0 0 0
with the values obtained with the 𝑆𝐼, the value of 1 being a 2 10 294 16 0 0
Predicted
(k-NN)
Values
(k-NN)
Values
the validation of the classifier and the algorithm used are 3 0 15 1649 41 0
summarized in the following points: 4 0 0 28 356 2
• The band with the 6 dry electrodes is placed around the 5 0 0 0 1 38
head, 2 gel electrodes are placed on the left trapezium,
and finally the pulse sensor is attached to the index of the TABLE VII. CONFUSION MATRIX OF PARTICIPANT 19
left hand. Values obtained from HRV
• The data is stored while the individual meditates by (Stress Index)
taking an upright, sitting posture without movement for 1 2 3 4 5
15 minutes. 120 18 2 0 0
1
• The data is processed, and 18 EEG wave parameters and 2 39 107 17 0 0
Predicted
(k-NN)
Values
Please cite:
Ugarte, D. E., Linares, D., Kemper, G., & Almenara, C. A. (2019). An algorithm to measure the stress level from EEG, EMG
and HRV signals. In 2019 International Conference on Information Systems and Computer Science (INCISCOS) (pp. 346–
353). Quito, Ecuador: IEEE. https://doi.org/10.1109/INCISCOS49368.2019.00061