#  Online Mental Stress Detection using Frontal-channel EEG Recordings in a
Classroom Scenario

Chi-Yuan Chang, Chieh Hsu, Ying Choon Wu, Siwen Wang, Darin Tsui and Tzyy-Ping
Jung, This work was supported in part by a research contract from Facebook, a
gift fund, KreutzKamp TMS RES F- 2467, to TPJ, the Army Research Laboratory
(W911NF-10-2-0022) and the National Science Foundation (DUE-1734883).C.-Y.
Chang is with Harvard Medical School and Beth Israel Deaconess Medical Center,
Boston (BIDMC).Y.-C. Wu and T.-P. Jung are with Dept. of Bioengineering (BIOE)
and Swartz Center for Computational Neuroscience (SCCN) of the University of
California, San Diego (UCSD).

###### Abstract

Objective: To investigate the effects of different approaches to EEG
preprocessing, channel montage selection, and model architecture on the
performance of an online-capable stress detection algorithm in a classroom
scenario. Methods: This analysis used EEG data from a longitudinal stress and
fatigue study conducted among university students. The students’ self-reported
stress ratings during each class session were the basis for classifying EEG
recordings into either normal or elevated stress states. We used a data-
processing pipeline that combined Artifact Subspace Reconstruction (ASR)and an
Independent Component Analysis (ICA)-based method to achieve online artifact
removal. We compared the performance of a Linear Discriminant Analysis (LDA)
and a 4-layer neural network as classifiers. We opted for accuracy, balanced
accuracy, and F1 score as the metrics for assessing performance. We examined
the impact of varying numbers of input channels using different channel
montages. Additionally, we explored different window lengths and step sizes
during online evaluation. Results: Our online artifact removal method achieved
performance comparable to the offline ICA method in both offline and online
evaluations. A balanced accuracy of 77% and 78% in an imbalanced binary
classification were observed when using the 11-frontal-channel LDA model with
the proposed artifact removal method. Moreover, the model performance remained
intact when changing the channel montage from 30 full-scalp channels to just
11 frontal channels. During the online evaluation, we achieved the highest
balanced accuracy (78%) with a window length of 20 seconds and a step size of
1 second. Conclusions: In this study, we present an EEG-based algorithm for
online mental stress detection. It incorporates an artifact removal pipeline
that combines ASR with an ICA. The algorithm employs an 11-frontal-channel LDA
model, showcasing promising potential for real-world stress monitoring
applications. Significance: This study comprehensively investigates the
deployment of stress detection in real-world scenarios. The findings of this
study provide insight into the development of daily mental stress monitoring.

###### Index Terms:

Mental Stress Detection, Online Artifact Removal, Electroencephalography, Low-
density channel array, ASR, ICA.

##  I Introduction

Stress is a reaction elicited when the demands from the environment exceed the
coping capacity of an organism, resulting in physiological and biological
adaptive responses related to fight or flight. [1]. These demands are called
stressors and can be further categorized into physical/ environmental or
mental/ task-related stressors [2]. In our daily lives, we face various
challenges and experience different levels of mental stress. However, people
usually underestimate the effect of mental stress on well-being, both
physically and mentally. When experiencing low-level stress, people might
suffer from upset stomachs [3], dizziness [4], increased heart rate [5], or
muscle tension [6]. As stress levels increase, the symptoms can become more
severe. Further, researchers have linked mental stress to various health
issues, such as immune disorders [7], obesity [8], and heart disease [9].
Additionally, individuals subject to chronic stress are prone to
neuropsychiatric conditions, including depression [10] and anxiety [11], as
well as stroke [12]. In extreme cases, mental stress can lead to substance
abuse and suicide [13]. Therefore, mental stress has been recognized as the
top proxy killer disease [14].

While recognizing its negative impacts, we do not necessarily need to avoid
mental stress [15]. In 1908, Yerkes and Dodson proposed a model to explain the
relationship between arousal and task performance [16, 17]. The model
indicates that performance improves as arousal increases in simple task
conditions, such as focused attention, flashbulb memory, and fear
conditioning. Conversely, in challenging task conditions, such as divided
attention, working memory, and decision-making, the relationship between
arousal and task performance follows an inverted U shape. Because stress
levels rise concurrently with arousal, we can model the relationship between
stress and task performance similarly. Indeed, research has shown that
moderate levels of mental stress can enhance performance in competitive
sports[18] and certain attention-related tasks [17].

Many of the tasks we encounter in daily life are challenging and stressful,
making monitoring mental stress essential for maximizing performance.
Questionnaires and self-reports have long served as tools for measuring stress
levels [19, 20, 21, 22], considering them as the standard for stress level
determination in related studies [23, 24, 25]. However, real-time monitoring
of mental stress using questionnaires and self-reports is not feasible.
Furthermore, these measurements are subjective and may be susceptible to
anchoring effects [26].

In contrast, physiological signals provide objective measures for stress
detection. The Automatic Nervous System (ANS) controls the involuntary
movements of the body, such as skin conductivity, heart rate, and pupil
dilation [27, 28, 29]. Since stress causes dynamic changes in the ANS, there
are several techniques for detecting stress level changes [2, 28]. The most
commonly used signals in stress detection are Heart Rate (HR), Heart Rate
Variability (HRV), Galvanic Skin Response (GSR), blood pressure, and
respiration rate. [30]. Previous studies have shown that, under stress, HR,
GSR, blood pressure, and respiration rate increase, and the R-peak-to-R-peak
interval in HRV shorten [2, 28]. Even though HR has been used extensively in
previous studies, HR might not accurately reflect mental stress in situations
involving body movement, as HR increases during exercise.

