Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Brainwaves Stress Pattern Based On Perceived Stress Scale Using Deep Learning

Uploaded by

Shivasangari G A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Brainwaves Stress Pattern Based On Perceived Stress Scale Using Deep Learning

Uploaded by

Shivasangari G A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

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)

in partial fulfillment for the award of


the degree of

BACHELOR OF ENGINEERING

IN

COMPUTER SCIENCE AND ENGINEERING

VIVEKANANDHA COLLEGE OF TECHNOLOGY FOR WOMEN


ELAYAMPALAYAM, TIRUCHENGODE-637 205

ANNA UNIVERSITY : CHENNAI 600 025

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

HEAD OF THE DEPARTMENT SUPERVISOR


Computer Science and Engineering Computer Science and Engineering

Vivekanandha College of Vivekanandha College of

Technology for Women, Technology for Women,


Sathinaickanpalayam, Sathinaickanpalayam,

Tiruchengode – 637 205 Tiruchengode – 637 205

Submitted for the project viva-voice examination held on .

INTERNAL EXAMINER EXTERNAL EXAMINER


ACKNOWLEDGEMENT
We would like to express our profound gratitude to our Honorable Chairman and Secretary
‘Vidhya Rathna’ Prof.Dr.M.KARUNANITHI,B.Pharm.,M.S., Ph.D.,D.Litt., and the
trust members who have provided all the facilities to develop our project successfully.

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 extremely grateful to our dignified Chief Executive


Mr.M.CHOCKALINGAM,M.Sc.,B.Ed., for allowing us to have maximum use of
facilities to do this project.

We are extremely thankful to our Principal Dr.M.DEVI,M.E.,Ph.D., for providing us an


opportunity to carry out this project.

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 indebted to our project guide Mr.P.DINESH KUMAR,M.E., and project


coordinator Mrs.R.AMSALEKA,M.E., for their valuable help and suggestion imparted
to us.

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

Stress is a ubiquitous aspect of human experience, yet identifying and classifying


stress levels presents unique challenges. A novel approach leveraging
Electroencephalogram (EEG) signals to detect and classify stress states using deep
learning techniques is proposed. The methodology involves the comprehensive analysis
of EEG signals to capture the full spectrum of brainwave frequencies. Principal
component analysis (PCA) is employed for feature dimensionality reduction, followed by
standard scaling to enhance signal processing efficiency. To characterize stress patterns,
we compute the Power Spectral Density (PSD) vector using the Welch method, comparing
healthy and unhealthy EEG signal groups. Subsequently, a voting classifier, combining
deep learning classifiers, is employed to discern stress and relaxation states. The study
extends beyond EEG signals alone, integrating Electrocardiogram (ECG) and Galvanic
Skin Response (GSR) data obtained with the Neuro electrics ENOBIO and Node MCU
systems, respectively. While previous research has explored EEG or ECG/GSR signals
independently for mental state classification, fewer studies have examined the synergistic
benefits of combining EEG with other physiological signals. Each model is rigorously
evaluated against relaxation videos interspersed within test sessions, with data labelled
into stress, relaxation, or neutral classes based on ECG and GSR values. By elucidating
the optimal machine learning approach, it contributes to the advancement of stress
detection methodologies, with implications for diverse fields ranging from healthcare to
performance optimization.

iv
TABLE OF CONTENTS

CHAPTER NO. TITLE PAGE NO.

ABSTRACT iv

LIST OF TABLES vii

LIST OF FIGURES viii

LIST OF ABBREVIATIONS ix

1 INTRODUCTION 1

1.1 OVERVIEW 1

1.2 DEEP LEARNING 1

1.3 WORKING OF DEEP LEARNING 2

1.4 SIGNAL PROCESSING 3

1.5 DEEP LEARNING IN HEALTHCARE 3

1.6 PROJECT OVERVIEW 4

1.7 STAGES OF BRAIN STRESS 4

1.8 SUMMARY 5
2 LITERATURE SURVEY 6

2.1 PHYSIOLOGICAL STRESS LEVEL 6


DETECTION BASED ON ELECTRO
DERMAL ACTIVITY

2.2 A SELF-PACED RELAXATION 7

v
RESPONSE DETECTION SYSTEM
BASED ON GALVANIC SKIN
RESPONSE ANALYSIS

2.3 LITERATURE SURVEY SUMMARY 8


3 SYSTEM ANALYSIS 10

