Sleep Track: Automated Detection and Classification of Sleep Stages

: Sleep is vital for our body’s physical restoration, but sleep disorders can cause various problems. Determining sleep stages is essential for diagnosing and curing such disorders. Polysomnography (PSG) signals are recordings of brain activity, eye movements, muscle activity and other physiological signals that are collected during a sleep study. Insomnia, Sleep Apnea, and Restless Legs Syndrome are some of the sleep problems that can be identified using these signals. However, analysing PSG signals manually can be time-consuming and prone to errors. Deep Learning Models such as Convolutional Neural Networks (CNN), can be used to automate the analysis of PSG signals. CNN is followed by Long-Short Term Memory (LSTM) and CNN are used as a stack ensemble method to recognize patterns in the signals that correspond to different sleep stages and events. By training these models on large datasets of PSG signals, they can detect the disorders. The dataset is collected from PhysioNet Sleep-EDF dataset that consists of PSG signals. The accuracies obtained using different training and testing data using CNN and CNN-LSTM are 95.15% and 83.9% respectively, and using metadata classifier the overall accuracy is increased by 1%. The future enhancement of the paper can be done by considering Heart rate, EEG Pz-oz signals and EEG Pz-oz along with EEG Fpz-cz.


Introduction
Sleep is complicated biological process which helps people maintain good health, process new information, and also re-energies our body.Our bodies need both sleep and wakefulness to function properly.Your brain is still working even while you are asleep.In addition, it maintains the health of other bodily systems like the immune system and metabolism.It is very important to make sure both the mind and body are rested.At the time of sleep, we undergo different stages.Getting a good amount of sleep helps in maintaining or losing weight.Sleeping fewer than 7 hours per night may lead to weight gain and increase in Body Mass Index (BMI).Good sleep can also improve concentration, problem solving skills, and productivity.Getting enough sleep can also help in maximizing athletic performance.Proper sleep can also help in strengthening our heart, by not doing so it may be risk of developing heart diseases.Your heart rate slows, your body temperature decreases, and your eye movement stops in the second stage of non-REM sleep.The brain waves get slower.A sleep spindle is a brief wave burst that occurs on rare occasions.Your body prepares to extreme deep sleep.Deep sleep is the third stage.During this period, your brain produces slow brain waves known as delta waves.It's difficult to wake you up at this point.During REM (rapid eye movement) sleep, which typically occurs about 90 minutes after falling asleep, vivid dreams take place.This stage of sleep involves rapid eye movements, heightened brain activity, and temporary paralysis of major muscles like those in the arms and legs.The initial REM cycle lasts for approximately 10 minutes, and subsequent REM stages tend to increase in duration as the sleep cycle progresses.To simplify this process, machine learning algorithms can be employed.The ML algorithms analyse sleep data and learn patterns and features to automatically classify each segment into the corresponding sleep stage.