Electroencephalography (EEG), a non-invasive measure of cortical activity, is
another commonly used method for stress detection [28]. Since EEG offers a
high temporal resolution and portability and is lower in cost than other
neuroimaging techniques, it has been widely used in neuroscience [31, 32],
clinical assessment [33], and brain-computer interfaces [34].

TABLE I: Previous studies of stress detection. Study | Stimuli | Biosignals used | Accuracy
---|---|---|---
Xia et al.[35] | Mental Arithmetic Task | EEG, ECG | 79.54%
Minguillon et al.[36] | Montreal Imaging Stress Task | EEG, ECG, EMG, EDA | 94.60%
Asif et al.[37] | Music Tracks | EEG | 98.76%
Saeed et al.[38] | No stimuli | EEG | 85.20%

Compared to commonly used ANS-based measures of stress, EEG provides a more
comprehensive, detailed, and temporally sensitive picture of stressor impacts
over time by measuring changes in the oscillatory activity of the cortex.
Hence, EEG can open new possibilities for stepping outside of the laboratory
and tackling the challenge of real-world stress as well. However, although
many studies have shown the feasibility of detecting stress in laboratory
environments using EEG and other measures, stress detection in realistic and
real-world contexts is still in its infancy. As shown in Table I, stress is
usually studied through artificial tasks that do not necessarily resemble
experiences of stressors encountered in day-to-day life [38].

To approach this question, this study analyzed EEG data from university
students during regular coursework, including lectures, quizzes, and other
activities, for a semester [39]. Students’ ratings of their subjective stress
during each class session served as ground truth for classifying each session
of EEG recordings as normal or elevated stress. We explore different
approaches to EEG preprocessing, channel selection, and model architecture in
service of an online-capable stress detection algorithm.

##  II Materials and Methods

###  II-A Data recording and preprocessing

####  II-A1 Data recording

At the beginning of each lecture, students were asked to complete the
Depression, Anxiety, Stress Scales-21 (DASS-21) questionnaire [22]. Next, eye-
open baseline EEG and ECG were recorded for about five minutes using a
32-channel NeuroScan System at a 1000 Hz sampling rate. Subsequently, the
students normally participated in their lectures and other classroom
activities for about sixty minutes while their EEG and ECG were continuously
recorded. After class, we recorded 5 minutes of resting state eye-open EEG and
ECG a second time.

Eighteen subjects participated in the first semester, and eight new subjects
in the second semester. We recorded 4 to 13 sessions per subject on different
days. Because of insufficient sessions from the second semester, we analyzed
only the data from the first semester.

####  II-A2 Data preprocessing

To classify mental stress levels using non-task-related data, we first extract
the 5-minute eye-open resting EEG at the beginning of the experiment. Then, we
performed band-pass filtering from 1Hz to 50Hz to remove high-frequency noise.
We further removed bad channels that contained negligible activity, noisy
signals, or have a poor correlation with adjacent channels. Next, we
implemented Artifact Subspace Reconstruction (ASR) to reconstruct the portion
where EEG signals are contaminated by muscle-related or motion-related
artifacts [40, 41]. Finally, we implemented Independent Component Analysis
(ICA) and rejected ICs with a probability higher than 80% of being artifact-
related ICs labeled by ICLabel [42].

###  II-B Data labeling and feature extraction

####  II-B1 Data labeling

We used the stress index in the DASS-21 questionnaire to quantify students’
subjective stress, which ranged from 0 to 38 across all sessions. DASS-21
scores divided each session into elevated or normal stress groups, with scores
above 14 representing elevated stress levels. After removing the sessions
missing DASS-21 reports, data remained for 71 normal and 21 elevated stress
sessions.

####  II-B2 Feature extraction

Based on 50 frequency bins with a bin width of 1Hz, we estimated the power
spectrum density (PSD) in the eye-open resting sessions. To reduce the number
of features, we selected frequency bins in the $\theta$ range as $\theta$ band
activities have been linked to stress-related cognitive state changes in
previous studies [43, 44]. We did not analyze activities in frequency ranges
because they overlapped with other non-brain artifacts, such as head movement
[45], or did not reflect consistent stress-induced brain response. The final
number of features used in the analysis was 150 (5 frequency bins $\times$ 30
channels).

####  II-B3 Synthetic minority over-sampling technique

Training classifiers on the imbalanced classes can potentially bias results
toward the majority group. To alleviate the imbalanced classes problem, we
evaluated the performance of the synthetic minority over-sampling technique
(SMOTE) [46], which essentially interpolates data points in the smaller group
to create balanced class sizes. It does so by first randomly selecting one
data point from the minority group. Next, it calculates k-nearest neighbors in
the minority group of the selected data point. Finally, SMOTE randomly selects
one neighbor and generates a synthetic minority data point between the
selected data point and the neighbor. By repeating this process, the number of
data points in the majority and minority groups is equal.

###  II-C Model selection and evaluation

####  II-C1 Linear Discriminant Analysis