3.1 PROBLEM DEFINITION 10

3.2 EXISTING SYSTEM 10

3.3 PROPOSED SYSTEM 11


4 SYSTEM REQUIREMENTS 13

4.1 HARDWARE REQUIREMENTS 13

4.2 SOFTWARE REQUIREMENTS 13

4.3 MATLAB DESCRIPTION 13

4.3.1 KEY FEATURES OF MATLAB 13

4.3.2 APPLICATIONS OF MATLAB 15


5 ALGORITHM DESCRIPTION 16

5.1 DISCRETE WAVELET TRANSFORM 16

5.2 FUZZY KNN ALGORITHM 18

5.3 VGG-16 ARCHITECTURE 21


6 PROPOSED METHODOLOGY 24

6.1 EXPERIMENT AND METHODOLOGY 24

6.2 PROCESS FLOW 25

6.3 DATA COLLECTION 26

vi
6.4 EGG DATA PREPROCESSING 28

6.5 DOWN SAMPLING 28

6.6 INTERPOLATE BAD CHANNELS 29

6.7 RE-REFERENCE 30

6.8 ECG & GSR DATA PREPROCESSING 32

6.9 LABELLING 32
7 RESULT ANALYSIS 33

7.1 1BINARY VERSUS MULTICLASS 34


PROBLEM

7.2 EGG ALONE VERSUS EGG WITH ECG 34


& GSR
8 CONCLUSION AND FUTURE 35
ENHANCEMENT

8.1 CONCLUSION 35

8.2 FUTURE ENHANCEMENT 35


9 APPENDIX 36

A.1 SAMPLE CODING 36

A.2 SCREEN SHOTS 49


10 REFERENCES 54

vii
LIST OF TABLES

TABLE NO. TABLE NAME PAGE NO.

1 Test Sample 26

2 Frequency Bands 30

vii
LIST OF FIGURES

FIGURE NO. FIGURE NAME PAGE NO.

1.1 Neural networks 2

5.1 A guide for using the wavelet transform 16


in Machine Learning

5.2 System 18

5.3 Clustering in Machine Learning 19

5.4 The essential neural network 20

5.5 Understanding the Softmax function in 21


minutes

5.6 Face Recognition with VGG16 22

6.1 Process map 23

6.2 Process Flow 24

6.3 The 10-20 International system of EGG 25


electrode placement

6.4 Example of Ocular artifact in an ICA 28


analysis

6.5 EG Electro physiological Monitoring 28


Method

6.6 Re-reference to Cz 29

6.7 Labelling with ECG and GSR signal 31

viii
LIST OF ABBREVIATIONS

ABBREVIATION EXPANSION

EEG - Electro Encephalo Gram

PCA - Principal Component Analysis

PSD - Power Spectral Density

MCU - Happy People Images

GSR - Micro Controller Unit

KNN - K-Nearest Neighbors

GBM - Gradient Boosting Machine

SVM - Support Vector Machine

ANN - Artificial Neural Networks

DNN - Deep Neural Networks

CNN - Convolutional Neural Networks

ECG - Electro Cardio Gram

EDA - Electro Dermal Activity

LSTM - Long Short-Term Memory

PD - Pupilar Diameter

SK - Skin Temperature

BVP - Blood Volume Pulse

VR - Virtual Reality

RResp - Relaxation Response

DWT - Discrete Wavelet Transform

ix
VGG - Visual Geometry Group

ICA - Independent Component Analysis

LCD - Liquid Crystal Display

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.

1.2 DEEP LEARNING

Deep learning is a branch of machine learning which is completely based on


artificial neural networks, as neural network is going to mimic the human brain so deep
learning is also a kind of mimic of human brain. The concept of deep learning is not new.
It has been around for a couple of years now. It is hype nowadays because earlier it did
not have that much processing power and a lot of data. As in the last 20 years, the
processing power increases exponentially, deep learning and machine learning came into
the picture. A formal definition of deep learning is neurons Deep Learning is a subset of
1
Machine Learning that is based on artificial neural networks (ANNs) with multiple layers,
also known as deep neural networks (DNNs). These neural networks are inspired by the
structure and function of the human brain, and they are designed to learn from large
amounts of data in an unsupervised or semi-supervised manner.

1.3 WORKING OF DEEP LEARNING

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.

Figure 1.1 Neural networks

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.

1.4 SIGNAL PROCESSING

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.