Literature survey
The following section summarizes the significant factor regarding the literacy of existing approaches.
Zhu, Luo and Yu [1] suggested CNN integrated with Attention-based Neural (AN) Network to classify Sleep Stages (SS) using the window feature Learning, Intra-feature Learning and Inter-feature Learning components.The current method used two datasets Sleep-EDF and Sleep-EDFX which comprises individual PSG recordings of whole night for 197 subjects.The study concluded that the Deep Learning techniques like CNN and AN network showed positive results for classifying SS.Using this approach, an accuracy of 93.7% was achieved.Zhou and his team members [2] suggested the Ensemble model to classify SS using Machine Learning algorithms namely, RF and LightGBM (LGBM).The present model resulted in improved performance in recognizing the N1 state.The dataset Sleep-EDF comprises whole night PSG recording corresponding to 197 subjects.The study concluded that integrating RF and LGBM improved the performance in detecting the SS.Using this approach, an accuracy of 82.8% was achieved.
Radhakrishnan, Ezra, Immanuel [3] suggested LGBM and XGBoost as Ensemble approaches to classify SS using Tsfresh for Feature Extraction.The proposed method used Sleep-EDF dataset for classifying Sleep Stages which consists pf EEG and EOG signals.The study concluded that using Tsfresh for feature extraction improved the potential rate of the present model to classify SS.Using this approach, an accuracy of 91.2% was achieved.Qing and his team members [4] suggested a Graph Temporal (GT) fused with Dual-input CNN for classifying SS.Authors used dual input CNN where one input is raw epoch and other Degree Sequence (DS) obtained after mapping each epoch of a Limited Penetrable Visibility Graph (LPVG).The study concluded that Dual-input CNN has improved performance.Using this approach, an accuracy of 88.8% was achieved.Mousavi, Afghah and Rajendra Acharya [5] suggested a deep learning method for automated sleep scoring.The goal was to find the sleep scoring using a method called SleepEEGNet that is made up of Deep Convolutional Neural Networks (DCNNs).The PhysioNet Sleep-EDF dataset was used to solve the above problem.The study concluded that the proposed method achieved an accuracy of 84.26%.
Yildirim, Baloglu and Acharya [6] put forward a Deep Learning Model that used PSG signals for Automated Classification for sleep scoring.The objective was to classify and monitor sleep stages that can help to detect neurological disorders.With respect to dataset the model acquired accuracies of 98.06%, 94.64%, 92.36%, 91.22% and 91.00% for two, three, four, five and six sleep classes, respectively.Sathish, Woo and Edmond [7] suggested the idea of predicting the quality of sleep using CNN.The objective was to classify and monitor sleep stages that helps detect neurological disorders.They used available sleep datasets namely, Sleep-Study, Sleep Deprivation and Sleep Cycle Data.Tim Schluter and Stefan Conrad [8] suggested Automated sleep scoring using Fourier Transform (FT) and Wavelet Transform (WT) for Apnea-Hypopnea Detection.The objective was to predict the automatic sleep stage score and Apnea-Hypopnea using FT and WT, DDTW and waveform recognition.They used CB-Reasoning dataset in their approach.The study concluded through decision tree induction and post processes that epochs of sleep results were given by case-based reasoning.Using this approach, an accuracy of 95.2% was achieved.
Khald Ali, Aboalayon and Faezipour [9] put forward Sleep stage Classification in real time using Single channel EEG method.The motive is to forecast sleep disorders, that can be identified as the major human life issues.The rules are primarily based totally on features implemented to EEG signals.The dataset used was EEG Mindware.The study concluded system to detect sleep stages using the single-channel EEG signal.To acquire EEG samples system makes use of single NeuroSky dry-sensor EEG electrode.Using this approach, an accuracy of 88% was achieved.Zhong and team [10] propound, Multiscale Residual Convolutional Neural Network (MRCNN) on wearable system that can classify sleep stages.The objective was to monitor human who has substantial consequences for medical research and practise.Using this approach, an accuracy of 92.06% was achieved.The signal is divided into 30s epochs and each epoch is associated with a particular sleep stage.
Christos, Konstantinos and Ioana [11] suggested, Classification of SS for humans with Minor Sleep disorders and Healthy Subjects using classifiers such as Hidden Markov Model, SVM, and Multilayer Perceptron (MLP).The objective was to compare different classifiers such as Hidden Markov Model, SVM, and MLP, and evaluate their performance on datasets with healthy subjects and see if the patient is diagnosed with apnea.Three classifiers, Extremely Randomized Tree, Gradient Boosting, and XGBoost, achieved the highest accuracy, and a voting classifier was implemented to combine their results.Using this approach, an accuracy of 88.88% was achieved.The conclusion of this work presents an alternative solution to the sleep stage classification problem using a combination of appropriate time and frequency domain features along with contextual EEG information.Pedro, Xi Long, Radha and other [12] platoon members suggested a Sleep stage bracket with an ECG and respiratory trouble.The automatic bracket of sleep stages using machine literacy models of the autonomic nervous system during sleep grounded on ECG and Respiratory Inductance Plethysmography (RIP) signals is presented in this exploration.These techniques are used to categorize healthy subjects' sleep stages into three classes (WNR) and four classes (WRLD).Using this approach, an accuracy of 80% was achieved.
Ramya Sri, Ravi Raja, Jahnavi and their research team [13] suggested a Systematic Review on Deep Learning Models for Sleep Stage Classification.Authors adopted Deep Learning Models for classifying SS.The objective suggested that Sleep is crucial for health, and identifying sleep disorders early is important for prevention.Using this approach, an accuracy of 87.6% was achieved.Alexandra, Alessandro, Ruben and Bogdan [14] suggested Automatic sleep stage Detection using varying PSG Input signals.RF and MLP algorithms are used to classify SS.The PhysioNet "You Snooze, You Win" data set used to evaluate the performance of the proposed method.The study concluded that to improve the accuracy of specific sleep stages, one need to add certain signals as input to RF.Using this approach, an accuracy of 93% was achieved.Rahman, Imamul and Rashik Hassan [15] suggested automatic scoring of sleep stages using single channel EOG.Random Under-Sampling Boosting (RUSBoost), RF and SVM are employed to classify various sleep stages. .Using this approach, an accuracy of 86.81% was achieved.The available databases, the Sleep-EDF, Sleep-EDFX and ISRUC-Sleep are used in method.The study concluded that, RUSBoost improved the performance of the model.
Authors [17] discussed the significance of person and activity identification in computer vision, particularly in recognizing atomic and non-atomic actions using machine learning techniques.The paper [18] discussed the importance of text summarization in online shopping and surveys various techniques, highlighting the use of seq2seq models with LSTM and attention mechanisms for improved accuracy.The approach [19] utilized Advanced Deep Learning with global threshold to improve E-commerce product classification, achieving high accuracy and challenging existing technology.The paper [20] explores the distinct ML applications in predicting heart attacks using patient health records.It compares Random Forest and CNN methods, and findings showed that Random Forest's better performance in terms of accuracy.Authors [21] presented data-driven prediction techniques, namely, ARIMA and LSTM to forecast COVID-19 cases and deaths.Further, it uses statistical measures to assess accuracy and aims to assist several countries in managing the pandemic.