The first classification model we investigated is Linear Discriminant Analysis
(LDA) [47], which aims to find a linear combination of features to separate
different classes into different distributions. In this study, we implement
LDA in scikit-learn [48], a Python library, with equal prior probabilities for
both classes. Since LDA is sensitive to outliers [49], we further selected 3Hz
to 7Hz from Fz, FCz, and Cz channels out of 150 features to prevent potential
outlier effects. These channels lie along the mid-line of the scalp topology,
and previous studies have shown that they typically capture activities closely
associated with changes in cognitive states within the $\theta$ range [50].

####  II-C2 Neural Network

Besides the linear classifier, we also investigated the performance of A non-
linear classifier. In particular, we built a 4-layer fully connected neural
network (NN) using pyTorch [51] and trained this NN using the features from
all the recording channels. Fig. 1 depicts the architectures of the NN. We
used ReLU as an activation function between layers and a Sigmoid function at
the output layers. The number of training epochs is 1000, and the loss
function for backpropagation is binary cross-entropy loss.

Figure 1: The architectures of the Neural Network used in this study. The
number of nodes is indicated by the number in each layer. All the layers are
fully connected to the next layer.

####  II-C3 Model evaluation

To evaluate the performance of our model, we implemented leave-one-session-out
(LOO) cross-validation after model training. LOO cross-validation selects a
test session from the dataset and then trains the model on the rest of the
sessions. Next, the trained model is applied to the test session. LOO cross-
validation performs the same procedure for all sessions and finally reports
the prediction results.

Since our dataset contains more normal than elevated stress sessions, the
chance level calculated over all the sessions is 77.17%. Therefore, instead of
using accuracy as a performance metric, we used balanced accuracy, which gives
us a chance level of 0.5. We also used the F1 Score to indicate the harmonic
balance between recall and precision to characterize a model’s sensitivity and
specificity.

###  II-D Practical issues of deployment

We must address several practical issues before deploying stress-detection
systems in the real world. First, we would like to monitor our stress levels
in real time. Unlike the laboratory scenarios, asking the users to wait 5
minutes before getting the results is unrealistic. Hence, online capability is
one of the most important indicators when we build our stress detection.
Second, we would like to reduce the number of recording channels needed in our
stress detection because EEG setup can be time-consuming and labor-intensive.
Adding additional channels to a recording system may also increase its
manufacturing cost significantly. Therefore, we investigated the effect of
recording channel reduction on our stress detection algorithms.

####  II-D1 Real-time ocular artifact removal

Independent component analysis can identify artifact-related ICs, especially
eye-related ICs, and remove them from the EEG signals [52, 53, 54]. However,
the computational time of ICA makes it unsuitable for real-time applications.
This study proposes an IC projection artifact removal method for removing eye-
related artifacts without performing online ICA. We focus solely on removing
eye-related ICs for two key reasons. Firstly, eye activities introduce
contamination into EEG signals within the frequency range of 0Hz to 8Hz, which
coincides with the frequency band of our PSD features [55]. Second, compared
to sparse and complicated muscle activities, two kinds of the most severe eye
artifacts, blink and horizontal saccade, can be well separated by ICA into
blink- and saccade-related ICs. Furthermore, these eye-related ICs exhibit
remarkable similarity across subjects. We performed ICA for each session
separately to check whether most contained blink- and saccade-related ICs. We
counted the number of eye-related ICs found in each session.

Our proposed method is comprised of three steps. First, we performed ICA on a
single subject and recorded its ICA unmixing matrix $W$ and its ICA mixing
matrix $W^{-1}$. Next, we removed the blink- and saccade-related ICs from the
mixing matrix $W^{-1}$ by assigning the corresponding columns to 0 and
recorded this new mixing matrix $M^{*}$. In cases where there is a discrepancy
in the number of recording channels between the template and the processed
data, we approximated the new mixing and unmixing matrices by retaining the
rows in $M^{*}$ and the columns in $W$ according to the channel labels.
Finally, we combined the unmixing matrix and the new mixing matrix to create
an IC decomposition template $P$. This template can remove the eye-related IC
activities using matrix multiplication, thereby preventing the need for online
ICA execution.

####  II-D2 Reduction of recording channels

We compared three recording montages and their stress-detection performance to
investigate the effect of recording channel reduction. Besides the original 30
recording channels, we selected 11 and 5 channels in the frontal region out of
the 30 channels. Fig. 2 shows the location of the three channels. We selected
these channels because we would like to capture the eye-related ICs in the IC
decomposition template. After the channel reduction, we performed data
preprocessing with the IC projection artifact removal method and trained our
stress detection algorithms with LDA and NN. One thing to clarify is that the
number of nodes in the input layer of NN changes from 150 to 55 and 25,
corresponding to 11 channels and 5 channels, to adapt to the change in the
number of recording channels.

Figure 2: Montage of channel reduction. (a) shows all 30 channels. (b) shows
the subselected 11 channels. (c) shows the subselected 5 channels. The red
circle indicates the location of 3 feature channels.

####  II-D3 Online stress detection evaluation

We investigated two important parameters in online use cases: the length of
the sliding window for the PSD estimation and the step size to move the
sliding window forward. First, we segmented a session into multiple epochs
using different sliding window lengths and step sizes. Next, we trained our
LDA stress detection model using the rest of the sessions and applied the
model to the epochs. For each window, we had a prediction about whether the
session was in the elevated stress group or the normal stress group. To
summarize these predictions, we used a majority vote to assign the session to
the group with the most predictions. After repeating this process for all the
sessions, we calculated the balanced accuracy for each pair of sliding window
lengths and step sizes.