1.5 DEEP LEARNING IN HEALTHCARE

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.

1.6 PROJECT OVERVIEW

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.

1.7 STAGES OF BRAIN STRESS

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

Addressing the pervasive issue of stress, electroencephalographic (EEG) signals


offer a non-invasive means to capture stress-related emotions. Leveraging deep learning,
particularly convolutional neural networks (CNNs), facilitates efficient analysis of EEG
data for stress classification. The objective is to classify stress and calm brain states using
EEG data, comparing different machine learning techniques and exploring the feasibility
of using EEG wearables for stress assessment.

5
CHAPTER 2
LITERATURE SURVEY

2.1 PHYSIOLOGICAL STRESS LEVEL DETECTION BASED ON ELECTRO


DERMAL ACTIVITY

J. Zhai et al. developed a stress assessment system utilizing four physiological


signals: electrodermal activity (EDA), skin temperature (ST), blood volume pulse (BVP),
and pupil diameter (PD). They employed SVM, NB, and decision trees for classifying
resting and stress states. Y. Deng et al. emphasized the significance of feature selection
in similar studies, proposing a Principal Component Analysis (PCA) method. They
evaluated the efficacy of feature selection using five classification algorithms: SVM,
Naïve Bayes, KNN, Linear Discriminant Function, and C4.5 induction tree.

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.

2.2 A SELF-PACED RELAXATION RESPONSE DETECTION SYSTEM


BASED ON GALVANIC SKIN RESPONSE ANALYSIS

R. Martinez et al. designed a system to identify Relaxation Response (RResp), the


bodily reaction of an individual when relaxing that positively affects the organism
regardless of its emotional state. Analyzing only the GSR signal, the authors identified
three levels of RResp (Low Relaxation Response, Medium Relaxation Response and
High Relaxation Response) that could be quantified with two calculated features and
classified using a decision tree.

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

SL Title, Author and year Technology Problem Advantages


No Description and
Limitations

1 Vitals: Camera based Deep Utilizes remote Advantages:


Physiological Monitoring Learning photoplethysmo- Have
and Health Management Graphy for non- potential for
Platform by Kwan Long contact vital signs widespread
Wong, Jing Wei chin and measurement, adoption and
Richard.H.Y.So offering a practical integration
IEEE 2022 and cost-effective into daily
solution for digital routines.
health. Limitations:
Lacks
precision

2 Psychosocial Demands Deep Investigating the Advantages:


and the Acceptance Learning impact of Provide
of Mental Health Risk psychosocial valuable
Monitoring Systems at demands on the insights into
Work by Veera Barbara perceived factors
Rick, Christopher Brandl usefulness and influencing
and Alexander Mertens behavioral the
IEEE 2022 intention to use acceptance
mental health risk of health
monitoring monitoring
systems among technologies
office workers. Limitations:
Lacks
Precision via
specificity of
analysis

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

3.1 PROBLEM DEFINITION

• 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.

3.2 EXISTING SYSTEM

The proposed stress detection system constitutes a multifaceted approach,


integrating advanced technology with methodological rigor to assess stress levels
reliably. At its core, the system relies on an EEG signal acquisition unit, leveraging the
sophisticated Emotiv Epoc neuroheadset, renowned for its precision in capturing neural
activity. Complementing this hardware component is a sophisticated Matlab module
meticulously designed for processing EEG signals with precision and efficiency,
ensuring accurate classification of stress levels. To uphold data integrity and fidelity,
stringent protocols are enforced during EEG data acquisition. Subjects are carefully
instructed to minimize head and muscular movements to mitigate potential artifacts,
safeguarding the reliability of the recorded signals. This meticulous approach
underscores the commitment to scientific rigor and ensures the integrity of the
experimental data.
The experiment unfolds in two distinct phases, meticulously designed to elucidate
the dynamics of stress response. Firstly, a comprehensive training phase provides subjects
with a familiarization process, enabling them to acclimate to the experimental procedures
and tasks. Subsequently, the testing phase unfolds, wherein subjects are exposed to

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.

3.3 PROPOSED SYSTEM

A comprehensive exploration of stress detection methodologies utilizing EEG signals