Proposed method
The paper is based on the classification of sleep stages using Machine Learning Algorithms namely, CNN and LSTM.In this paper, the PhysioNet Sleep-EDF dataset is used.The data set consists of recordings of various types of PSG signals.The EEG data are analyzed by the system to identify features that are specific to each stage of sleep using a combination of signal processing methods along with machine learning algorithms.Once a classification model has been trained using these features, it can successfully distinguish between each stage of sleep.The ultimate objective is to create an automated and feasible system that can precisely identify and categorize various sleep stages in real-time, which can be used in the detection and treatment of sleep disorders.first approach, we send the signals through the CNN classifier.In the second approach, we use CNN followed by LSTM.After obtaining accuracies from all the approaches, we make use of a metadata classifier to get the best accuracy from the used approaches.However, there are still challenges that need to be addressed when using CNNs for sleep tracking, including the need for large amounts of labelled data, potential algorithmic bias, and the interpretability of the models.Additionally, there is a need for continued research and development to optimize the performance of CNNs.The potential of the CNNs to pick up Spatial and Temporal Information Right from a Raw EEG signal is one of its key advantages.This enables the network to record complex patterns and relationships between various channels and time points, without requiring any manual feature extraction.A second advantage is that by using techniques like 1D convolutional layers and pooling layers, you can handle variable-length input sequences.This helps with EEG processing, where signals may differ according to the recording length or duration of an event being studied.The model consists of 12 layers and is designed to process high dimensional data, such as EEG signals.

Modules and its description
The first input layer takes data of input shape (3000,1) which corresponds to 3000 time points and 1 channel electrode.A convolutional layer with 32 filters in size 3, as well as Rectified Linear Activation Unit (ReLU) activation capabilities, is the 1st layer.In order to increase the stability and speed of training, the output shall then be transmitted through a batch normalization layer.

Design Architecture of CNN
The last dense layer contains five units with SoftMax activation functions, giving a prediction of the likelihood that input is connected to any of the 5 classes.In this model, we used a sliding window approach to convert the input shape from 3000,1 to 15000,1.A sliding window approach is to divide the input signal into smaller overlapping segments or windows, which are then individually processed for each window.Hyperparameters that can be adjusted to derive the best possible features from a signal are window size and overlap.

CNN and LSTM
CNN can extract the relevant features from the raw EEG signals such as temporal patterns and frequency components.The topological features are extracted using CNN which is useful in classifying sleep stages.In signal processing, a topological feature refers to the mathematical properties of the shape or structure of signals that are inconsistent with certain transformations such as scaling, rotation, and translation.These characteristics allow for signals to be described and analyzed in a meaningful way, giving insight into their structure and dynamics.LSTMs are widely used for time series data where they provide an excellent ability to capture both long term dependencies and transitional patterns.So, considering the strengths of CNN and LSTM we use CNN-LSTM architecture to classify sleep stages.

Design architecture of CNN-LSTM
This model contains two legs one with short filters and other with long filters.The output of both the layers are concatenated and fed into SoftMax layers to produce final predictions.Our model takes input vector of 3000.The first input layer defines input shape of the model as a 1D-array with input length number of samples and single channel.Four convolution layers with 64, 128, 128 and 128 filters are included in this first leg of the network.This leg will be accompanied by two Max pooling layers with a dropout rate of 0.5.The second leg is similar to the first but with longer filters and smaller strides of 400 and 50 samples respectively.In the figure 5, the input shape is 5, 2688 which gives us the idea of five-time steps and every step has a total of 2688 features.In order to avoid overfitting, the input shall first pass through the dropout layer at a rate of 0.5.There are two bidirectional LSTM layers stacked on top of one another with 512 units each.A sliding window approach is then used to create sequences of five clips from the input data.

