Brainwaves Stress Pattern Based On Perceived Stress Scale Using Deep Learning
Brainwaves Stress Pattern Based On Perceived Stress Scale Using Deep Learning
A PROJECT REPORT
Submitted by
SAPNASRI T (613020104072)
SHIVASANGARI G A (613020104077)
THAMIRA R (613020104091)
BACHELOR OF ENGINEERING
IN
MAY 2024
ANNA UNIVERSITY : CHENNAI 600 025
BONAFIDE CERTIFICATE
Certified that this project report “BRAINWAVES STRESS PATTERN BASED ON
PERCEIVED STRESS SCALE USING DEEP LEARNING” is the bonafide work of
“SAPNASRI.T (613020104072), SHIVASANGARI.G.A (613020104077),
THAMIRA. R (613020104091)” who carried out the project work under my supervision.
SIGNATURE SIGNATURE
Dr.M.K.CHANDRASEKARAN,M.E., Mr.P.DINESH KUMAR.,M.E.,
Ph.D., ASSISTANT PROFESSOR
We wish to convey our special thanks to our beloved and Honorable Executive Director
Prof.Dr.S.KUPPUSWAMI,B.E.,M.Sc(Engg).,Dr.Ing(France) who gave opportunity to
frame the project to the full satisfaction.
We are very thankful to our Head of the Department in Computer Science and
Engineering Dr.M.K.CHANDRASEKARAN,M.E.,Ph.D., who had motivated us and
provided guidance throughout the project.
We are very thankful to all the Teaching and Non-Teaching faculty Members of Computer
Science and Engineering Department for their timed help.
Finally, we are thankful to our beloved family and friends for their moral support.
iii
ABSTRACT
iv
TABLE OF CONTENTS
ABSTRACT iv
LIST OF ABBREVIATIONS ix
1 INTRODUCTION 1
1.1 OVERVIEW 1
1.8 SUMMARY 5
2 LITERATURE SURVEY 6
v
RESPONSE DETECTION SYSTEM
BASED ON GALVANIC SKIN
RESPONSE ANALYSIS
vi
6.4 EGG DATA PREPROCESSING 28
6.7 RE-REFERENCE 30
6.9 LABELLING 32
7 RESULT ANALYSIS 33
8.1 CONCLUSION 35
vii
LIST OF TABLES
1 Test Sample 26
2 Frequency Bands 30
vii
LIST OF FIGURES
5.2 System 18
6.6 Re-reference to Cz 29
viii
LIST OF ABBREVIATIONS
ABBREVIATION EXPANSION
PD - Pupilar Diameter
SK - Skin Temperature
VR - Virtual Reality
ix
VGG - Visual Geometry Group
x
CHAPTER 1
INTRODUCTION
1.1 OVERVIEW
Stress is a problem that is widespread throughout the world, dubbed by the World
Health Organization as the Health Epidemic of the 21st Century. Although it is natural to
have a certain level of stress due to the challenges faced daily, stress is not only caused
by factors external to the individual, in many cases it is related to the way of interacting
with the environment and the internal processes involved. In Europe alone, more than 50%
of workers and students suffer from stress. There are positive and negative emotions.
Stress is part of the negative ones and if suffered continuously can lead to the appearance
of other emotions such as anger or sadness. This set of emotions can be captured through
the collection of electroencephalographic or EEG signals from the human brain. In most
cases, the procedure of the various studies in this field consists of inducing a calm state in
the subject to subsequently make him enter different emotional states while these
contrasting signals are recorded. The major advantage EEG is that it only records
electromagnetic waves from the individual’s brain and is therefore non-invasive.
Most deep learning methods use neural network architectures, which is why deep
learning models are often referred to as deep neural networks. The term “deep” usually
refers to the number of hidden layers in the neural network. only contain 2-3 hidden layers,
while deep networks can have as many as 150. Deep learning models are trained by using
large sets of labeled data and neural network architectures that learn features directly from
the data without the need for manual feature extraction.
The figure 1.1 represents the neural networks which are organized in layers
consisting of a set of interconnected nodes. One of the most popular types of deep neural
networks is known as convolutional neural networks (CNN or Convent). A CNN
convolves learned features with input data, and uses 2Dconvolutional layers, making this
architecture well suited to processing 2D data, such as images.
2
CNNs eliminate the need for manual feature extraction, so it does not need to identify
features used to classify images. The CNN works by extracting features directly from
images. The relevant features are not pretrained; they are learned while the network trains
on a collection of images. This automated feature extraction makes deep learning models
highly accurate for computer vision tasks such as object classification.
The initial amplification of the signal was tunable, but in the final stage it was set to
8000 times. Right after the amplifier the final filter was placed. It was a fifth order
lowpass filter with cutoff frequency at 20 Hz, this means the 50 Hz noise was almost
erased together with other possibly high frequency noise. At the end a second tunable
amplifier was connected, it was set to 1000 times. Because the mayday was set to acquire
10000 samples at 5 kHz the program ran slow, but the resolution achieved was more
important than the speed of the program. The desired frequencies were nowhere to be
observed, at least not at a readable amplitude.
Deep learning provides the healthcare industry with the ability to analyze data at
exceptional speeds without compromising on accuracy. It is not machine learning, nor is
it AI, it is an elegant blend of both that uses a layered algorithmic architecture to sift
through data at an astonishing rate. The benefits of deep learning in healthcare are plentiful
fast, efficient, accurate but they do not stop there. Even more benefits lie within the neural
networks formed by multiple layers of AI and ML and their ability to learn. The secret to
deep learning’s success is in the name learning. Deep learning uses mathematical models
that are designed to operate a lot like the human brain. The multiple layers of network
and technology allow for computing capability that is unprecedented, and the ability to
3
sift through vast quantities of data that would previously have been lost, forgotten, or
missed. These deep learning networks can solve complex problems and tease out strands
of insight from reams of data that abound within the healthcare profession. It is a skill set
that has not gone unnoticed by the healthcare profession.
The primary objective of the present Master Thesis is to classify stress and calm
brain states from EEG data acquired in an inductive stress experiment and contrast them
with other biological signal data such as GSR (EDA) and electro- cardiogram (ECG).
Secondary objectives include comparing the performance of different machine
Learning and Deep Learning techniques to corroborate which is the most suitable for
studies in this area and a study on the importance of channels to assess the feasibility of
using an EEG wearable.
There are many kinds of stress. However, based on research studies about the types
of stress in psychology, stress can be divided into three primary types:
● Acute stress
Acute stress results from body’s reaction to a new or challenging situation. It is that
feeling people get from an approaching deadline or when you narrowly avoid being hit
by a car. When experience it because that makes people enjoy. Like an exhilarating ride
on a roller coaster or an outstanding personal achievement. Acute stress is classified as
short-term. Usually, emotions and the body return to their normal state relatively soon.
4
● Episodic acute stress
Episodic acute stress is when acute stresses happen on a frequent basis. This can be
because of repeatedly tight work deadlines. It can also be because of the frequent high-
stress situations experienced by some professionals, such as healthcare workers. With
this type of stress, people do not get time to return to a relaxed and calm state. And the
effects of the high-frequency acute stresses accumulate. It often leaves us feeling like
people are moving from one crisis to another.
● Chronic stress
Chronic stress is the result of stressors that continue for a long period of time.
Examples include living in a high-crime neighborhood or constantly fighting with the life
partner. This type of stress feels never-ending. Patients often have difficulty seeing any
way to improve or change the situation that is the cause of our chronic stress.
1.8 SUMMARY
5
CHAPTER 2
LITERATURE SURVEY
These foundational studies have inspired this work. While previous research has
validated procedures based on physiological signals like ECG or GSR, utilizing EEG
signals for emotional detection remains a relatively new and unexplored area. This study
aims to extend prior work by contrasting stress prediction results derived from EEG data
with simultaneous ECG and EDA data. This approach seeks to determine if combining
these signals yields advantages beyond what individual signals offer separately.
Moreover, the literature survey underscores three key points: the importance of feature
selection in stress detection studies, the variety of classification algorithms used in stress
assessment systems, and the potential benefits of combining multiple physiological
signals for more robust stress detection. The importance of feature selection in stress
detection studies, highlighting the need for robust methods to extract relevant features
from complex datasets. The diversity of classification algorithms used in stress
assessment systems, emphasizing the necessity of selecting appropriate algorithms based
on the characteristics of the data and the desired outcomes. The potential benefits of
combining multiple physiological signals for more comprehensive stress detection,
6
suggesting that integrated approaches may enhance the accuracy and reliability of stress
assessment systems.
Other studies have proposed various methods to detect stress from EEG.
Kaminska et al. investigated the use of EEG signals to classify the stress level of subjects
while using virtual reality (VR). The acquisition protocol consisted of alternating between
simulated relaxation and stress scenes while monitoring with an EEG headset. They then
compared the performance of a CNN with other Machine Learning methods by stress
classification, obtaining the best result (96.42%) with an SVM considering all brain
waves. Phutela et al. proposed a stress classification system using a 4-electrode Muse
EEG headband. The experiment consisted of showing four clips, two of stress induction
and two of comedy scenes. Once the data were acquired with the headset, they compared
two classification models, Multilayer Perceptron (MLP) and Long Short-Term Memory
(LSTM), achieving an accuracy of 93.17% with the LSTM architecture.
7
2.3 LITERATURE SURVEY SUMMARY
8
3 Performance Evaluation Deep Investigating the Advantages:
of LoRa 915 MHz for Learning impact of Adaptive Contributes
Health Monitoring with Data Rate (ADR) to power
Adaptive Data Rate by on LoRa efficiency
Puput Dani Prasetyo Adi, transmission for and provides
Abdul Wahid and Imam efficient data prolonged
Tahyudin transfer in UHF operational
IEEE 2022 frequencies, life for
particularly in a connected
health monitoring sensors
system with Limitations:
sensors Limits its
communicating applicability
alternately to holistic
health
monitoring
due to less
precision
9
CHAPTER 3
SYSTEM ANALYSIS
• To develop a system for understanding and recognizing the stress level based
on electroencephalogram (EEG).
• To prevent disease and decrease the possibility of health issues such as clinical
brain damage, it is necessary to detect stress as early as possible.
10
targeted stress induction methodologies. These stressors, including the Stroop color word
test and mental arithmetic tasks, are meticulously chosen to elicit varying degrees of
stress, allowing for comprehensive stress assessment across different contexts and
intensities. A cohort of 10 subjects, carefully selected from the Nanyang Technological
University community, participates in the experiment. The demographic composition,
comprising predominantly males (9 out of 10) and a single female participant, ensures
diverse representation while maintaining a cohesive sample. All subjects fall within the
age bracket of 20 to 35 years and are confirmed to be in good health, minimizing
confounding variables and enhancing the reliability of the study outcomes. Through this
meticulously orchestrated experimental design, the study endeavors to deepen our
understanding of stress dynamics and refine stress assessment methodologies. By
elucidating the nuances of stress response in controlled settings, the proposed system
holds promise for informing interventions and strategies aimed at mitigating the adverse
effects of stress on individuals' well-being.
11
In addition to the primary goal, this research encompasses several secondary objectives.
These include assessing the performance of diverse Machine Learning and Deep Learning
techniques to ascertain the most suitable approach within this domain. Moreover, there is a
deliberate examination of the importance of channels in EEG wearables, with a specific
focus on evaluating their feasibility for stress detection applications. Through a meticulous
investigation into these objectives, this research endeavours to advance our comprehension
of stress detection methodologies. Ultimately, the overarching aim is to contribute to the
refinement of stress assessment and management strategies, thereby enhancing individual
well-being and quality of life.
In the pursuit of the primary objective, the stress induction experiment is designed to
elicit varying levels of stress responses among the participants. By employing standardized
stressors such as cognitive tasks or emotionally charged stimuli, the experiment aims to
capture a diverse range of EEG patterns corresponding to different stress levels. This
approach ensures robust training of the classification models and facilitates accurate
discrimination between stress and calm brain states. Furthermore, the comparison of EEG-
based stress classifications with those derived from other physiological signals adds a layer
of depth to the analysis. By integrating multiple modalities, such as GSR and ECG, the study
can elucidate the unique contributions of each signal in stress assessment. This holistic
approach not only enhances the reliability of stress detection but also provides valuable
insights into the interplay between various physiological responses under different stress
conditions.
Additionally, the secondary objectives of the research encompass a comprehensive
evaluation of different Machine Learning and Deep Learning techniques. By systematically
comparing the performance of these algorithms, the study seeks to identify the most effective
approach for stress classification. Moreover, the investigation into the importance of
channels in EEG wearables underscores the need for optimized sensor configurations to
maximize the accuracy and reliability of stress detection systems.
12
CHAPTER 4
SYSTEM REQUIREMENTS
Idle : MATLAB
Operating System : Windows 10
• Matrix Operations
MATLAB is renowned for its ability to perform matrix and vector operations
seamlessly. This capability simplifies mathematical computations and facilitates the
implementation of algorithms.
13
• Algorithm Development
● Data Analysis
With its rich set of statistical and machine learning toolboxes, MATLAB enables
users to explore and analyze data effectively. From preprocessing raw data to performing
advanced statistical analysis, MATLAB provides tools for every stage of the data analysis
pipeline.
• Visualization
• Application Development
• Integration
● Parallel Computing
MATLAB's robust toolsets for statistics, machine learning, and deep learning are
utilized in data science projects for predictive modeling, pattern recognition, and data-
driven decision-making.
• Financial Modeling
• Biomedical Research
15
CHAPTER 5
ALGORITHM DESCRIPTION
A better approach for analyzing signals with a dynamical frequency spectrum is the
Wavelet Transform. The Wavelet Transform has a high resolution in both the frequency
and the time-domain. It does not only tell us which frequencies are present in a signal, but
also at which time these frequencies have occurred. This is accomplished by working with
different scales.
● For small frequency values a high resolution in the frequency domain, low
16
Figure 5.1 A guide for using the wavelet transform in machine learning
The approximation and detail coefficients of the sym5 wavelet (level 1 to 5) applied
on a chirp signal, from level 1 to 5. On the left, the schematic representation of the high
pass and low pass filters applied on the signal at each level.
The chirp signal and the DWT is applied to it subsequently. There are a few things
to notice here:
……………………………..(1)
19
• K MEANS CLUSTERING
20
The k-means clustering algorithm mainly performs two tasks:
• Determines the best value for K-centre points or centroids by an iterative process.
• Assigns each data point to its closest K-centre. Those data points which are near to
the K-centre, create a cluster.
The full abbreviation of VGG is the Visual Geometry Group, which belongs to the
Department of Science and Engineering of Oxford University. It has released a series of
convolutional network models beginning with VGG, which can be applied to face
recognition and image classification, from VGG16 to VGG19. The original purpose of
VGG's research on the depth of convolutional networks is to understand how the depth of
convolutional networks affects the accuracy and accuracy of large-scale image
classification and recognition. Deep-16 CNN, to deepen the number of network layers
and to avoid too many parameters, a small 3x3 convolution kernel is used in all layers.
21
Figure 5.5 Understanding the softmax function in minutes
The input of VGG is set to an RGB image of 224x244 size. The average RGB value
is calculated for all images on the training set image, and then the image is input as an
input to the VGG convolution network. A 3x3 or 1x1 filter is used, and the convolution
step is fixed. There are 3 VGG fully connected layers, which can vary from VGG11 to
VGG19 according to the total number of convolutional layers + fully connected layers.
The minimum VGG11 has 8 convolutional layers and 3 fully connected layers. The
maximum VGG19 has 16 convolutional layers. +3 fully connected layers. In addition, the
VGG network is not followed by a pooling layer behind each convolutional layer, or a
total of 5 pooling layers distributed under different convolutional layers.
22
Figure 5.6 Face recognition with VGG16
VGG16 contains 16 layers and VGG19 contains 19 layers. A series of VGGs is the
same in the last three fully connected layers. The overall structure includes 5 sets of
convolutional layers, followed by a MaxPool. The difference is that more and more
cascaded convolutional layers are included in the five sets of convolutional layers.
Each convolutional layer in AlexNet contains only one convolution, and the size of
the convolution kernel is 7 7, In VGGNet, each convolution layer contains 2 to 4
convolution operations. The size of the convolution kernel is 3 3, the convolution step
size is 1, the pooling kernel is 2 * 2, and the step size is 2. The most obvious improvement
of VGGNet is to reduce the size of the convolution kernel and increase the number of
convolution layers.
23
CHAPTER 6
PROPOSED METHODOLOGY
The EEG sensor is used to detect the brain waves and indicates the stress including
attention and meditation levels. It is preferred to use NodeMCU as it is user friendly,
lower cost and stable of accuracy. LCD base board is connected to the LCD to show the
output of the system. After captured the signal using EEG sensor, the data will be
processed by the controller. In this work, Smart types of sensors are used namely brain
wave sensor. The controller works with C programming and for this project there are
three parts of coding which include EEG sensor and LCD. LCD is used to display the
result. Thingspeak is used to store the results of the EEG sensor got at different times.
25
Figure 6.3 The 10 - 20 International system of EGG electrode placement.
The first part of this project consisted of obtaining data from humans. An
experimental inductive stress procedure is carried out with the aim of eliciting emotional
changes in several subjects within a controlled and as realistic as possible laboratory
environment. To carry out this experiment, data were collected from six men and four
women, all of them students between the ages of 18 and 38.
• 3D Puzzle
The subject was asked to solve a 3-dimensional puzzle in a limited time. After
watching a relaxing video, the subject had a limit of seven minutes to solve the puzzle.
When there were only two minutes left, the subject was alerted to try to make them
nervous. At the end of the test the subject is shown the solution. Sometimes the solution
on paper is more difficult to understand than doing the puzzle itself, which adds
frustration and stress.
• Mathematical calculations
26
calculations in a limited time, in this case three minutes.
• Video game
The subject was provided with a musical mobile game that incorporates an
increasing difficulty. Depending on the subject’s knowledge of this type of video game,
the difficulty was adjusted to challenge the subject. Apart from the tests themselves, an
attempt was made to generate a stressful environment and the subject’s reactions and
behaviors were noted while monitoring the experiment.
3D Puzzle 7 210.000
To perform the EEG data preprocessing, the Python MNE library, a package for
visualizing and analyzing human neurophysiological data, was used. There are several
methodologies for working with EEG data. The following steps have been chosen for
this project, adapted from the manual Introduction to EEG preprocessing.
Methodological working in imaging neuroscience.
The first step after importing the raw EEG data is to define the type of acquisition
channel. In this project all channels were EEG. Next, the electrode assembly that was used
with the ENOBIO device must be selected, in this case a standard_1020, since 19
electrodes were used.
The next step is to apply a 500 Hz down sampling, which reduces the data size. After
down sampling, the data has been stored as .csv file. Additional physiological artifact is
removed.
Then, an ICA analysis is applied to detect the ocular components and separate them
from the brain components. ICA is a common practice that consists of searching for a
linear transformation that minimizes the statistical dependence between the components
involved in the signal to subsequently eliminate artifactual sources from each EEG
sample and reconstruct the signals without these components.
28
Figure 6.4 Example of ocular artifact in an ICA analysis
Channels were interpolated using the spherical spline method, which projects the
sensor locations onto a unit sphere and interpolates the signal at the bad sensor locations
based on the signals from the good locations.
29
6.7 RE-REFERENCE
In EEG data recording, the most typical references are the vertex electrode (Cz),
single or linked earlobes, or the tip of the nose. There is no consensus on which is the
most appropriate method, but some studies claim that earlobes introduce more noise than
a scalp channel.
In this project, all channels were re-referenced from the earlobe (GND) to the Cz
electrode, since the chosen configuration is symmetrical.
● Crop
This step consists in performing a crop of the dataset for each subject test. Thus,
seven datasets (three tests and four relaxation videos) are created for each subject, one
per step of the protocol, which will allow us to easily label the samples later.
Windowing consists of dividing a signal into different windows with the same length
(and, therefore, with the same number of samples) to later apply some transformation and
calculate different characteristics that summarize the information of the window. These
windows can have overlapping, which means that two consecutive windows share a
percentage of their data. Two approaches have been followed for feature extraction. The
first approach followed is like the one described in A Simplified CNN Classification
30
Method for MI-EEG via the Electrode Pairs Signals. Front. Smoke. Neurosis. 2020 by
Xiangmin Lun et al., using only the values of the filtered signals and without performing
feature extraction beyond calculating the mean and standard deviations of the chosen
windows for each channel.
The second procedure consisted of calculating the Delta, Theta, Alpha, Beta and
Gamma bands (also known as brain rhythms) of each window, since they are related to
the different mental states, as shown in previous studies such as Somayeh Mohammady’s
Wavelet Theory. As there is no standard definition of the range that defines each of the
bands, the ranges defined in the book Wavelet.
Delta 0-4
Theta 4-8
Alpha 8 - 14
Beta 14 - 30
Gamma 30 - 45
In both cases, windows of 500 samples were selected, so that each window
represented 1 second, since, as mentioned above, the sampling frequency is 500 samples
per second. Since there is no consensus on whether overlapping is preferable for EEG data,
two datasets were created for each approach, one without overlapping and one with an
overlapping of 250 samples.
31
6.8 ECG & GSR DATA PREPROCESSING
For the preprocessing of the ECG signals, a high-pass filter was applied to eliminate
noise. In the case of the GSR signals, a mean normalization was applied, since each
subject has a different sweating level and the environmental conditions (temperature and
humidity) of the laboratory may not coincide between subjects. Subsequently, as with the
EEG signals, two approaches were followed, one without overlapping windows and the
other with an overlapping of 250 samples. These physiological data have been used to
make a comparison with the EEG data in the classification results. Once the data had
been preprocessed, labelling was carried out and the classes were checked to see if they
were balanced to subsequently train the models.
6.9 LABELLING
In a first stage, labelling aims to consider the problem as a binary one; stress versus
relaxation. But as in some samples it was not clear whether the subject was stressed or
relaxed, a third class called neutral has been added. To decide with which state to label
each time, the ECG and GSR data recorded with the Biopac and the interviews conducted
with the subjects after the experiment, where each one assessed which test and which
specific moments had caused them more stress, were used as a reference.
32
CHAPTER 7
RESULT ANALYSIS
To test the hypothesis about the contribution of EEG to stress detection, several
experimental scenarios have been carried out are as follows.
• EEG data with different feature extraction technique, to select the best set of
features.
• EEG data without overlapping and with overlapping of 250 samples, to select the
best windowing approach.
• A binary classification of stress/relax vs the rest, to check if there is a class with
dubious labelling.
• A comparison between EEG data, ECG/GSR data and the combination of both, to
assess whether EEG data make a significant contribution to prediction.
• An intrasubject classification, to test whether samples from any subject cause
conflicts in the classification and whether there is gender bias.
All experiments have been tested with the four different machine learning techniques
(LightGBM, KNN, SVM and CNN). As mentioned in the methodology section, all
models have been trained with the same data and the same proportion of train (80%) and
test (20%) partitions were used to classify mental state according to stress level. To
validate the results, a 5-Fold cross-validation has been applied. Therefore, the data are
split into 5 folds and in each iteration one of these folds is used to test the model while the
rest are used to train the model.
33
These results might indicate that frequency bands are not very suitable for predicting
stress following the methodology of this experiment. Since EEG signals are time-
continuous data, the effect of applying overlap on the samples had to be tested.
As the table shows, no improvement is observed in any model and in the case of
LightGBM, the accuracy in the test set decreases to 86.24%.
In the previous predictions, a tendency of the models to misclassify the neutral state
was observed. For this reason, the three-class classification problem was reduced to a
binary stress/relax problem. In the stress vs. relax case, the accuracy of the best model
(LightGBM) in the above tests was reduced to 80.65% while the CNN increased to
69.03%. On the other hand, in the relax versus rest classification, both LightGBM and
KNN significantly increased the accuracy.
The next step was to compare the results of the best model trained only with EEG
data, in this case the LightGBM without feature extraction and overlap, with the results
obtained from training the same models with ECG and GSR data recorded with Biopac
and with the combination of EEG, ECG and GSR data.
The results show that combining EEG signals with ECG and GSR signals provides
a significant improvement in prediction over using EEG signals alone. This increase is
more than 4% in the LightGBM model and 3% in the KNN model. On the other hand,
combining the signals results in an 8% increase in accuracy compared to using only the
physiological signals from the Biopac.
34
CHAPTER 8
CONCLUSION AND FUTURE ENHACEMENT
8.1 CONCLUSION
In conclusion, our project aims to address the critical need for early detection of
stress through the utilization of Electroencephalogram (EEG) data. By capturing EEG
signals and processing them using C programming, a system capable of understanding
and recognizing stress levels is developed. The integration of an LCD display enables
real-time feedback of the results, providing users with immediate insights into their stress
levels. Furthermore, by leveraging Thingspeak for data storage, the availability of
historical data for further analysis and monitoring is ensured. Overall, it contributes to
preventive healthcare by enabling early intervention and potentially reducing the risk of
clinical brain damage associated with prolonged stress.
Enhancements for the system could include improving the accuracy of stress detection
algorithms through the utilization of machine learning techniques. Personalized feedback and
recommendations based on individual stress patterns and preferences could enhance user
engagement and effectiveness. Integration with wearable devices for continuous monitoring
and feedback would offer users a more seamless approach to stress management. Expanding
data storage capabilities and implementing advanced analytics for trend analysis could provide
valuable insights into long-term stress patterns and their health impacts. Additionally, exploring
opportunities for integrating biofeedback mechanisms for real-time stress reduction techniques
could offer users immediate relief during stressful situations. These enhancements aim to
elevate the system's capabilities and contribute to more proactive and personalized stress
management solutions.
35
APPENDIX
if nargout > 0
varargout = { [] [] 0 {} [] };
end
% add paths
% ---------
if ~isdeployed
tmp = which('eeglab_data.set');
if ~isempty(which('eeglab_data.set')) && ~isempty(which('Standard-10-10-
Cap47.ced'))
tmpWarning = warning('query', 'backtrace');
warning off backtrace;
warning(sprintf([ '\n\nPath Warning: It appears that you have added the path to all
of the\n' ...
'subfolders to EEGLAB. This may create issues with some EEGLAB
extensions\n' ...
'If EEGLAB cannot start or your experience a large number of warning\n' ...
'messages, remove all the EEGLAB paths then go to the EEGLAB folder\n' ...
'and start EEGLAB which will add all the necessary paths.\n\n' ]));
warning(tmpWarning.state, 'backtrace');
foldertorm = fileparts(which('fgetl.m'));
if ~isempty(strfind(foldertorm, 'eeglab'))
rmpath(foldertorm);
end
foldertorm = fileparts(which('strjoin.m'));
if ~isempty(strfind(foldertorm, 'eeglab'))
rmpath(foldertorm);
end
end
myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]);
myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]);
myaddpath( eeglabpath, ['@mmo' filesep 'mmo.m'], 'functions');
myaddpath( eeglabpath, 'readeetraklocs.m', [ 'functions' filesep 'sigprocfunc' ]);
myaddpath( eeglabpath, 'supergui.m', [ 'functions' filesep 'guifunc' ]);
myaddpath( eeglabpath, 'pop_study.m', [ 'functions' filesep 'studyfunc' ]);
myaddpath( eeglabpath, 'pop_loadbci.m', [ 'functions' filesep 'popfunc' ]);
myaddpath( eeglabpath, 'statcond.m', [ 'functions' filesep 'statistics' ]);
myaddpath( eeglabpath, 'timefreq.m', [ 'functions' filesep 'timefreqfunc' ]);
myaddpath( eeglabpath, 'icademo.m', [ 'functions' filesep 'miscfunc' ]);
40
myaddpath( eeglabpath, 'eeglab1020.ced', [ 'functions' filesep 'supportfiles' ]);
addpathifnotinlist(fullfile(eeglabpath, 'plugins'));
eeglab_options;
% remove BIOSIG path which are not needed and might cause conflicts
biosigp{1} = fileparts(which('sopen.m'));
biosigp{2} = fileparts(which('regress_eog.m'));
biosigp{3} = fileparts(which('DecimalFactors.txt'));
removepath(fileparts(fileparts(biosigp{1})), biosigp{:})
else
eeglab_options;
end
evalin('base', 'eeg_global;');
if nargin < 1 || exist('EEG') ~= 1
EEG = [];
ALLEEG = [];
CURRENTSET = [];
ALLCOM = [];
LASTCOM = [];
STUDY =[];
CURRENTSTUDY = 0;
EEG = eeg_emptyset;
eegh('[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;');
if ismatlab && get(0, 'screendepth') <= 8
disp('Warning: screen color depth too low, some colors will be inaccurate in time-
frequency plots');
end
end
versL = ~option_allmenus;
if nargin == 1
if strcmp(onearg, 'versions')
disp( [ 'EEGLAB v' eeg_getversion ] );
elseif strcmp(onearg, 'nogui')
if nargout < 1, clear ALLEEG; end % do not return output var
elseif strcmp(onearg, 'redraw')
W_MAIN = findobj('tag', 'EEGLAB');
if ~isempty(W_MAIN)
42
updatemenu;
if nargout < 1, clear ALLEEG; end % do not return output var
return;
else
eegh('eeglab(''redraw'');');
end
elseif strcmp(onearg, 'rebuild')
W_MAIN = findobj('tag', 'EEGLAB');
close(W_MAIN);
eeglab redraw;
return;
elseif strcmp(onearg, 'full')
versL = false;
else
fprintf(2,['EEGLAB Warning: Invalid argument ''' onearg '''. Restarting EEGLAB
interface instead.\n']);
eegh('[ALLEEG EEG CURRENTSET ALLCOM] = eeglab(''rebuild'');');
end
else
onearg = 'rebuild';
end
ALLCOM = ALLCOM;
try, colordef('white'); catch end
if versL
disp('Some menus items hidden. Use Preference menu to show them all.');
end
% checking strings
% ----------------
e_try = 'try,';
43
e_catch = 'catch, eeglab_error; LASTCOM= ''''; clear EEGTMP ALLEEGTMP
STUDYTMP; end;';
nocheck = e_try;
ret = 'if ~isempty(LASTCOM), if LASTCOM(1) == -1, LASTCOM = '''';
return; end; end;';
check = ['[EEG LASTCOM] = eeg_checkset(EEG, ''data'');' ret '
eegh(LASTCOM);' e_try];
checkcont = ['[EEG LASTCOM] = eeg_checkset(EEG, ''contdata'');' ret '
eegh(LASTCOM);' e_try];
checkica = ['[EEG LASTCOM] = eeg_checkset(EEG, ''ica'');' ret '
eegh(LASTCOM);' e_try];
checkepoch = ['[EEG LASTCOM] = eeg_checkset(EEG, ''epoch'');' ret '
eegh(LASTCOM);' e_try];
checkevent = ['[EEG LASTCOM] = eeg_checkset(EEG, ''event'');' ret '
eegh(LASTCOM);' e_try];
checkbesa = ['[EEG LASTCOM] = eeg_checkset(EEG, ''besa'');' ret ' eegh(''% no
history yet for BESA dipole localization'');' e_try];
checkepochica = ['[EEG LASTCOM] = eeg_checkset(EEG, ''epoch'', ''ica'');' ret '
eegh(LASTCOM);' e_try];
checkplot = ['[EEG LASTCOM] = eeg_checkset(EEG, ''chanloc'');' ret '
eegh(LASTCOM);' e_try];
checkicaplot = ['[EEG LASTCOM] = eeg_checkset(EEG, ''ica'', ''chanloc'');' ret '
eegh(LASTCOM);' e_try];
checkepochplot = ['[EEG LASTCOM] = eeg_checkset(EEG, ''epoch'', ''chanloc'');' ret '
eegh(LASTCOM);' e_try];
checkepochicaplot = ['[EEG LASTCOM] = eeg_checkset(EEG, ''epoch'', ''ica'',
''chanloc'');' ret ' eegh(LASTCOM);' e_try];
44
storecall = '[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
eegh(''[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);'');';
storenewcall = '[ALLEEG EEG CURRENTSET LASTCOM] = pop_newset(ALLEEG,
EEG, CURRENTSET, ''study'', ~isempty(STUDY)+0); eegh(LASTCOM);';
storeallcall = [ 'if ~isempty(ALLEEG) && ~isempty(ALLEEG(1).data), ALLEEG =
eeg_checkset(ALLEEG);' ...
'EEG = eeg_retrieve(ALLEEG, CURRENTSET); eegh(''ALLEEG =
eeg_checkset(ALLEEG); EEG = eeg_retrieve(ALLEEG, CURRENTSET);''); end;' ];
% nh = no dataset history
% -----------------------
e_storeall_nh = [e_catch 'eegh(LASTCOM);' ifeeg storeallcall 'disp(''Done.''); end;
eeglab(''redraw'');'];
e_hist_nh = [e_catch 'eegh(LASTCOM);'];
% study checking
% --------------
e_check_study = 'if length(EEG) > 1 && CURRENTSTUDY == 1, STUDY =
std_checkset(STUDY, ALLEEG); eegh(''STUDY = std_checkset(STUDY,
ALLEEG);''); end;';
e_load_study = [e_catch 'if ~isempty(LASTCOM), STUDY = STUDYTMP; STUDY =
eegh(LASTCOM, STUDY); ALLEEG = ALLEEGTMP; EEG = ALLEEG;
45
CURRENTSET = [1:length(EEG)]; eegh(''CURRENTSTUDY = 1; EEG = ALLEEG;
CURRENTSET = [1:length(EEG)];''); CURRENTSTUDY = 1; disp(''Done.''); end;
clear ALLEEGTMP STUDYTMP; eeglab(''redraw'');'];
e_plot_study = [e_catch 'if ~isempty(LASTCOM), STUDY = STUDYTMP; STUDY =
eegh(LASTCOM, STUDY); disp(''Done.''); end; clear ALLEEGTMP STUDYTMP;
eeglab(''redraw'');']; % ALLEEG not modified
% detecting icalab
% ----------------
if exist('icalab')
disp('ICALAB toolbox detected (algo. added to "run ICA" interface)');
end
46
% add the paths
% -------------
if strcmpi(eeglabpath, './') || strcmpi(eeglabpath, '.\'), eeglabpath = [ pwd filesep ]; end
% add paths
% ---------
if ~isdeployed
tmp = which('eeglab_data.set');
if ~isempty(which('eeglab_data.set')) && ~isempty(which('Standard-10-10-Cap47.ced'))
tmpWarning = warning('query', 'backtrace');
warning off backtrace;
47
warning(sprintf([ '\n\nPath Warning: It appears that you have added the path to all of
the\n' ...
'subfolders to EEGLAB. This may create issues with some EEGLAB extensions\n' ...
'If EEGLAB cannot start or your experience a large number of warning\n' ...
'messages, remove all the EEGLAB paths then go to the EEGLAB folder\n' ...
'and start EEGLAB which will add all the necessary paths.\n\n' ]));
warning(tmpWarning.state, 'backtrace');
foldertorm = fileparts(which('fgetl.m'));
if ~isempty(strfind(foldertorm, 'eeglab'))
rmpath(foldertorm);
end
foldertorm = fileparts(which('strjoin.m'));
if ~isempty(strfind(foldertorm, 'eeglab'))
rmpath(foldertorm);
end
end
myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]);
myaddpath( eeglabpath, 'eeg_checkset.m', [ 'functions' filesep 'adminfunc' ]);
myaddpath( eeglabpath, ['@mmo' filesep 'mmo.m'], 'functions');
myaddpath( eeglabpath, 'readeetraklocs.m', [ 'functions' filesep 'sigprocfunc' ]);
myaddpath( eeglabpath, 'supergui.m', [ 'functions' filesep 'guifunc' ]);
myaddpath( eeglabpath, 'pop_study.m', [ 'functions' filesep 'studyfunc' ]);
myaddpath( eeglabpath, 'pop_loadbci.m', [ 'functions' filesep 'popfunc' ]);
myaddpath( eeglabpath, 'statcond.m', [ 'functions' filesep 'statistics' ]);
myaddpath( eeglabpath, 'timefreq.m', [ 'functions' filesep 'timefreqfunc' ]);
myaddpath( eeglabpath, 'icademo.m', [ 'functions' filesep 'miscfunc' ]);
myaddpath( eeglabpath, 'eeglab1020.ced', [ 'functions' filesep 'supportfiles' ]);
addpathifnotinlist(fullfile(eeglabpath, 'plugins'));
eeglab_options;
48
A.2 SCREEN SHOTS
49
Figure A.3 ERP image with large number of trials
50
Figure A.5 PSD mapping
51
REFERENCES
52