##  III Results

###  III-A Stress detection with and without artifact removal and SMOTE

Fig. 3 shows the effect of our artifact-removal pipeline on the PSD features
of selected channels. On the top row, the PSDs of the elevated and normal
stress groups T after band-pass filtering alone do not directly differentiate
in the feature frequency range of all the feature channels. On the other hand,
after artifact removal, we found noticeable group differences between 4 to
10Hz over all three channels (bottom row). The scale of the PSD also dropped
from 20 dB to 10dB after artifact removal.

Figure 3: PSD features of selected channels before and after artifact removal.
The first row shows the PSDs of band-pass-filtered only data. The second row
shows the PSDs of data that have undergone artifact removal. The spectral
activities of the normal and elevated stress groups are shown in blue and red,
respectively. The solid lines indicate the mean, and the shaded area indicates
the standard deviation across sessions. The cross dots indicate frequency bins
in which the spectral power of EEG activities reliably differentiates the two
groups using a bootstrap test ($p<0.05$). The dashed line indicates the
frequency range used in the LDA analysis.

The comparisons of stress detection performance before and after artifact
removal are shown in Table II and Table III concerning the LDA model and NN
model. In both models, we observe a gradual increase in accuracy and balanced
accuracy after each artifact removal step. Also, the performance of the LDA
model is always better than the NN model. The best performance appears when
combining ASR with offline ICA. When replacing the offline ICA method with the
IC projection artifact removal method, we observe noticeable improvements
compared to applying ASR alone in both models. Moreover, there is only a 1%
difference between the LOO balanced accuracy of the proposed method and
offline ICA in the LDA model.

TABLE II: The effects of artifact removal on the performance of LDA-based stress detection. BP refers to band-pass filtering. Projection refers to the IC projection artifact removal method. LDA | LOO Acc. | LOO Balanced Acc. | F1
---|---|---|---
BP Only | 68.48% | 62.81% | 0.43
BP + ASR | 72.83% | 70.66% | 0.53
BP + ASR + ICA | 79.35% | 78.24% | 0.63
BP + ASR + Projection | 80.43% | 77.26% | 0.63
TABLE III: The effects of artifact removal on the performance of 4-layer NN stress detection. BP refers to band-pass filtering. Projection refers to the IC projection artifact removal method. NN | LOO Acc. | LOO Balanced Acc. | F1
---|---|---|---
BP Only | 75.00% | 56.98% | 0.3
BP + ASR | 77.17% | 66.77% | 0.49
BP + ASR + ICA | 83.70% | 74.35% | 0.62
BP + ASR + Projection | 80.43% | 68.88% | 0.53

Since our two groups of data did not contain balanced numbers of datasets, we
evaluated whether SMOTE could enhance the performance of our stress detection
models. Table IV shows the effect of SMOTE on the analysis after the artifact
removal pipeline with offline ICA. Though the LOO balanced accuracy increased
slightly, there was no significant improvement in both models with the SMOTE
process.

In the following analysis, we only reported the results from the LDA model
without SMOTE, as the LDA model consistently outperformed the NN model, and
the effect of SMOTE was found to be negligible.

TABLE IV: The effects of SMOTE on LDA and NN stress detection. | LOO Acc. | LOO Balanced Acc. | F1
---|---|---|---
LDA (w/o SMOTE) | 79.35% | 78.24% | 0.63
LDA (w/ SMOTE) | 81.52% | 79.64% | 0.65
NN (w/o SMOTE) | 83.70% | 74.35% | 0.62
NN (w/ SMOTE) | 81.52% | 76.29% | 0.62

###  III-B Consistency of eye-related ICs across different recordings

To evaluate the consistency of eye-related ICs across different recordings,
Figure. 4 shows the portion of sessions with different numbers of eye-related
ICs found. We found that 45.7% of sessions contain two eye-related ICs, and
42.4% of sessions contain three eye-related ICs. Moreover, only 2.2% of
sessions contain no eye-related ICs. Fig. 5 shows an example of the three eye-
related ICs in a session.

Figure 4: Histogram of the number of eye-related ICs found in each session.
The histogram has been normalized by the number of sessions. Figure 5: Example
of the three eye-related ICs found within a session. The left and center ICs
correspond to blink- and saccade-related ICs, respectively. Figure 6: Example
of the rejected eye-related ICs.

###  III-C Effect of reducing the channel montage on stress level
classification accuracy

After evaluating the performance of the IC projection artifact removal method,
we further compared the effect of reducing the number of recording channels.
Table V shows the performance of the LDA models trained on data recorded by
different input channels. All data were processed using the IC projection
artifact removal method before training LDA models. We found that the
performance of the LDA classifier increased by 1% after the electrode montage
was reduced from 30 to 11 channels. However, with a 5-channel montage, the
balanced accuracy dropped drastically from 77% to 60%.