Metadata classifier
A meta-data classifier can be utilized as part of a stack ensemble learning strategy to classify sleep stages using EEG data.The goal behind stack ensemble learning is to use a metaclassifier to integrate the predictions of numerous base classifiers to enhance overall classification accuracy.The base classifiers used in this architecture are CNN and CNN-LSTM.These classifiers predict the sleep stages from EEG signals.The results of base classifiers are fed into a metadata classifier where the final sleep stage is classified by using a voting mechanism.The raw EEG signal or extra features that are not present in the base classifiers could be used as inputs to the meta-data classifier.To increase overall classification accuracy, a meta-data classifier can be employed as part of a stack ensemble learning strategy.

Description of dataset
The European Data Format (EDF) database is widely used for research purposes in the field of biomedical engineering and neuroscience.The EDF database contains recordings from over 35,000 individuals, collected from various clinical and research settings around the world.The recordings are stored in a standardized file format, which allows for easy sharing and analysis of the data.The EDF file format consists of a header and a data record.The header contains information about the recording, such as the duration of the recording, the number of channels, the sampling rate, and the signal types.The data record contains the actual physiological signals acquired during the recording.The EDF database includes data from a variety of physiological conditions and signals, including: 1. EEG: Recordings of brain activity using electrodes placed on the scalp 2. ECG: Recordings of heart activity using electrodes placed on the chest 3. EMG: Recordings of the muscle activity using electrodes placed on the skin 4. EOG: Recordings of eye movements using electrodes placed around the eyes 5. Respiratory signals: Recordings of breathing patterns using various sensors 6. Blood pressure: Recordings of blood pressure using various sensors Each PSG in the Sleep-EDF Database includes data from a variety of sensors, including EEG, EOG, and EMG, which are used to track brain activity, eye movements, and muscle tone during sleep.The data is typically recorded over several hours while the subject is sleeping.In addition to the Sleep-EDF Database, there are other datasets available in EDF format that include sleep-tracking data, such as the Montreal Archive of Sleep Studies (MASS) and the Siesta Database.The Sleep-EDF database is a collection of polysomnographic recordings of human sleep, which includes data from 153 subjects with at least one recording of 8 hours or more.The database includes both healthy individuals and patients with various sleep disorders, likely to be sleep apnea, insomnia, and narcolepsy.The recordings were obtained by a variety of recording systems and sampling rates.The system is being trained and tested using data from the EDF database.

Experimental results
In this study, the sleep stages are classified into five different classes namely N1, N2, N3, REM and Awake.CNN and CNN-LSTM are the models used to classify sleep stages.Experimental results showed that CNN has better performance for smaller data and CNN-LSTM has better performance in larger data.

Module 1: CNN
The accuracy obtained using CNN is around 95.15%.The raw data is fed into CNN there is no feature extraction was done explicitly.The CNN itself extract features using convolutional layers and it classifies the sleep stages from the extracted data.CNN extract unique features across multiple layers of convolutional transformation.In the figure 6, 0-4 represents the sleep stages Awake, N1, N2, N3 and REM respectively.We can clearly observe that the N1 state is recognized accurately compared with other states.This is tested using small data.From the figure 7 the accuracy of 83.9% can be seen.The CNN-LSTM has achieved 83.9%.For the larger data, the CNN-LSTM is performing better.Here, the model is been trained using smaller data so the CNN-LSTM performance is lower than CNN is observed.

Module 3: Metadata classifier
In this module, the outputs from the base classifiers i.e., CNN and CNN-LSTM are compared and given as final output.Here, the probabilities of classes from two models are weighted average and the class with highest probability is the class predicted.From the figure 9, the accuracy of 94.57% is observed which is lesser than CNN and CNN-LSTM, but slightly lesser than CNN.When the performance of both the models are lesser, the metadata classifier has highest performance compared to both the models.So, the conclusion was when both the models failed to perform metadata classifier is considered.
Table 2 shows the performance of all the models.CNN has highest performance compared with other models.Whereas, the metadata classifier stands at the second place having slightly lesser performance than the CNN model.But when both models are failed the metadata classifier shows the higher performance.The CNN-LSTM has lesser performance but it shows higher performance when the data is large.