has been meticulously conducted. Through a meticulously designed stress induction
experiment involving ten subjects, a wealth of physiological data has been collected.
Following this data acquisition phase, four distinct models have been meticulously trained:
Light-GBM, a 16-layer Convolutional Neural Network (CNN), K-Nearest Neighbors
(KNN), and Support Vector Machine (SVM). The primary objective of this Master's Thesis
is to discern stress and calm brain states from EEG data acquired during the aforementioned
stress induction experiment. Furthermore, this study aims to juxtapose these EEG-based
classifications with those derived from other biological signals, such as Galvanic Skin
Response (GSR or EDA) and Electrocardiogram (ECG), thereby providing a holistic
understanding of stress dynamics.

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

4.1 HARDWARE REQUIREMENTS

Processor : Intel®core™i5-2410M CPU@2.30GHz processor


Speed : 2.30 GHz
Operating System : 64-bit operating system
RAM : 4 GB RAM

4.2 SOFTWARE REQUIREMENTS

Idle : MATLAB
Operating System : Windows 10

4.3 MATLAB DESCRIPTION

MATLAB (Matrix Laboratory) is a powerful computational software environment


developed by MathWorks. It is widely used across various industries and academic
disciplines for numerical computing, data analysis, algorithm development, and
visualization. MATLAB provides a comprehensive suite of tools for solving complex
mathematical problems, simulating systems, and analysing data efficiently.

4.3.1 KEY FEATURES OF MATLAB

• 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

MATLAB offers an extensive collection of built-in functions and libraries for


developing algorithms across various domains such as signal processing, image
processing, control systems, and machine learning.

● 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

MATLAB's plotting and visualization capabilities allow users to create high-


quality 2D and 3D plots, graphs, and animations to illustrate their data and results. This
feature aids in understanding complex relationships within the data and communicating
findings effectively.

• Application Development

MATLAB can be used to develop standalone applications, graphical user


interfaces (GUIs), and web applications. This flexibility makes it suitable for prototyping,
deploying, and sharing computational solutions with others.

• Integration

MATLAB seamlessly integrates with other programming languages such as


C/C++, Python, and Java, enabling users to leverage existing code and libraries within
MATLAB environments.

● Parallel Computing

MATLAB supports parallel computing across multicore processors, clusters, and


cloud environments. This feature enhances computational performance and scalability for
14
computationally intensive tasks.

4.3.2 APPLICATIONS OF MATLAB

• Engineering and Science

MATLAB is extensively used in engineering disciplines such as electrical,


mechanical, and aerospace engineering for modeling, simulation, and analysis of systems.

• Data Science and Machine Learning

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

MATLAB is employed in financial modeling and quantitative analysis for


portfolio optimization, risk management, and algorithmic trading strategies.

• Biomedical Research

MATLAB finds applications in biomedical research for image processing, signal


analysis, and modeling physiological systems.

• Academic Research and Education

MATLAB is widely adopted in academic institutions for teaching and research


purposes across various disciplines due to its ease of use and versatility.

15
CHAPTER 5
ALGORITHM DESCRIPTION

5.1 DISCRETE WAVELET TRANSFORM

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.

The Discrete Wavelet Transform has:

● For small frequency values a high resolution in the frequency domain, low

resolution in the time- domain,


● or large frequency values a low resolution in the frequency domain, high resolution

in the time domain.


In other words, the Wavelet Transform makes a trade-off; at scales in which time-
dependent features are interesting it has a high resolution in the time-domain and at scales
in which frequency-dependent features are interesting it has a high resolution in the
frequency domain.

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:

● In PyWavelets the DWT is applied with pywt.dwt()


● The DWT return two sets of coefficients; the approximation coefficients and
detail coefficients.
● The approximation coefficients represent the output of the low pass filter (averaging
filter) of the DWT.
● The detail coefficients represent the output of the high pass filter (difference filter)
of the DWT.
● By applying the DWT again on the approximation coefficients of the previous DWT,
17
the wavelet transforms of the next level.
● At each next level, the original signal is also sampled down by a factor of 2.

The DWT is implemented as a filter bank; At each subsequent level, the


approximation coefficients are divided into a coarser low pass and high pass part and the
DWT is applied again on the low-pass part.
The original signal is now converted to several signals each corresponding to
different frequency bands. Later, the approximation and detail coefficients at the different
frequency sub-bands can be used in applications like removing high frequency noise from
signals, compressing signals, or classifying the different types signals.
The pywt.wavedec() is also used to immediately calculate the coefficients of a higher
level. This function takes as input the original signal and the level and returns the one set
of approximation coefficients (of the n-th level) and n sets of detail coefficients (1 to n-th
level).
This idea of analyzing the signal on different scales is also known as multiresolution
/ multiscale analysis, and decomposing the signal in such a way is also known as
multiresolution decomposition, or sub-band coding.