TABLE V: The effects of reducing input channels on the performance of LDA-based stress detection. After reducing the channel montage, the data are preprocessed using the proposed projection method. All the models used frequency bins between 3 to 7Hz on Fz, FCz, and Cz as features. LDA | LOO Acc. | LOO Balanced Acc. | F1
---|---|---|---
30 Channels | 80.43% | 77.26% | 0.63
11 Channels | 80.43% | 78.94% | 0.64
5 Channels | 67.39% | 60.43% | 0.40
TABLE VI: Leave-one-session-out validation of LDA stress detection. All the models used frequency bins 3Hz to 7Hz on Fz, FCz, Cz as features. Proj. refers to the IC projection artifact removal method. LDA | Preprocessing | LOO Acc. | LOO Balanced Acc. | F1
---|---|---|---|---
| BP Only | 68.48% | 62.81% | 0.43
30 Channels | BP+ASR | 72.83% | 70.66% | 0.53
BP+ASR+ICA | 79.35% | 78.24% | 0.63
BP+ASR+Proj. | 80.43% | 77.26% | 0.63
11 Channels | BP+ASR | 75.00% | 75.42% | 0.58
BP+ASR+Proj. | 80.43% | 78.94% | 0.64
5 Channels | BP+ASR | 70.65% | 64.22% | 0.45
BP+ASR+Proj. | 67.39% | 60.43% | 0.40

###  III-D Online stress detection

We evaluate the online capability of our 11-channel LDA model with the IC
projection artifact removal method. We selected this model because of its
potential to achieve comparable performance to the model processed by offline
ICA with fewer recording channels. Fig. 7 shows the balanced accuracy of the
11-channel LDA model with different pairs of sliding window lengths and step
sizes. When using a window length equal to 1 second, the balanced accuracy of
the model hovers around 55%. When the window length increases to 20 seconds,
the balanced accuracy peaks at 78%. When the window length equals 5 minutes,
the balanced accuracy drops to 75%, and there is a 4% decrease compared to
offline results shown in Table V. Though the performance declined
concomitantly with reductions in step sizes at window lengths of less than 20
seconds, we found that the difference in stress-detection performance with
different step sizes was subtle, whereas the choice of window length dominated
the model’s performance. Contrary to our expectations that a longer window
length woudl provide better PSD estimation, the balanced accuracy actually
declined when the window length is between 40 seconds and 3 minutes.

Figure 7: Online evaluation with different windows and step sizes. Balanced
accuracy is calculated from LOO results, and the prediction of each session is
made by a majority vote across all the sliding windows. The cyan, blue, and
purple lines show the results of step sizes 1 sec, 10 sec, and 15 sec,
respectively. The window length with maximum balanced accuracy is marked by a
cross in all step sizes.

##  IV Discussion

Mental stress can greatly affect one’s cognitive performance. Detecting stress
in daily life can benefit clinical treatments and task performance, as mental
stress can impact many aspects of a person’s cognitive and physiological
functions. However, stepping into the real world outside of a research lab’s
controlled conditions brings several challenges. In this study, we addressed
the following considerations that are key to successful real-world stress
detection: (1) obtaining robust EEG signal through artifact removal, (2)
online classification capabilities using the IC projection artifact removal
method, and (3) optimizing the number of input EEG channels.

Each step in our artifact removal pipeline incrementally improved the
performance of our stress detection models, as shown in Table II and Table
III. Moreover, our proposed IC projection artifact removal method yielded a
balanced accuracy comparable to offline ICA. These results suggest that there
is limited room for improvement in further removing muscle artifacts after
removing eye artifacts.

Our proposed IC projection artifact removal method relies heavily on the
consistency of eye-related ICs across recordings. Fig. 4 shows that nearly 90%
of the sessions in this dataset contain 2 or more eye-related ICs, indicating
that blink-related and saccade-related ICs appear in almost all sessions.

In addition to identifying blink-related and saccade-related ICs, we observed
an extra IC in certain sessions that could potentially be linked to minor
lateral eye movements or facial expressions such as frowning. Conversely, the
ICs associated with muscle activity exhibited greater diversity. Due to the
complex nature of muscles, comprising numerous fibers, capturing a single body
movement within a single IC poses a challenge for ICA.

When comparing the performance of the LDA and NN models, we consistently
observe superior performance from the LDA model over the NN model. One
plausible explanation for this difference is overfitting. The NN model offers
many trainable parameters, yet the available training data is relatively
limited. Upon comparing models’ performances with and without SMOTE, we noted
only marginal enhancements for both LDA and NN models when employing SMOTE.
This could be attributed to the scarcity of training data, as SMOTE assumes
that the sampled data shares similar statistical characteristics with the
underlying population.

Low-density channel arrays are preferred to reduce setup times and equipment
costs. Since ICA can decompose eye activities with channels near the frontal
region, a full scalp montage may be unnecessary, particularly when using the
proposed IC projection artifact removal method. Moreover, our LDA model
achieved comparable accuracy using only 11 versus 30 channels of EEG data
(Table V), in keeping with the idea that features from a limited subset of
channels (Fz, FCz, and Cz) can capture the discriminative information for
reliable stress detection. However, because our IC projection artifact removal
method is based on independent components, its performance drops with too few
input channels—as shown by our finding that with only 5 channels, ICA fails to
decompose eye activities into distinct blink- and saccade-related ICs.
Instead, ICs represent a mixture of brain and eye activities. Assuming that
the most likely blink- and saccade-related ICs would be removed from the
analysis, only three ICs would remain to reconstruct the surface EEG signals.
Also, a substantial portion of brain signals would be lost with the ”mixed”
ICs accounting for eye activities, resulting in a decline in model
performance.

