Automatic sleep staging method and system based on deep learning
By adopting deep learning technology and multimodal data processing in the sleep automatic staging system, the problem of complex feature extraction, insufficient multimodal data fusion and generalization capabilities is solved, and fast and accurate automatic staging of sleep is achieved, and the Rich downstream analysis functions have improved the practicality and universality of sleep research.
Patent Information
- Application Number
- CN202411081244.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-08
- Publication Date
- 2024-12-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing automatic sleep staging method has problems such as complex feature extraction, difficulty in fusion of multimodal data, insufficient generalization ability of model and lack of downstream analysis functions, which limits its application and universality in sleep research.
A sleep automatic staging system based on deep learning was designed, including manual marking module, automatic marking module and downstream analysis module, and automatic staging of sleep data is used to use convolutional layer, bidirectional LSTM layer and attention mechanism and other technologies to perform automatic staging of sleep data. It provides functions of sleep phase proportion analysis, sleep phase conversion analysis and signal characteristics analysis of specific frequency bands.
It realizes fast and accurate automatic sleep staging, lowers the technical threshold, provides rich downstream analysis functions, enhances the practicality and universality of sleep research, and helps scientific researchers analyze sleep data in depth.
Smart Images

Figure CN118592904B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of signal processing and machine learning, and specifically relates to a method and system for automatic sleep staging based on deep learning. Background Art
[0002] Automatic sleep staging is a key link in sleep research, and its goal is to automatically identify and classify different sleep stages through algorithms. Traditionally, this work mainly relies on experts to observe signals such as electroencephalogram (EEG) and electromyography (EMG), but this method has problems such as strong subjectivity and time-consuming and labor-intensive. With the rapid development of machine learning technology, automatic staging algorithms have been continuously improved in accuracy and efficiency, and have gradually become a hot topic in the field of sleep research.
[0003] Automatic sleep staging algorithms can be divided into two categories: traditional machine learning-based methods and end-to-end neural network-based methods. Traditional machine learning-based methods usually rely on extracting features from EEG and EMG data to classify sleep stages. These features include the frequency components, amplitude changes, power spectral density, and specific time-frequency features of the signal. Kreuzer et al. (2015) proposed a semi-automatic sleep staging algorithm based on threshold method and frequency features. Patanaik et al. (2018) proposed a method based on support vector machine (SVM) to achieve automatic staging of mouse sleep stages by extracting features from EEG and EMG signals. Wang et al. (2020) proposed a method based on random forests, which significantly improved the representation ability of features and the generalization of the model by introducing an adaptive feature selection algorithm. This type of method improves the accuracy of staging to a certain extent, but still relies on a complex feature extraction process and has high requirements for data preprocessing.
[0004] The other type is an end-to-end method based on neural networks. This type of method uses deep learning technology and does not require manual feature extraction. Instead, it automatically learns the intrinsic representation of data through neural networks and directly learns the features required for classification from raw sleep data and other physiological data. Common network architectures include convolutional neural networks (CNNs) and recurrent neural networks (RNNs), which can effectively capture spatial features and process long-term dependencies in sequence data. Tsinalis et al. (2016) proposed a sleep staging method based on deep learning, using convolutional neural networks (CNNs) to learn classification features directly from raw EEG data. Miladinović et al. (2019) proposed the SPINDLE method, in which the time-frequency diagram obtained by Fourier transform of the raw data is used as the model input, and the CNN outputs the predicted sleep stage, and further calibrates the sleep phase transition through the hidden Markov model. Yamabe et al. (2019) proposed the MC-SleepNet method. After the raw data is preprocessed, features are first extracted through CNN, and then sleep stages are predicted through LSTM. K. Jha et al. (2024) proposed the SlumberNet method, which uses the ResNet network structure to perform sleep staging based on EEG and EMG data. This type of method reduces the reliance on manual feature extraction and significantly improves the accuracy and efficiency of staging.
[0005] Although the above methods have achieved certain success in automatic sleep staging, there are still some shortcomings and challenges: (1) Complex feature extraction: Traditional machine learning-based methods rely on complex feature extraction processes and require a lot of domain knowledge and experience to select and optimize features, which not only increases the complexity of the algorithm but also limits its versatility; (2) Multimodal data fusion: How to effectively integrate multiple physiological signals such as EEG and EMG, and how to deal with the problem of missing data in different modalities, requires further research; (3) Insufficient generalization ability of the model: Existing deep learning models may overfit specific data sets during training, resulting in insufficient generalization ability in different experimental environments, which limits the application scope and universality of the model; (4) Lack of downstream analysis functions: Existing sleep staging systems mostly focus on improving classification accuracy, but ignore the further analysis and application of classification results, which limits the depth and breadth of users' research after obtaining the staging results and cannot fully tap the potential of the automatic staging system. Therefore, a more efficient, comprehensive and intelligent sleep automatic staging solution is needed to bring new breakthroughs and developments to the field of sleep research. Summary of the invention
[0006] In view of the above, the purpose of the present invention is to provide a deep learning-based automatic sleep staging method and system to achieve efficient and accurate automatic sleep staging, while providing a series of rich downstream analysis functions to help users conduct in-depth sleep research and data interpretation, further enhancing its practicality and universality in the field of scientific research.
[0007] In order to achieve the above-mentioned invention object, the technical solution provided by the present invention is as follows:
[0008] An automatic sleep staging system based on deep learning provided by an embodiment of the present invention includes: a manual marking module, an automatic marking module and a downstream analysis module;
[0009] The manual labeling module is used to manually label the original EEG signals and EMG signals at different sleep stages. The sub-functions of the manual labeling module include batch data import, data preview, manual labeling and result export;
[0010] The automatic labeling module is used to automatically label the original EEG signals and EMG signals according to different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module include batch data import, model automatic labeling, result calibration and result export.
[0011] The downstream analysis module is used to perform downstream analysis based on the marking results output by the manual marking module or the automatic marking module. The sub-functions of the downstream analysis module include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis.
[0012] Specifically, in the sub-functions of the manual labeling module, batch data import includes: importing the selected raw EEG and EMG signal data;
[0013] Data preview includes: displaying the global and local signals of the current EEG signal, displaying the global and local signals of the current EMG signal, displaying the continuous EEG signal and EMG signal including the current time window and the previous time window and the next time window according to the set time window length, and displaying the EEG power spectrum density diagram and EEG time-frequency diagram of the current time window;
[0014] Manual marking includes: the user determines the sleep stage of the current time window according to the data displayed by the data preview function, and realizes manual marking through the interface buttons or keyboard numeric keys. The interface displays and updates the marking results in real time;
[0015] Result export includes: saving marking results, exporting user manual marking results according to the set data path, and selecting and importing completed marking results for display.
[0016] Specifically, in the sub-functions of the automatic marking module, batch data import includes: importing the selected raw EEG signal and EMG signal data into a data list;
[0017] Model automatic labeling includes: setting the time window length and sampling rate, selecting the automatic sleep staging model, selecting the data in the data list and starting automatic labeling. The interface displays the global signals of EEG and EMG signals, as well as the labeling results and confidence levels predicted by the automatic sleep staging model.
[0018] The result calibration includes: the interface displays the local original EEG signal and EMG signal of the specified time window, as well as the EEG power spectrum density map and EEG time-frequency map of the current time window. The user calibrates the marking results of the time window with low confidence based on the displayed data;
[0019] Result export includes: exporting the model automatic marking results or calibrated marking results according to the set data path.
[0020] Specifically, the automatic sleep staging model includes an input layer, a convolution layer, an adaptive pooling layer, a bidirectional LSTM layer, an attention mechanism layer, a fully connected layer and a Dropout layer. The automatic sleep staging model automatically marks the original EEG signals and EMG signals for sleep. First, the original EEG signals and EMG signals are received through the input layer for parallel processing, and preliminary feature extraction is performed on them respectively through the convolution layer. Then, the sequence length of the preliminary extracted features is uniformly adjusted through the adaptive pooling layer. Then, the long-term dependency of the time series is captured based on the uniformly adjusted features through the bidirectional LSTM layer to obtain a high-level feature representation. Then, the importance weight of each time step is calculated based on the high-level feature representation through the attention mechanism layer to obtain a weighted feature sequence. Finally, the weighted feature sequences corresponding to the EEG signals and EMG signals output by the attention mechanism layer are subjected to feature fusion and final classification through the fully connected layer and the Dropout layer.
[0021] Specifically, in the sub-functions of the downstream analysis module, the sleep stage proportion analysis includes: the system calculates the sleep stage proportion based on the manual labeling results or the automatic labeling results and displays the statistical data;
[0022] Sleep phase transition analysis includes: the system counts the number of sleep phase transitions, the time point of phase transitions, and the type of sleep phase transitions for each sleep phase according to the manual or automatic marking results and displays the statistical data, and draws a sleep phase transition diagram for display;
[0023] Sleep continuity analysis includes: the system calculates the average duration of total sleep, the average duration of specific sleep stages and the interruption frequency based on manual or automatic marking results and displays statistical data;
[0024] The characteristic analysis of signals in a specific frequency band includes: the system filters the EEG signals through a bandpass filter to obtain the EEG signals in a specific frequency band for display, and displays the ratio of theta waves and delta waves of the EEG signals in a specific frequency band, and displays the EEG time-frequency diagram and electromyographic signals at the same time. After performing a fast Fourier transform on the EEG signals in a specific frequency band to convert the time domain signals into the frequency domain, the power spectrum density of the specific frequency band is calculated. The average power is calculated by integrating the power spectrum density in the specific frequency band, and the relative power is obtained by calculating the ratio of the average power in the specific frequency band to the total power. The total power is the sum of the average powers of all analyzed frequency bands. The system draws and displays the curves of the average power and relative power of the specific frequency band changing with time.
[0025] The sub-functions of the downstream analysis module also include the export of statistical data for sleep stage percentage analysis, sleep phase transition analysis, and sleep continuity analysis.
[0026] Specifically, the calculation formula for the sleep stage ratio is as follows:
[0027] ,
[0028] The total duration of a specific sleep stage is obtained by counting different sleep stages divided according to manual marking results or automatic marking results, and the total sleep duration is the total duration of all sleep stages.
[0029] Specifically, the calculation formulas for the average total sleep duration, the average duration of a specific sleep stage, and the interruption frequency are as follows:
[0030] ,
[0031] ,
[0032] ,
[0033] The total number of sleep segments, the number of segments in a specific sleep stage, and the number of interruptions are obtained by counting different sleep stages divided according to the results of automatic sleep marking or manual sleep marking.
[0034] Specifically, the calculation formula of power spectral density is as follows:
[0035] ,
[0036] in, is the power spectral density of a specific frequency band, is the fast Fourier transform operation, is the EEG signal of a specific frequency band extracted by a bandpass filter. is the sampling frequency, is the length of the signal, i.e. the number of sampling points.
[0037] Specifically, the system is designed based on the MATLAB App Designer tool.
[0038] To achieve the above-mentioned purpose of the invention, an embodiment of the present invention further provides a method for automatic sleep staging based on deep learning, comprising the following steps:
[0039] The manual labeling module is used to manually label the original EEG signals and EMG signals at different sleep stages. The sub-functions of the manual labeling module include batch data import, data preview, manual labeling and result export.
[0040] The automatic labeling module is used to automatically label the original EEG signals and EMG signals according to different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module include batch data import, model automatic labeling, result calibration and result export.
[0041] The downstream analysis module is used to perform downstream analysis based on the labeling results output by the manual labeling module or the automatic labeling module. The sub-functions of the downstream analysis module include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis.
[0042] Compared with the prior art, the present invention has the following beneficial effects:
[0043] (1) The present invention designs a manual labeling module and an automatic labeling module, which is convenient for users to select the corresponding labeling function according to their needs. In the automatic labeling module, advanced deep learning technology is used to construct an automatic sleep staging model, which can realize fast and accurate automatic staging of long-term sleep recording data of indefinite length. Researchers do not need to spend a lot of time on manual staging, thereby significantly improving the efficiency of research work.
[0044] (2) The present invention designs a downstream analysis module and provides a wealth of downstream analysis functions, allowing users to observe the proportion of each sleep stage, the sleep phase transition process and the sleep continuity characteristics. It can also deeply analyze the characteristics of different sleep stages of specific frequency band signals according to needs, such as the signal changes and energy distribution of the frequency band, so as to further explore the scientific significance of the automatic labeling results. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 is a structural schematic diagram of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention;
[0047] Figure 2 Schematic diagram of functional modules of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention;
[0048] Figure 3 It is a schematic diagram of a manual marking interface of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention;
[0049] Figure 4 It is a schematic diagram of an automatic marking interface of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention;
[0050] Figure 5 is a schematic diagram of a downstream analysis interface of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention;
[0051] Figure 6 It is a flowchart of the deep learning-based automatic sleep staging method provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0052] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.
[0053] The inventive concept of the present invention is: in response to the technical problems of high technical threshold, high cost and lack of downstream analysis function in the automatic sleep staging method in the prior art, the embodiment of the present invention provides a deep learning-based automatic sleep staging method and system, which combines manual sleep labeling, automatic labeling based on the automatic sleep staging model and rich downstream analysis functions to support in-depth sleep research and data interpretation, which can lower the technical threshold, help sleep researchers to conduct sleep research more easily and efficiently, and further enhance its practicality and universality in the field of scientific research.
[0054] The embodiment of the present invention develops and designs a deep learning-based automatic sleep staging system based on MATLAB App Designer, which aims to achieve fast and accurate automatic sleep staging, while providing a series of rich downstream analysis tools to help users conduct in-depth research. In addition, the system will support convenient data export to Excel, allowing users to easily perform subsequent personalized data processing. In order to meet the needs of different users, the system also retains the manual labeling function.
[0055] When designing the system, the pre-trained automatic sleep staging model is exported to a general .pth format, which saves the structure and weights of the model and is convenient for cross-platform deployment. Next, the pre-trained automatic sleep staging model is integrated into MATLAB App Designer, which is a powerful interactive application integrated development environment in MATLAB software. It provides rich components and flexible layout options, so that complex data processing and analysis tasks can be presented in an intuitive graphical interface. The automatic sleep staging system based on deep learning designed in the embodiment of the present invention is suitable for users of different technical levels. After the user imports the original data, the program will first perform necessary preprocessing on the data, and the preprocessed data is input into the automatic sleep staging model for reasoning. At the same time, a user-friendly interface is developed based on MATLAB App Designer, which supports users to directly perform data operations and view results through a visual interface. The interface design is concise and clear, and the operation process is clear and intuitive. It is easy to use even for non-professional users to facilitate the use of sleep researchers. In addition, for users with a MATLAB programming foundation, the system functions can be easily expanded. When applied, the deep learning-based automatic sleep staging system provided in the embodiment of the present invention will be open source, and is committed to building an open scientific research environment, encouraging more scientific researchers to participate and jointly promote the continuous improvement and innovation of the system, so as to better serve the sleep research community and contribute to the development of sleep science.
[0056] Figure 1 is a schematic diagram of the structure of the automatic sleep staging system based on deep learning provided by an embodiment of the present invention, such as Figure 1 As shown, the embodiment provides a deep learning-based automatic sleep staging system 100 , including: a manual labeling module 110 , an automatic labeling module 120 and a downstream analysis module 130 .
[0057] Figure 2 is a functional module diagram of a deep learning-based automatic sleep staging system provided in an embodiment of the present invention, such as Figure 2As shown, the manual labeling module 110 is used to manually label the original EEG signals and EMG signals for different sleep stages. The sub-functions of the manual labeling module 110 include batch data import, data preview, manual labeling, and result export. The automatic labeling module 120 is used to automatically label the original EEG signals and EMG signals for different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module 120 include batch data import, model automatic labeling, result calibration, and result export. The downstream analysis module 130 is used to perform downstream analysis based on the labeling results output by the manual labeling module or the automatic labeling module. The sub-functions of the downstream analysis module 130 include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis, and specific frequency band signal feature analysis.
[0058] like Figure 3 The figure shows a schematic diagram of the manual marking interface. The user selects and imports the original EEG and EMG data, and displays the file name of the current marked data. Then, the data is bandpass filtered with the help of Butterworth filter to remove high-frequency and low-frequency noise to reduce interference in subsequent analysis. Then, the time window (epoch) length is set. The default is 4 seconds as an epoch. The interface will display the global and local signals of the current EEG signal, the global and local signals of the current EMG signal, and the continuous EEG and EMG signals including the current time window, the previous time window, and the next time window (currently 3 time windows) are displayed according to the set time window length. The EEG power spectrum density diagram and EEG time-frequency diagram of the current time window are displayed. In the embodiment, the calculation and plotting of the power spectrum density graph and the time-frequency graph are implemented using the spectrogram function of MATLAB, which uses the short-time Fourier transform (STFT) technology to perform time-frequency analysis on the signal. Specifically, the spectrogram function divides the input signal into multiple overlapping short time periods, applies a window function to each section and calculates the Fourier transform, thereby obtaining a spectral representation of the signal changing over time. The power spectrum density graph shows the average power distribution of the signal at different frequencies, and is usually represented by a two-dimensional curve, in which the horizontal axis is the frequency and the vertical axis is the power density amplitude. The time-frequency graph shows the signal intensity at different time points and frequencies, and the color depth is used to characterize the intensity change. These graphical representation methods provide powerful tools for analyzing the frequency composition of the signal and its time evolution, thereby laying the foundation for accurate judgment of the sleep stage.
[0059] Furthermore, the user determines the sleep stage of the signal corresponding to each time window based on the data displayed by the data preview function, and completes the manual marking of the sleep stage. At the same time, in order to speed up the marking process, the interface provides shortcut keys corresponding to each sleep stage in the sleep stage: 1-WAKE (representing the awake state), 2-REM (representing rapid eye movement sleep) and 3-NREM (representing non-rapid eye movement sleep). The user manually marks each time window by clicking the marking button on the interface or the numeric shortcut keys on the keyboard. The marking process is updated in real time, and the marking results are displayed in real time. The user can modify and adjust the marking results as needed. After completing the manual marking, click to save the marking results, and support exporting the user's manual marking results according to the set data path. It also supports the selection of importing the completed marking results for display in the manual marking interface. In addition, there is a help document button to guide users in marking operations through help documents.
[0060] like Figure 4 The figure shows the schematic diagram of the automatic labeling interface. The user selects and imports the original EEG and EMG data, and the imported data file name will be displayed in the data list. The user sets the time window length and sampling rate, selects the automatic sleep staging model, selects the data in the data list and turns on automatic labeling. The labeling results and confidence predicted by the automatic sleep staging model are displayed in the interface. It also includes the global signal of the current EEG and EMG signals, the continuous EEG and EMG signals including the current time window and the previous time window and the next time window (currently 3 time windows), and the EEG power spectrum density map and EEG time-frequency map of the current time window. At the same time, users are supported to manually calibrate the labeling results predicted by the model according to the data displayed by the model classification function. Finally, the model automatic labeling results or calibrated labeling results are exported according to the set data path.
[0061] In the embodiment, the automatic sleep staging model used in the system is a multi-dimensional time series data classification algorithm based on deep learning. PyTorch is used to build a sleep stage automatic staging neural network. The constructed automatic sleep staging model processes two physiological signals, EEG and EMG, at the same time, and fully utilizes the complementary information of multimodal data through parallel processing processes. The model uses a one-dimensional convolutional layer for preliminary feature extraction, which can effectively capture the local pattern and frequency characteristics of the signal. Then, an adaptive pooling layer is used to unify input sequences of different lengths to a fixed length, which enhances the flexibility and robustness of the model. The core of the model is a bidirectional LSTM (Long Short-Term Memory) layer, which enables the network to capture long-term temporal dependencies while considering past and future contextual information. The introduction of the attention mechanism further enhances the model's ability to recognize key time steps, enabling it to adaptively focus on the most relevant features. Finally, through a multi-layer fully connected network and a Dropout layer, the model achieves effective feature fusion and abstraction while preventing overfitting. This structural design fully considers the temporal and multimodal characteristics of sleep data, which can not only capture local features but also understand long-term dependencies, providing a solid foundation for accurate sleep stage classification.
[0062] Specifically, the overall network structure and processing flow of the automatic sleep staging model are as follows:
[0063] (1) Input layer:
[0064] EEG signal input: shape is (batch_size, sequence_length);
[0065] EMG signal input: shape is (batch_size, sequence_length);
[0066] Among them, the sequence length sequence_length =Fs*epoch, Fs is the sampling frequency, and batch_size is the batch size.
[0067] (2) Convolutional layer:
[0068] EEG convolution layer: 1D convolution, input channel 1, output channel 64, kernel size 50, stride 25;
[0069] EMG convolution layer: 1D convolution, input channel 1, output channel 64, kernel size 50, stride 25;
[0070] The EEG and EMG signals are first subjected to preliminary feature extraction through 1D convolution, which can capture the local pattern and frequency characteristics of the signal. Output shape: (batch_size, 64, new_sequence_length), where 64 is the output channel and new_sequence_length is the length of the new sequence.
[0071] (3) Adaptive pooling layer:
[0072] Adaptive average pooling is used to uniformly adjust the length of the new sequence after convolution to 80 to ensure consistency in subsequent processing and facilitate processing of input data of different lengths at different sampling rates. Output shape: (batch_size, 64, 80), where 64 is the output channel and 80 is the output sequence length.
[0073] (4) Bidirectional LSTM layer:
[0074] EEG bidirectional LSTM layer: input size 64, hidden layer size 64, bidirectional;
[0075] EMG bidirectional LSTM layer: input size 64, hidden layer size 64, bidirectional;
[0076] The pooled data is fed into the bidirectional LSTM layer to capture the long-term dependencies of the time series and obtain high-level feature representations. The output shape is: (batch_size, 80, 128), where 80 is the output sequence length and 128 is the output channel size.
[0077] (5) Attention mechanism layer:
[0078] EEG attention layer: input size 128 (output of EEG bidirectional LSTM layer);
[0079] EMG attention layer: input size 128 (output of EMG bidirectional LSTM layer);
[0080] The attention mechanism is applied to the output of the bidirectional LSTM layer, and the importance weight of each time step is calculated based on the high-level feature representation to obtain a weighted feature sequence. Output shape: (batch_size, 128), where 128 is the output channel size.
[0081] (6) Fully connected layer and Dropout layer:
[0082] First fully connected layer: input 256 (concatenation of EEG and EMG attention layer outputs), output 64;
[0083] First Dropout layer: dropout rate 0.5;
[0084] Second fully connected layer: input 64, output 32;
[0085] Second Dropout layer: dropout rate 0.3;
[0086] The third fully connected layer: input 32, output num_classes (number of categories, default is 3);
[0087] The attention outputs of EEG and EMG are concatenated, and feature fusion and final classification are performed through fully connected layers and Dropout layers.
[0088] When training the model, a specific bandpass filter is first applied to remove high-frequency noise and baseline drift. The data is then segmented according to a predefined epoch (usually 4 seconds). The data also needs to be appropriately deformed according to the input requirements of the model. The processed dataset is divided into training and test sets, and encapsulated into an iterable data loader through PyTorch's DataLoader to facilitate batch training of the model. The manual labeling results are used as label supervised training to optimize model parameters.
[0089] The automatic sleep staging model provided in the above embodiment has the following advantages:
[0090] Multimodal fusion: This model processes EEG and EMG signals simultaneously, which can capture sleep characteristics more comprehensively than methods that use only a single signal source. This multimodal approach can provide richer information and further improve classification accuracy and robustness.
[0091] End-to-end learning: The model adopts an end-to-end deep learning architecture, directly learning from the original signal to the final classification, which avoids the tedious manual feature extraction process in traditional methods and can automatically learn the most relevant feature representations;
[0092] Time series modeling and attention mechanism: By combining bidirectional LSTM and attention mechanism, the model can not only capture long-term time series dependencies, but also adaptively focus on the most important time steps, which can better grasp the complex time series dynamics of sleep data than simple CNN or traditional machine learning methods;
[0093] Strong architectural adaptability: The use of adaptive pooling layers enables the model to process input sequences of different lengths, increasing the versatility and practicality of the model, which makes it easier to apply the model to different datasets and experimental settings.
[0094] Anti-overfitting design: By using dropout layers and appropriate network depth, the model improves performance while also focusing on preventing overfitting, which is particularly important for sleep research, which usually has limited sample size.
[0095] like Figure 5The figure shows a schematic diagram of the downstream analysis interface. The user first sets the frequency band, time period or sleep phase of interest to be analyzed. It supports alignment with specified sleep phase transition time points, and performs sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis. The analysis results are displayed on the interface using UITable, and statistical data can be displayed in charts to help deeply understand the physiological significance of the sleep state. It supports exporting statistical data of sleep stage proportion analysis, sleep phase transition analysis and sleep continuity analysis to Excel, which is convenient for users to conduct personalized data analysis and subsequent research.
[0096] (1) Analysis of sleep stage proportion:
[0097] The sleep stage ratio reflects the proportion of each sleep stage (i.e., wakefulness, non-rapid eye movement sleep NREM, rapid eye movement sleep REM) in the total sleep time. It is used to evaluate the overall distribution of sleep structure, identify abnormal changes in sleep patterns, and compare the differences in sleep structure under different experimental conditions. This indicator is calculated by calculating the duration of the sleep stage and then calculating the percentage of each stage in the total recorded time. The calculation formula is as follows:
[0098] ,
[0099] The total duration of a specific sleep stage is obtained by counting different sleep stages divided according to manual marking results or automatic marking results, and the total sleep duration is the total duration of all sleep stages.
[0100] (2) Sleep phase transition analysis:
[0101] Sleep phase transition analysis focuses on the frequency and pattern of transitions between different sleep phases. It is used to evaluate the stability and continuity of sleep, identify abnormal sleep pattern transitions, and study the effects of drugs or specific experimental operations on sleep structure. The main sleep phase transitions involved include WAKE→NREM, NREM→WAKE, NREM→REM, and REM→WAKE. The system counts the number of each sleep phase transition, the time point of the phase transition, and the type of sleep phase transition based on manual or automatic labeling results and displays the statistical data. It also draws a sleep phase transition diagram for display.
[0102] (3) Sleep continuity analysis:
[0103] Sleep continuity analysis evaluates the duration and interruption frequency of the overall sleep stage or a specific sleep stage, which reflects the stability and quality of sleep and is an important indicator for measuring sleep depth and restorativeness. Sleep interruption is a key concept in sleep continuity analysis, which usually refers to the event of transitioning from a sleep state (NREM or REM) to a wakeful state. The system calculates the average duration of total sleep, the average duration of a specific sleep stage, and the interruption frequency based on manual or automatic marking results and displays statistical data. The calculation formula is as follows:
[0104] ,
[0105] ,
[0106] ,
[0107] The total number of sleep segments, the number of segments in a specific sleep stage, and the number of interruptions are obtained by counting different sleep stages divided according to the results of automatic sleep staging or manual sleep marking.
[0108] (4) Analysis of signal characteristics in specific frequency bands:
[0109] The system filters the EEG signal through a bandpass filter to obtain the EEG signal of a specific frequency band for display, and displays the θ wave / δ wave ratio of the EEG signal of a specific frequency band, and displays the EEG time-frequency diagram and electromyographic signal at the same time. After performing a fast Fourier transform on the EEG signal of a specific frequency band to convert the time domain signal to the frequency domain, the power spectrum density of the specific frequency band is calculated. The average power is calculated by integrating the power spectrum density within the specific frequency band. The relative power is obtained by calculating the ratio of the average power of a specific frequency band to the total power (the sum of the average power of all analyzed frequency bands). Finally, the system draws and displays the curves of the average power and relative power of a specific frequency band over time. The calculation formula for the power spectrum density is as follows:
[0110] ,
[0111] in, is the power spectral density of a specific frequency band, is the fast Fourier transform operation, The EEG signal of a specific frequency band (such as theta wave 4~8 Hz, delta wave 1~4 Hz) is extracted through a bandpass filter. is the sampling frequency, is the length of the signal, i.e. the number of sampling points.
[0112] In summary, a deep learning-based automatic sleep staging system provides a comprehensive sleep data analysis solution by combining manual and automated sleep staging methods. The open source nature of the system is committed to building an open scientific research environment, encouraging more researchers to participate and jointly promote the continuous improvement and innovation of the system, so as to better serve the sleep research community and contribute to the development of sleep science. The user-friendly visual interface design of the system can significantly reduce the technical threshold of sleep research. Even users with zero programming knowledge can easily import data and use the system for automatic sleep staging and subsequent downstream analysis. The interface is friendly and easy to use, which promotes the widespread application and further development of sleep data in scientific research.
[0113] Based on the same inventive concept, Figure 6 As shown, an embodiment of the present invention also provides a method for automatic sleep staging based on deep learning, comprising the following steps:
[0114] S1, use the manual labeling module to manually label the original EEG signals and EMG signals in different sleep stages. The sub-functions of the manual labeling module include batch data import, data preview, manual labeling and result export.
[0115] S2, using the automatic labeling module to automatically label the original EEG signals and EMG signals according to different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module include batch data import, model automatic labeling, result calibration and result export.
[0116] S3, using the downstream analysis module to perform downstream analysis based on the labeling results output by the manual labeling module or the automatic labeling module, the sub-functions of the downstream analysis module include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis.
[0117] It should be noted that the automatic sleep staging method based on deep learning provided in the above embodiment belongs to the same inventive concept as the automatic sleep staging system based on deep learning. The specific implementation process is detailed in the embodiment of the automatic sleep staging system based on deep learning, which will not be repeated here.
[0118] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An automatic sleep staging system based on deep learning, It is characterized in that include: Manual labeling module, automatic labeling module and downstream analysis module; The manual labeling module is used to manually label the original EEG signals and EMG signals at different sleep stages. The sub-functions of the manual labeling module include batch data import, data preview, manual labeling and result export. Among them, the data preview includes: displaying the EEG power spectrum density map and EEG time-frequency map of the current time window; The automatic labeling module is used to automatically label the original EEG signals and EMG signals for different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module include batch data import, model automatic labeling, result calibration and result export. Among them, the result calibration includes: the interface displays the local original EEG signals and EMG signals of the specified time window, as well as the EEG power spectrum density map and EEG time-frequency map of the current time window. The user calibrates the labeling results of the time window with low confidence based on the displayed data; The downstream analysis module is used to perform downstream analysis based on the marking results output by the manual marking module or the automatic marking module. The user first sets the frequency band, time period or sleep phase of interest to be analyzed, and supports alignment of specified sleep phase transition time points. The sub-functions of the downstream analysis module include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis; among them, the specific frequency band signal feature analysis includes: displaying the EEG time-frequency diagram and electromyographic signal at the same time, performing fast Fourier transform on the EEG signal of the specific frequency band to convert the time domain signal to the frequency domain, and calculating the power spectral density, average power, relative power, and total power of the specific frequency band, wherein the average power is calculated by integrating the power spectral density within the specific frequency band, and the relative power is obtained by calculating the ratio of the average power of the specific frequency band to the total power. The total power is the sum of the average power of all analyzed frequency bands. The system draws and displays the average power and relative power of the specific frequency band over time.
2. The deep learning-based automatic sleep staging system according to claim 1, It is characterized in that In the sub-functions of the manual labeling module, batch data import includes: importing the selected raw EEG and EMG signal data; The data preview also includes: displaying the global and local signals of the current EEG signal, displaying the global and local signals of the current EMG signal, and displaying the continuous EEG signal and EMG signal including the current time window and the previous time window and the next time window according to the set time window length; Manual marking includes: the user determines the sleep stage of the current time window according to the data displayed by the data preview function, and realizes manual marking through the interface buttons or keyboard numeric keys. The interface displays and updates the marking results in real time; Result export includes: saving marking results, exporting user manual marking results according to the set data path, and selecting and importing completed marking results for display.
3. The deep learning-based automatic sleep staging system according to claim 1, It is characterized in that In the sub-functions of the automatic marking module, batch data import includes: importing the selected raw EEG and EMG signal data into the data list; Model automatic labeling includes: setting the time window length and sampling rate, selecting the automatic sleep staging model, selecting the data in the data list and starting automatic labeling. The interface displays the global signals of EEG and EMG signals, as well as the labeling results and confidence levels predicted by the automatic sleep staging model. Result export includes: exporting the model automatic marking results or calibrated marking results according to the set data path.
4. The deep learning-based automatic sleep staging system according to claim 1, It is characterized in that The automatic sleep staging model includes an input layer, a convolution layer, an adaptive pooling layer, a bidirectional LSTM layer, an attention mechanism layer, a fully connected layer and a Dropout layer. The automatic sleep staging model automatically marks the original EEG signals and EMG signals for sleep. First, the original EEG signals and EMG signals are received through the input layer for parallel processing, and preliminary feature extraction is performed respectively through the convolution layer. Then, the sequence length of the preliminary extracted features is uniformly adjusted through the adaptive pooling layer. Then, the long-term dependency of the time series is captured based on the uniformly adjusted features through the bidirectional LSTM layer to obtain a high-level feature representation. Then, the importance weight of each time step is calculated based on the high-level feature representation through the attention mechanism layer to obtain a weighted feature sequence. Finally, the weighted feature sequences corresponding to the EEG signals and EMG signals output by the attention mechanism layer are subjected to feature fusion and final classification through the fully connected layer and the Dropout layer.
5. The deep learning-based automatic sleep staging system according to claim 1, It is characterized in that In the sub-functions of the downstream analysis module, sleep stage proportion analysis includes: the system calculates the sleep stage proportion based on manual labeling results or automatic labeling results and displays statistical data; Sleep phase transition analysis includes: the system counts the number of sleep phase transitions, the time point of phase transitions, and the type of sleep phase transitions for each sleep phase according to the manual or automatic marking results and displays the statistical data, and draws a sleep phase transition diagram for display; Sleep continuity analysis includes: the system calculates the average duration of total sleep, the average duration of specific sleep stages and the interruption frequency based on manual or automatic marking results and displays statistical data; The characteristic analysis of the signal in a specific frequency band also includes: the system filters the EEG signal through a bandpass filter to obtain the EEG signal in a specific frequency band for display, and displays the ratio of theta waves and delta waves of the EEG signal in the specific frequency band; The sub-functions of the downstream analysis module also include the export of statistical data for sleep stage percentage analysis, sleep phase transition analysis, and sleep continuity analysis.
6. The deep learning-based automatic sleep staging system according to claim 5, It is characterized in that The calculation formula for sleep stage percentage is as follows: , The total duration of a specific sleep stage is obtained by counting different sleep stages divided according to manual marking results or automatic marking results, and the total sleep duration is the total duration of all sleep stages.
7. The deep learning-based automatic sleep staging system according to claim 5, It is characterized in that The average total sleep duration, the average duration of a specific sleep stage, and the frequency of interruptions were calculated using the following formulas: , , , The total number of sleep segments, the number of segments in a specific sleep stage, and the number of interruptions are obtained by counting different sleep stages divided according to automatic sleep results or manual sleep marking results.
8. The deep learning-based automatic sleep staging system according to claim 5, It is characterized in that The power spectral density is calculated as follows: , in, is the power spectral density of a specific frequency band, is the fast Fourier transform operation, is the EEG signal of a specific frequency band extracted by a bandpass filter. is the sampling frequency, is the length of the signal, i.e. the number of sampling points.
9. The deep learning-based automatic sleep staging system according to claim 1, It is characterized in that The system is designed based on the MATLAB App Designer tool.
10. A method for automatic sleep staging based on deep learning, It is characterized in that The following steps are involved: The manual labeling module is used to manually label the original EEG signals and EMG signals at different sleep stages. The sub-functions of the manual labeling module include batch data import, data preview, manual labeling and result export. The data preview includes: displaying the EEG power spectrum density map and EEG time-frequency map of the current time window; The automatic labeling module is used to automatically label the original EEG signals and EMG signals for different sleep stages based on the pre-trained automatic sleep staging model. The sub-functions of the automatic labeling module include batch data import, model automatic labeling, result calibration and result export. Among them, the result calibration includes: the interface displays the local original EEG signals and EMG signals of the specified time window, as well as the EEG power spectrum density map and EEG time-frequency map of the current time window. The user calibrates the labeling results of the time window with low confidence based on the displayed data; The downstream analysis module is used to perform downstream analysis based on the marking results output by the manual marking module or the automatic marking module. The user first sets the frequency band, time period or sleep phase of interest to be analyzed, and supports alignment with the specified sleep phase transition time point. The sub-functions of the downstream analysis module include sleep stage proportion analysis, sleep phase transition analysis, sleep continuity analysis and specific frequency band signal feature analysis; among them, the specific frequency band signal feature analysis includes: the system filters the EEG signal through a bandpass filter to obtain the EEG signal of the specific frequency band for display, and displays the ratio of the θ wave and the δ wave of the EEG signal of the specific frequency band, and displays the EEG time-frequency diagram and the electromyographic signal at the same time. After the EEG signal of the specific frequency band is converted to the frequency domain by fast Fourier transform, the power spectral density of the specific frequency band is calculated. The average power is calculated by integrating the power spectral density in the specific frequency band, and the relative power is obtained by calculating the ratio of the average power of the specific frequency band to the total power. The total power is the sum of the average power of all analyzed frequency bands. The system draws and displays the average power and relative power of the specific frequency band over time.
Citation Information
Cited By
Personalized sleep state monitoring method and system based on multi-mode physiological electric signals
CN122376022A