5.2 FUZZY KNN ALGORITHM:


In the area of research and application, classification of objects is important. k-
nearest neighbor algorithm (k-NN) is a non-parametric method used for classification and
regression. In both cases, the input consists of the k closest training examples in the feature
space. The output depends on whether k- NN is used for classification or regression. The
theory of fuzzy sets is introduced into the k-nearest Neighbor technique to develop a fuzzy
version of the algorithm. Three Methods of assigning fuzzy memberships to the labeled
samples are proposed, and experimental results and comparisons to the crisp version are
presented. In fact, not only does the fuzzy algorithm dominate its counterpart in terms of
a lower error rate, the resulting memberships give a confidence measure of the
classification. The fuzzy K-NN rule is also shown to compare well against other standard,
more sophisticated pattern recognition procedures in these experiments.
18
Figure 5.2 system
achieve rate

The Formula for the calculation is,

……………………………..(1)

19
• K MEANS CLUSTERING

K-Means Clustering is an Unsupervised Learning algorithm, which groups the


unlabeled dataset into different clusters. Here K defines the number of pre-defined
clusters that need to be created in the process, as if K=2, there will be two clusters, and
for K=3, there will be three clusters, and so on. It allows us to cluster the data into different
groups and a convenient way to discover the categories of groups in the unlabeled dataset
on its own without the need for any training. It is a centroid-based algorithm, where each
cluster is associated with a centroid. The main aim of this algorithm is to minimize the sum
of distances between the data point and their corresponding clusters.
The algorithm takes the unlabeled dataset as input, divides the dataset into k-number of
clusters, and repeats the process until it does not find the best clusters. The value of k
should be predetermined in this algorithm.

Figure 5.3 Clustering in machine learning

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.

5.3 VGG16 ARCHITECTURE

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.

Figure 5.4 The Essential neural network

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

6.1 EXPERIMENT AND 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.

Figure 6.1 Process map


igure 8: Flow chart
24
The data collected from all subjects are used to construct the prediction models
(multisubject model). This is a decision that favors the availability of a larger amount of
data, which are subsequently analyzed in the experimental work performed.

6.2 PROCESS FLOW:


Experiment protocol/Set up

Cohen’s PSS-10 Stress


Measurement
EEG Data Acquisition
Cohen’s PSS-
10 Stress Score
EEG Raw Data

EEG Signal Transform


Categorize (time to frequency Domain)
Stress Group
based on
PSS-10 Score EEG Filtered Data

Compute ESD Value for Alpha Right,


Alpha Left, Beta Left, Beta Right

Mean ESD Value for Alpha Right,


Alpha Left, Beta Left, Beta Right

Human Stress Pattern

Figure 6.2 Process flow

25
Figure 6.3 The 10 - 20 International system of EGG electrode placement.

6.3 DATA COLLECTION

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

The experimenter sequentially proposed mathematical calculations of increasing


difficulty. As the subject answered each question correctly, another calculation of greater
difficulty was proposed. The objective was to answer the maximum number of

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.

Test Duration (min) Number of


samples
(approx.)

Relaxation video 1 2 60.000

3D Puzzle 7 210.000

Relaxation video 2 2 60.000

Mathematical calculations 3 90.000

Relaxation video 3 2 60.000

Video game 4 (approx.) 120.000

Relaxation video 4 2 60.000

Interview & survey - -

Table 1 Test Samples

Data acquisition results in two files for each subject

• An edf file which stores EEG data


• A csv file which gathers ECG and GSR data
27
6.4 EEG DATA PREPROCESSING

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.

● Working with metadata

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.

6.5 DOWN SAMPLING

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

6.6 INTERPOLATE BAD CHANNELS

As this is a multi-subject analysis, it is necessary to maintain the same


dimensionality for all subjects (same number of channels). Therefore, in this case it is
preferable to interpolate the bad channels instead of eliminating them, since the bad
channels do not have to coincide between subjects.

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.

Figure 6.5 EG Electro physiological Monitoring method

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.

Figure 6.6 Re-reference to Cz

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 and Feature Extraction

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.

Theories were applied

Frequency band Range (Hz)

Delta 0-4

Theta 4-8

Alpha 8 - 14