Finally, we evaluated the online capability of the 11-channel LDA model with
the IC projection artifact removal method by investigating the effect of
different pairs of sliding window lengths and step sizes on the balanced
accuracy. The choice of window length over step size dominates the model’s
performance, probably because of the quality of the PSD estimation. The longer
the window length, the better the estimation quality. We observed the best
performances across different step sizes using a window length of around 20
seconds, indicating that the quality of PSD estimation was sufficient to
detect stress level changes. When the window length was shorter than the step
size, the algorithm ignored the data points between them, resulting in a down-
sampling effect that hampered the performance of stress detection. The effect
is more severe when using a large step size, as observed in Fig. 7. On the
other hand, at a window length of 5 minutes, we found that the balanced
accuracy dropped slightly compared to the offline results, possibly because
some sessions involved an eyes-open resting baseline that exceeds 5 minutes.

One thing that caught our attention is that, instead of a monotonic increase,
the model’s balanced accuracy dropped before returning to expected performance
levels when using a 5-minute window length. We hypothesize that mental stress
changes do not affect EEG signals constantly, but rather, on a repeated cycle
such that EEG-based changes due to psychological stress might be diluted by
the long window length. However, obtaining the benchmarks for stress detection
in an online scenario would make testing this hypothesis very difficult.

##  V Conclusion

This study proposes a robust, online capable, EEG-Based mental stress
detection algorithm suitable for pervasive, real-world monitoring using a low-
density channel array. To remove ocular artifacts in real time, we proposed an
IC projection artifact removal method that reduced the required computational
time while maintaining performance compared to offline ICA. This study also
explored the influence of different models, preprocessing pipelines, and the
number of recording channels. Our results show that with 15 features from Fz,
FCz, and Cz channels, the proposed LDA-based stress detection algorithm can
achieve a 78% balanced accuracy in an imbalanced binary stress detection
problem. Moreover, for the purposes of artifact removal, the proposed LDA-
based stress detection algorithm requires only 11 recording channels near the
frontal region. The findings of this study could lead to the deployment of
daily mental stress monitoring in the future.

##  VI Acknowledgement

Dr. Li-Wei Ko recorded the dataset used in this study at National Chiao Tung
University (National Yang-Ming Chiao Tung University), Hsinchu, Taiwan. The
authors gratefully acknowledge the support from Dr. Li-Wei Ko, Microsoft
Research, and the National Science Foundation.