Conclusion and future enhancement
Sleep is a crucial biological process that helps maintain good health, process new information, and re-energize the body.Generally, sleep stages are classified into 5 different stages namely, Awake, N1, N2, N3, and REM.Different stages of sleep provide the body with a variety of physiological and mental health functions, including bodily and mental regeneration, consolidations in memory as well as emotion regulation.However, classifying sleep stages has a significant role.It helps to diagnose and observe sleep disorders such as insomnia, narcolepsy, and sleep apnea.Signals like PSG can be used to diagnose various sleep disorders but analyzing them manually can be time taking.Deep Learning Models and various Machine Learning models can be used to recognize patterns in the signals that correspond to different sleep stages and events.The motive of the paper is to improve the classification of sleep stages using various machine learning algorithms such as CNN with LSTM and CNN.Two approaches were taken: CNN followed by LSTM and CNN as a classifier.The data pre-processing stage involves segmenting the raw EEG signal into shorter epochs, filtering out noise and artefacts, and assigning each epoch a corresponding sleep stage using expert annotations.
Using CNN, 95.15% of accuracy is obtained.The CNN extracts various from the raw signal and classify sleep stages.Using CNN-LSTM the highest accuracy of 83.9% was obtained.Among all the models, CNN-LSTM model had better performance in classifying sleep stages for larger data whereas for smaller data CNN has better performance.The future enhancement of the paper can be done by combining different types of physiological signals, such as EEG, EOG and EMG which might improve the accuracy of sleep stage classification.

Fig. 1 .
Fig. 1.Classification of Sleep Stages.(Courtesy: Source [16]).The sleep cycle consists of different stages namely N1, N2, N3, Rapid Eye Movements (REM).Your brain goes through its normal cycles of activity as you sleep.The four stages of sleep are separated into two phases: The first one is the non-REM sleep, which consists of three stages.During the last two stages of non-REM sleep, we completely fall asleep.REM sleep begins about an hour to one and a half hour after falling asleep.When you sleep, your body alternates between REM and non-REM sleep.For most people, the initial stage of sleep cycle begins with non-REM sleep.Before entering a brief REM sleep cycle, you progress through the other non-REM sleep stages.The cycle then begins again at stage 1.Non-REM sleep's first stage lasts 5 to 10 minutes.Everything, including muscle and visual activity, begins to slow down.Your heart rate slows, your body temperature decreases, and your eye movement stops in the second stage of non-REM sleep.The brain waves get slower.A sleep spindle is a brief wave burst that occurs on rare occasions.Your body prepares to extreme deep sleep.Deep sleep is the third stage.During this period, your brain produces slow brain waves known as delta waves.It's difficult to wake you up at this point.During REM (rapid eye movement) sleep, which typically occurs about 90 minutes after falling asleep, vivid dreams take place.This stage of sleep involves rapid eye movements, heightened brain activity, and temporary paralysis of major muscles like those in the arms and legs.The initial REM cycle lasts for approximately 10 minutes, and subsequent REM stages tend to increase in duration as the sleep cycle progresses.To simplify this process, machine learning algorithms can be employed.The ML algorithms analyse sleep data and learn patterns and features to automatically classify each segment into the corresponding sleep stage.

Figure 2
Figure 2 depicts the architecture diagram of the proposed work and the following section illustrates its description.Initially, EEG signals are split into epochs of 30sec.Then the signals undergo feature extraction such that only the relevant features are selected.In the

3. 2
.1.CNN Sleep tracking is a field that has been revolutionized by deep learning techniques in recent years, with CNNs being one of the most widely used approaches.CNNs are particularly effective in analyzing time-series data, such as EEG signals, which are commonly used in sleep tracking.The main advantage of CNNs for analyzing complex signals such as EEG, which contain a wide range of frequencies and temporal patterns.

Fig. 3 .
Fig. 3. CNN design architecture.In time series prediction, LSTM networks are also used where they can be used to predict trends and trends in the signal for a given period of time thus predicting subsequent values.LSTM can handle long term dependencies and temporal patterns which are used to classify sleep stages.Whereas the temporal patterns deal with the dynamic and structural information of the signal.The strengths of CNN and LSTM are combined as CNN-LSTM neural network.
/doi.org/10.1051/e3sconf/20234300102020 4304.2.2 Module 2: CNN-LSTMThe accuracy obtained using CNN is around 83.9%.CNN extracts the spatial features from the raw EEG data and LSTM extracts the temporal dependencies in the data.The two different model have different advantages, so combining both the models given a best model.The CNNs output is fed into LSTM input and it is used to classify Sleep stages.LSTM is pre owned to classify the time series data.

Table 2 .
Comparison of all the models using classification report.Classification report for metadata classifier.