Beta 14 - 30

Gamma 30 - 45

Table 2 Frequency bands

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.

Figure 6.7 Labelling with ECG and GSR signal.

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.

To evaluate model results the metric used is accuracy in percentages (%)

ACCURACY = NUMBER OF CORRECT PREDICTIONS * 100


TOTAL NUMBER OF PREDICTIONS

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%.

7.1 Binary versus multiclass problem

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.

Analyzing these results, samples labeled as neutral in case of being misclassified


tend to be classified as stress while samples labeled as relax are easier to classify.

7.2 EEG alone versus EEG with ECG and GSR

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.

8.2 FUTURE ENHANCEMENT

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

A.1 SAMPLE CODING

function varargout = eeglab( onearg )


ver = version;
if strcmpi(ver, '9.4.0.813654 (R2018a)')
disp('Link to install <a
href="https://www.mathworks.com/downloads/web_downloads/download_update?rele
ase=R2018a&s_tid=ebrg_R2018a_2_1757132">2018a Update 2</a>');
errordlg( [ 'You are running Matlab version R2019a, which has important bugs' 10
'Matlab crashes when running EEGLAB in this version of Matlab' 10 'Install 2018a
Update 2 to fix the issue (link on the command line)' ]);
end

if nargout > 0
varargout = { [] [] 0 {} [] };
end

% check Matlab version


% --------------------
vers = version;
indp = find(vers == '.');
if str2num(vers(indp(1)+1)) > 1, vers = [ vers(1:indp(1)) '0' vers(indp(1)+1:end) ]; end
indp = find(vers == '.');
vers = str2num(vers(1:indp(2)-1));
tmpv = which('version');
if ~isempty(findstr(lower(tmpv), 'biosig'))
[tmpp tmp] = fileparts(tmpv);
rmpath(tmpp);
end
% remove freemat folder if it exist
tmpPath = fileparts(fileparts(which('sread')));
newPath = fullfile(tmpPath, 'maybe-missing', 'freemat3.5');
if exist(newPath) == 7
warning('off', 'MATLAB:rmpath:DirNotFound');
rmpath(newPath)
warning('on', 'MATLAB:rmpath:DirNotFound');
36
end
if ismatlab && vers < 7
tmpWarning = warning('query', 'backtrace');
warning('off', 'backtrace');
warning('This Matlab version is too old to run the current EEGLAB');
warning('Download EEGLAB 4.3b at
http://sccn.ucsd.edu/eeglab/eeglab4.5b.teaching.zip');
warning('This version of EEGLAB is compatible with all Matlab version down to
Matlab 5.3');
warning(tmpWarning.state, 'backtrace');
return;
end
if ismatlab && vers < 7.06
tmpWarning = warning('query','backtrace');
warning off backtrace;
warning('You are using a Matlab version older than 7.6 (2008a)');
warning('Some of the EEGLAB functions might not be functional');
warning('Download EEGLAB 4.3b at
http://sccn.ucsd.edu/eeglab/eeglab4.5b.teaching.zip');
warning('This version of EEGLAB is compatible with all Matlab version down to
Matlab 5.3');
warning( tmpWarning.state, 'backtrace');
end
if ~ismatlab
warning('off', 'Octave:abbreviated-property-match');
warning('off', 'Octave:legacy-function');
warning('off', 'Octave:num-to-str');
warning('off', 'backtrace');
warning('off', 'Octave:divide-by-zero');
try
pkg load statistics
catch
warning('Statistics module not found - type "pkg install -forge io" then "pkg
install -forge statistics" to install it');
end
try
pkg load signal
catch
37
warning('Signal processing module not found - type "pkg install -forge control"
then "pkg install -forge signal" to install it');
end
end

% check potential issues with strjoin


% -----------------------------------
strjoinPath = fileparts(which('strjoin'));
[~,strjoinPath2] = fileparts(strjoinPath);
if ~strcmpi(strjoinPath2, 'strfun')
warning(sprintf('Potential function conflict for strjoin.m located in "%s" \nWe
suggest removing the path from Matlab to avoid problems.', strjoinPath));
end

% check for duplicate versions of EEGLAB


% --------------------------------------
eeglabpath = mywhich('eeglab.m');
eeglabpath = eeglabpath(1:end-length('eeglab.m'));
if nargin < 1 && ~isdeployed
eeglabpath2 = '';
if strcmpi(eeglabpath, pwd) || strcmpi(eeglabpath(1:end-1), pwd)
cd('functions');
warning('off', 'MATLAB:rmpath:DirNotFound');
rmpath(eeglabpath);
warning('on', 'MATLAB:rmpath:DirNotFound');
eeglabpath2 = mywhich('eeglab.m');
cd('..');
else
try, rmpath(eeglabpath); catch, end
eeglabpath2 = mywhich('eeglab.m');
end
if ~isempty(eeglabpath2)
eeglabpath2 = eeglabpath2(1:end-length('eeglab.m'));
tmpWarning = warning('query', 'backtrace');
warning off backtrace;
disp('******************************************************');
warning('There are at least two versions of EEGLAB in your path');
warning(sprintf('One is at %s', eeglabpath));
38
warning(sprintf('The other one is at %s', eeglabpath2));
warning(tmpWarning.state, 'backtrace');
end
addpath(eeglabpath);
end

% add the paths


% -------------
if strcmpi(eeglabpath, './') || strcmpi(eeglabpath, '.\'), eeglabpath = [ pwd filesep ]; end

% solve BIOSIG problem


% --------------------
pathtmp = mywhich('wilcoxon_test');
if ~isempty(pathtmp)
try,
rmpath(pathtmp(1:end-15));
catch, end
end

% test for local SCCN copy


% ------------------------
if ~isdeployed
addpathifnotinlist(eeglabpath);
if exist( fullfile( eeglabpath, 'functions', 'adminfunc') ) ~= 7
warning('EEGLAB subfolders not found');
end
end

% determine file format


% ---------------------
fileformat = 'maclinux';
comp = computer;
try
if strcmpi(comp(1:3), 'GLN') || strcmpi(comp(1:3), 'MAC') || strcmpi(comp(1:3),
'SOL')
fileformat = 'maclinux';
elseif strcmpi(comp(1:5), 'pcwin')
fileformat = 'pcwin';
39
end
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 path to to fmrlab if neceecessary


path_runica = fileparts(mywhich('runica'));
if length(path_runica) > 6 && strcmpi(path_runica(end-5:end), 'fmrlab')
rmpath(path_runica);
end

% add path if toolboxes are missing


% ---------------------------------
if option_donotusetoolboxes
p1 = fileparts(mywhich('ttest'));
p2 = fileparts(mywhich('filtfilt'));
p3 = fileparts(mywhich('optimtool'));
p4 = fileparts(mywhich('gray2ind'));
if ~isempty(p1), rmpath(p1); end
if ~isempty(p2), rmpath(p2); end
if ~isempty(p3), rmpath(p3); end
if ~isempty(p4), rmpath(p4); end
end

% 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

% declare the variables as global


evalin('base', 'eeg_global;');
eeg_global;

% remove empty datasets in ALLEEG


while ~isempty(ALLEEG) && isempty(ALLEEG(end).data)
41
ALLEEG(end) = [];
end
if ~isempty(ALLEEG) && max(CURRENTSET) > length(ALLEEG)
CURRENTSET = 1;
EEG = eeg_retrieve(ALLEEG, CURRENTSET);
end
% for the history function
% ------------------------
comtmp = 'warning off MATLAB:mir_warning_variable_used_as_function';
evalin('base' , comtmp, '');
evalin('caller', comtmp, '');

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

% default option folder


% ---------------------
if ~isdeployed
eeglab_options;
fprintf('eeglab: options file is %s%seeg_options.m\n', homefolder, filesep);
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];

% check string and backup old dataset


% -----------------------------------
backup = [ 'if CURRENTSET ~= 0,' ...
' [ ALLEEG EEG ] = eeg_store(ALLEEG, EEG, CURRENTSET,
''savegui'');' ...
' eegh(''[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET,
''''savedata'''');'');' ...
'end;' ];

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;' ];

testeegtmp = 'if exist(''EEGTMP'') == 1, EEG = EEGTMP; clear EEGTMP; end;'; %


for backward compatibility
ifeeg = 'if ~isempty(LASTCOM) && ~isempty(EEG),';
ifeegnh = 'if ~isempty(LASTCOM) && ~isempty(EEG) &&
~isempty(findstr(''='',LASTCOM)),';

% 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);'];

% same as above but also save history in dataset


% ----------------------------------------------
e_newset = [e_catch 'EEG = eegh(LASTCOM, EEG);' testeegtmp ifeeg
storenewcall 'disp(''Done.''); end; eeglab(''redraw'');'];
e_store = [e_catch 'EEG = eegh(LASTCOM, EEG);' ifeegnh storecall
'disp(''Done.''); end; eeglab(''redraw'');'];
e_hist = [e_catch 'EEG = eegh(LASTCOM, EEG);'];
e_histdone = [e_catch 'EEG = eegh(LASTCOM, EEG); if ~isempty(LASTCOM),
disp(''Done.''); end;' ];

% 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

% build structures for plugins


% ----------------------------
trystrs.no_check = e_try;
trystrs.check_data = check;
trystrs.check_ica = checkica;
trystrs.check_cont = checkcont;
trystrs.check_epoch = checkepoch;
trystrs.check_event = checkevent;
trystrs.check_epoch_ica = checkepochica;
trystrs.check_chanlocs = checkplot;
trystrs.check_epoch_chanlocs = checkepochplot;
trystrs.check_epoch_ica_chanlocs = checkepochicaplot;
trystrs.check_ica_chanlocs = checkicaplot;
catchstrs.add_to_hist = e_hist;
catchstrs.store_and_hist = e_store;
catchstrs.new_and_hist = e_newset;
catchstrs.new_non_empty = e_newset;
catchstrs.update_study = e_plot_study;
catchstrs.load_study = e_load_study;

% create eeglab figure


% --------------------
if ~strcmpi(onearg, 'nogui')
eeg_mainfig(onearg);
end

% 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

% solve BIOSIG problem


% --------------------
pathtmp = mywhich('wilcoxon_test');
if ~isempty(pathtmp)
try,
rmpath(pathtmp(1:end-15));
catch, end
end

% test for local SCCN copy


% ------------------------
if ~isdeployed
addpathifnotinlist(eeglabpath);
if exist( fullfile( eeglabpath, 'functions', 'adminfunc') ) ~= 7
warning('EEGLAB subfolders not found');
end
end

% determine file format


% ---------------------
fileformat = 'maclinux';
comp = computer;
try
if strcmpi(comp(1:3), 'GLN') || strcmpi(comp(1:3), 'MAC') || strcmpi(comp(1:3), 'SOL')
fileformat = 'maclinux';
elseif strcmpi(comp(1:5), 'pcwin')
fileformat = 'pcwin';
end
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;

% remove path to to fmrlab if neceecessary


path_runica = fileparts(mywhich('runica'));
if length(path_runica) > 6 && strcmpi(path_runica(end-5:end), 'fmrlab')
rmpath(path_runica);
end

48
A.2 SCREEN SHOTS

Figure A.1 EEG signal bands

Figure A.2 Potential versus Latency mapping

49
Figure A.3 ERP image with large number of trials

Figure A.4 Channel spectra and topography maps

50
Figure A.5 PSD mapping

Figure A.6 Continuous EEG data epoch

51
REFERENCES

1. A. Nirabi, F. A. Rahman, M. H. Habaebi, K. A. Sidek and S. Yusoff, &quot;


Machine Learning- Based Stress Level Detection from EEG Signals, &quot; 2021
IEEE 7th International Conference on Smart Instrumentation, Measurement and
Applications (ICSIMA), Bandung, Indonesia, 2021, pp. 53-58,
doi:10.1109/ICSIMA50015.2021.9526333.
2. G. Li, C. H. Lee, J. J. Jung, Y. Youn and D. Camacho, &quot; Deep learning for
EEG data analytics: A survey&quot;, Concurrency and Computation: Practice and
Experience, vol. 32, no. 18, 2019.
3. Y. Gogna, R. Singla and S. Tiwari, &quot;Steady State Detection During A
Cognitive Task,&quot; 2019 IEEE 5th International Conference for Convergence
in Technology (I2CT), Bombay, India, 2019, pp. 1-4,
doi:10.1109/I2CT45611.2019.9033870.
4. M. J. Hasan and J. M. Kim, &quot;A hybrid feature pool-based emotional stress
state detection algorithm using EEG signals&quot;, Brain Sciences, vol. 9, no. 12,
2019.
5. P. Samal and R. Singla, &quot;EEG Based Stress Level Detection During
Gameplay,&quot; 2021 2nd Global Conference for Advancement in Technology
(GCAT), Bangalore, India, 2021, pp. 1-4,
doi:10.1109/GCAT52182.2021.9587468.

52

You might also like