## References

  * [1] S. Cohen, R. C. Kessler, and L. U. Gordon, _Measuring stress: A guide for health and social scientists_. Oxford University Press on Demand, 1997.
  * [2] G. Giannakakis, D. Grigoriadis, K. Giannakaki, O. Simantiraki, A. Roniotis, and M. Tsiknakis, “Review on psychological stress detection using biosignals,” _IEEE Transactions on Affective Computing_ , vol. 13, no. 1, pp. 440–460, 2019.
  * [3] S. P. Behere, R. Yadav, and P. B. Behere, “A comparative study of stress among students of medicine, engineering, and nursing,” _Indian journal of psychological medicine_ , vol. 33, no. 2, pp. 145–148, 2011.
  * [4] G. Andersson and L. Yardley, “Time-series analysis of the relationship between dizziness and stress,” _Scandinavian Journal of Psychology_ , vol. 41, no. 1, pp. 49–54, 2000.
  * [5] J. Delaney and D. Brodie, “Effects of short-term psychological stress on the time and frequency domains of heart-rate variability,” _Perceptual and motor skills_ , vol. 91, no. 2, pp. 515–524, 2000.
  * [6] U. Lundberg, I. E. Dohns, B. Melin, L. Sandsjö, G. Palmerud, R. Kadefors, M. Ekström, and D. Parr, “Psychophysiological stress responses, muscle tension, and neck and shoulder pain among supermarket cashiers.” _Journal of occupational health psychology_ , vol. 4, no. 3, p. 245, 1999\.
  * [7] S. C. Segerstrom and G. E. Miller, “Psychological stress and the human immune system: a meta-analytic study of 30 years of inquiry.” _Psychological bulletin_ , vol. 130, no. 4, p. 601, 2004.
  * [8] A. B. Jarali and G. Radhakrishnan, “Stress, obesity and selected health problems among professionals,” _Asian Journal of Nursing Education and Research_ , vol. 3, no. 3, p. 3, 2013.
  * [9] T. G. Pickering, “Mental stress as a causal factor in the development of hypertension and cardiovascular disease,” _Current hypertension reports_ , vol. 3, no. 3, pp. 249–254, 2001.
  * [10] S. Checkley, “The neuroendocrinology of depression and chronic stress,” _British medical bulletin_ , vol. 52, no. 3, pp. 597–617, 1996.
  * [11] G. C. Dieleman, A. C. Huizink, J. H. Tulen, E. M. Utens, H. E. Creemers, J. van der Ende, and F. C. Verhulst, “Alterations in hpa-axis and autonomic nervous system functioning in childhood anxiety disorders point to a chronic stress hypothesis,” _Psychoneuroendocrinology_ , vol. 51, pp. 135–150, 2015\.
  * [12] D. Kotlega, M. Gołab-Janowska, M. Masztalewicz, S. Ciećwież, and P. Nowacki, “The emotional stress and risk of ischemic stroke,” _Neurologia i neurochirurgia polska_ , vol. 50, no. 4, pp. 265–270, 2016\.
  * [13] D. A. Brent, “Risk factors for adolescent suicide and suicidal behavior: mental and substance abuse disorders, family environmental factors, and life stress,” _Suicide and Life-Threatening Behavior_ , vol. 25, pp. 52–63, 1995\.
  * [14] J. Debnath, N. Chauahan, T. Prakash, and D. Goli, “Stress,” a proxy killer” and role of adaptogen as antistress agent,” _Archives of Pharmacy Practice_ , vol. 2, no. 1, p. 6, 2011.
  * [15] H. Selye, “Stress without distress,” in _Psychopathology of human adaptation_. Sprin-ger, 1976, pp. 137–146.
  * [16] R. M. Yerkes, J. D. Dodson _et al._ , “The relation of strength of stimulus to rapidity of habit-formation,” 1908.
  * [17] M. A. Staal, “Stress, cognition, and human performance: A literature review and conceptual framework,” 2004.
  * [18] J. G. Jones and L. Hardy, “Stress and cognitive functioning in sport,” _Journal of Sports Sciences_ , vol. 7, no. 1, pp. 41–63, 1989.
  * [19] N. Cahir and R. D. Morris, “The psychology student stress questionnaire,” _Journal of clinical psychology_ , vol. 47, no. 3, pp. 414–417, 1991.
  * [20] C. S. Crandall, J. J. Preisler, and J. Aussprung, “Measuring life event stress in the lives of college students: The undergraduate stress questionnaire (usq),” _Journal of behavioral medicine_ , vol. 15, no. 6, pp. 627–662, 1992\.
  * [21] S. Levenstein, C. Prantera, V. Varvo, M. L. Scribano, E. Berto, C. Luzi, and A. Andreoli, “Development of the perceived stress questionnaire: a new tool for psychosomatic research,” _Journal of psychosomatic research_ , vol. 37, no. 1, pp. 19–32, 1993.
  * [22] P. F. Lovibond and S. H. Lovibond, “The structure of negative emotional states: Comparison of the depression anxiety stress scales (dass) with the beck depression and anxiety inventories,” _Behaviour research and therapy_ , vol. 33, no. 3, pp. 335–343, 1995.
  * [23] D. Rissén, B. Melin, L. Sandsjö, I. Dohns, and U. Lundberg, “Surface emg and psychophysiological stress reactions in women during repetitive work,” _European journal of applied physiology_ , vol. 83, no. 2, pp. 215–222, 2000.
  * [24] N. L. Lopez-Duran, R. Nusslock, C. George, and M. Kovacs, “Frontal eeg asymmetry moderates the effects of stressful life events on internalizing symptoms in children at familial risk for depression,” _Psychophysiology_ , vol. 49, no. 4, pp. 510–521, 2012.
  * [25] G. C. Blackhart, J. A. Minnix, and J. P. Kline, “Can eeg asymmetry patterns predict future development of anxiety and depression?: A preliminary study,” _Biological psychology_ , vol. 72, no. 1, pp. 46–50, 2006.
  * [26] D. L. Paulhus, S. Vazire _et al._ , “The self-report method,” _Handbook of research methods in personality psychology_ , vol. 1, no. 2007, pp. 224–239, 2007.
  * [27] J. N. Langley, _The autonomic nervous system_. W. Heffer, 1921.
  * [28] N. Sharma and T. Gedeon, “Objective measures, sensors and computational techniques for stress recognition and classification: A survey,” _Computer methods and programs in biomedicine_ , vol. 108, no. 3, pp. 1287–1301, 2012.
  * [29] J. Beatty, B. Lucero-Wagoner _et al._ , “The pupillary system,” _Handbook of psychophysiology_ , vol. 2, no. 142-162, 2000.
  * [30] S. Gedam and S. Paul, “A review on mental stress detection using wearable sensors and machine learning techniques,” _IEEE Access_ , vol. 9, pp. 84 045–84 066, 2021.
  * [31] T. S. Grummett, S. P. Fitzgibbon, T. W. Lewis, D. DeLosAngeles, E. M. Whitham, K. J. Pope, and J. O. Willoughby, “Constitutive spectral eeg peaks in the gamma range: suppressed by sleep, reduced by mental activity and resistant to sensory stimulation,” _Frontiers in human neuroscience_ , vol. 8, p. 927, 2014.
  * [32] F. Artoni, C. Fanciullacci, F. Bertolucci, A. Panarese, S. Makeig, S. Micera, and C. Chisari, “Unidirectional brain to muscle connectivity reveals motor cortex control of leg muscles during stereotyped walking,” _NeuroImage_ , vol. 159, pp. 403–416, 2017.
  * [33] H. Marzbani, H. R. Marateb, and M. Mansourian, “Neurofeedback: a comprehensive review on system design, methodology and clinical applications,” _Basic and clinical neuroscience_ , vol. 7, no. 2, p. 143, 2016.
  * [34] G. E. Fabiani, D. J. McFarland, J. R. Wolpaw, and G. Pfurtscheller, “Conversion of eeg activity into cursor movement by a brain-computer interface (bci),” _IEEE Trans. on Neural Syst. and Rehabil. Eng._ , vol. 12, no. 3, pp. 331–338, 2004.
  * [35] L. Xia, A. S. Malik, and A. R. Subhani, “A physiological signal-based method for early mental-stress detection,” _Biomedical Signal Processing and Control_ , vol. 46, pp. 18–32, 2018.
  * [36] J. Minguillon, E. Perez, M. A. Lopez-Gordo, F. Pelayo, and M. J. Sanchez-Carrion, “Portable system for real-time detection of stress level,” _Sensors_ , vol. 18, no. 8, p. 2504, 2018.
  * [37] A. Asif, M. Majid, and S. M. Anwar, “Human stress classification using eeg signals in response to music tracks,” _Computers in biology and medicine_ , vol. 107, pp. 182–196, 2019.
  * [38] S. M. U. Saeed, S. M. Anwar, H. Khalid, M. Majid, and U. Bagci, “Eeg based classification of long-term stress using psychological labeling,” _Sensors_ , vol. 20, no. 7, p. 1886, 2020.
  * [39] L.-W. Ko, O. Komarov, W. D. Hairston, T.-P. Jung, and C.-T. Lin, “Sustained attention in real classroom settings: An eeg study,” _Frontiers in human neuroscience_ , vol. 11, p. 388, 2017.
  * [40] C. A. E. Kothe and T.-P. Jung, “Artifact removal techniques with signal reconstruction,” _U.S. Patent Application No. 14/895,440_ , 2014.
  * [41] C.-Y. Chang, S.-H. Hsu, L. Pion-Tonachini, and T.-P. Jung, “Evaluation of artifact subspace reconstruction for automatic artifact components removal in multi-channel eeg recordings,” _IEEE Transactions on Biomedical Engineering_ , vol. 67, no. 4, pp. 1114–1121, 2019.
  * [42] L. Pion-Tonachini, K. Kreutz-Delgado, and S. Makeig, “Iclabel: An automated electroencephalographic independent component classifier, dataset, and website,” _NeuroImage_ , vol. 198, pp. 181–197, 2019.
  * [43] M. Sani, H. Norhazman, H. Omar, N. Zaini, and S. Ghani, “Support vector machine for classification of stress subjects using eeg signals,” in _2014 IEEE Conference on Systems, Process and Control (ICSPC 2014)_. IEEE, 2014, pp. 127–131.
  * [44] J. Alonso, S. Romero, M. Ballester, R. Antonijoan, and M. Mañanas, “Stress assessment based on eeg univariate features and functional connectivity measures,” _Physiological measurement_ , vol. 36, no. 7, p. 1351, 2015.
  * [45] I. I. Goncharova, D. J. McFarland, T. M. Vaughan, and J. R. Wolpaw, “Emg contamination of eeg: spectral and topographical characteristics,” _Clinical neurophysiology_ , vol. 114, no. 9, pp. 1580–1593, 2003.
  * [46] N. V. Chawla, K. W. Bowyer, L. O. Hall, and W. P. Kegelmeyer, “Smote: synthetic minority over-sampling technique,” _Journal of artificial intelligence research_ , vol. 16, pp. 321–357, 2002.
  * [47] S. Balakrishnama and A. Ganapathiraju, “Linear discriminant analysis-a brief tutorial,” _Institute for Signal and information Processing_ , vol. 18, no. 1998, pp. 1–8, 1998.
  * [48] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay, “Scikit-learn: Machine learning in Python,” _Journal of Machine Learning Research_ , vol. 12, pp. 2825–2830, 2011.
  * [49] Ş. Büyüköztürk and Ö. Çokluk-Bökeoğlu, “Discriminant function analysis: Concept and application,” _Eurasian J Educ Res_ , vol. 33, pp. 73–92, 2008\.
  * [50] O. Attallah, “An effective mental stress state detection and evaluation system using minimum number of frontal brain electrodes,” _Diagnostics_ , vol. 10, no. 5, p. 292, 2020.
  * [51] A. Paszke, S. Gross, F. Massa, A. Lerer, J. Bradbury, G. Chanan, T. Killeen, Z. Lin, N. Gimelshein, L. Antiga, A. Desmaison, A. Kopf, E. Yang, Z. DeVito, M. Raison, A. Tejani, S. Chilamkurthy, B. Steiner, L. Fang, J. Bai, and S. Chintala, “Pytorch: An imperative style, high-performance deep learning library,” in _Advances in Neural Information Processing Systems 32_. Curran Associates, Inc., 2019, pp. 8024–8035. [Online]. Available: http://papers.neurips.cc/paper/9015-pytorch-an-imperative-style-high-performance-deep-learning-library.pdf
  * [52] T.-P. Jung, S. Makeig, C. Humphries, T.-W. Lee, M. J. McKeown, V. Iragui, and T. J. Sejnowski, “Removing electroencephalographic artifacts by blind source separation,” _Psychophysiology_ , vol. 37, no. 2, p. 163–178, 2000.
  * [53] N. Bigdely-Shamlo, K. Kreutz-Delgado, C. Kothe, and S. Makeig, “Eyecatch: Data-mining over half a million eeg independent components to construct a fully-automated eye-component detector,” in _Engineering in Medicine and Biology Society (EMBC), 2013 35th Annual International Conference of the IEEE_. IEEE, 2013, pp. 5845–5848.
  * [54] L. Frølich, T. S. Andersen, and M. Mørup, “Automatic removal of eye movement and blink artifacts from eeg data using blind component separation,” _Psychophysiology_ , vol. 41, pp. 313–325, 2004.
  * [55] A. Schlögl, C. Keinrath, D. Zimmermann, R. Scherer, R. Leeb, and G. Pfurtscheller, “A fully automated correction method of eog artifacts in eeg recordings,” _Clinical neurophysiology_ , vol. 118, no. 1, pp. 98–104, 2007.