Method for insomnia detection based on electrocardiogram analysis across different sleep stages

TWI937607BActive Publication Date: 2026-09-01NAT CHIN YI UNIV TECH
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
TW113143664
Authority / Receiving Office
TW · TW
Patent Type
Patents
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2026-09-01
Estimated Expiration
2044-11-12

AI Technical Summary

Technical Problem

Current insomnia diagnosis methods, such as polysomnography (PSG) and multiple sleep latency test (MSLT), are time-consuming, expensive, and inconvenient for widespread screening and continuous monitoring due to their complexity and requirement of numerous electrodes.

Method used

An insomnia detection method using electrocardiogram (ECG) analysis through signal preprocessing and deep learning-based detection classification, employing convolutional neural networks and a loss function to classify ECG signals into sleep stages and identify insomnia.

Benefits of technology

Improves insomnia detection accuracy by classifying ECG signals into sleep stages, providing a more efficient and cost-effective method for large-scale screening and continuous monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure TWG2TB001908585_001
    Figure TWG2TB001908585_001
  • Figure TWG2TB001908585_002
    Figure TWG2TB001908585_002
  • Figure TWG2TB001908585_003
    Figure TWG2TB001908585_003
Patent Text Reader

Abstract

This invention relates to an insomnia detection method based on electrocardiogram (ECG) analysis of different sleep stages. It includes signal preprocessing and detection classification steps. First, the ECG signals from the entire night's sleep of the input subject are classified, differentiated, and segmented to obtain 30-second ECG signals from three sleep stages. A detection model is then established using a deep learning model based on convolutional neural networks, along with a loss function and optimizer. Furthermore, a dataset is created from ECG signals from different subjects provided by a sleep database to train, validate, and test the deep learning model, resulting in an optimized model. This optimized model is then used to perform calculations and analysis on the obtained ECG signals from the three sleep stages, ultimately outputting classification results and effectively improving classification accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method for detecting insomnia, and more particularly to a method for detecting insomnia based on electrocardiogram analysis of different sleep stages. Prior Technology

[0002] Sleep plays a vital role in maintaining bodily and mental function. Its physiological manifestations include a decrease in heart rate and body temperature, as well as a slowing of brain and organ activity. Therefore, sufficient sleep not only contributes to improved physical strength and cognitive function but also supports bodily repair, the normal functioning of the immune system, and the promotion of growth and development. Furthermore, good sleep helps maintain emotional stability, improve memory, and enhance concentration. Adults should ensure 7-9 hours of sleep each night. However, data from various adult samples from different countries show that approximately 30% of adults experience one or more symptoms of insomnia. According to a 2006 epidemiological study of sleep disorders in Taiwan conducted by the Taiwan Sleep Medicine Society, the prevalence of insomnia in Taiwan was 24.8% (20.5% for men and 29.3% for women). Therefore, insomnia is a common sleep problem characterized by poor sleep quality, difficulty falling asleep, sleep interruptions, or early morning awakenings. Insomnia not only affects an individual's quality of life but can also trigger a series of health problems. Chronic insomnia can lead to fatigue, poor concentration, mood swings, and may even cause depression and anxiety; therefore, early identification and treatment of insomnia is crucial.

[0003] Continuing from the previous point, the diagnosis of insomnia requires a detailed consultation and evaluation by a professional physician. Clinically, sleep testing methods used to assist in the diagnosis of insomnia include polysomnography (PSG) and multiple sleep latency test (MSLT). For PSG, subjects need to go to a specialized sleep laboratory or sleep center and spend the night undergoing the test. Therefore, under the supervision of nursing staff, electrode patches are placed on the head, corners of the eyes, chin, heart, and legs. Simultaneously, sensor bands are attached to the chest and abdomen, pulse oximeters are placed on the fingers, respiratory sensors are placed over the mouth and nose, and a blood pressure monitor is strapped to the arm to record sleep physiological data throughout the night. PSG is considered the gold standard for diagnosing sleep-related breathing disorders, including obstructive sleep apnea (OSA), central sleep apnea, and sleep-related hypoventilation. Hypoxia can also be assessed by PSG, which can be used to evaluate other sleep disorders, including nocturnal seizures, narcolepsy, periodic limb movement disorder (PLMD), and rapid eye movement sleep behavior disorder (RBD).

[0004] The morning after the PSG test, the subject will undergo the MSLT test. The MSLT provides the subject with five short sleep opportunities during the day. The test includes an EEG, eye movement, jaw muscle electromyography, and an electrocardiogram (ECG). If the subject enters any sleep stage within 20 minutes, the test time will be extended by 15 minutes to confirm whether premature REM sleep has occurred. Conversely, if the subject fails to fall asleep within 20 minutes, the test ends. Therefore, the purpose of this test is to assess the degree of daytime sleepiness and track the onset time of REM sleep.

[0005] Currently, MSLT is a valuable and widely used tool for identifying daytime narcolepsy and idiopathic narcolepsy. However, performing MSLT and PSG tests is quite time-consuming, expensive, and inconvenient for subjects. In addition, these tests require connecting a large number of wires and electrodes to the subject's body. Although these methods are considered the gold standard for insomnia diagnosis, their cost and time requirements prevent them from being widely applied to large-scale insomnia screening and continuous monitoring. Therefore, in order to overcome the inconvenience and high cost of traditional insomnia monitoring methods, the inventors of this invention have devoted themselves to research and further conceived the concept. After multiple research and development improvements to address the aforementioned problems, this invention application is hereby filed. Summary of the Invention

[0006] Therefore, the purpose of this invention is to provide an insomnia detection method based on electrocardiogram analysis of each sleep stage, which can effectively detect and classify the electrocardiogram signals of the subject in each sleep stage to determine whether the event belongs to insomnia, thus effectively improving the accuracy of detection.

[0007] Therefore, this invention provides an insomnia detection method based on electrocardiogram (ECG) analysis of various sleep stages. This method is executed by computer software to detect and identify the ECG signals input by the subject throughout the night. The insomnia detection method includes signal preprocessing and detection classification steps. The signal preprocessing procedure processes the entire night's sleep ECG signals by classifying them into two different sleep phases, distinguishing them into five sleep periods, merging them into three sleep stages, and finally extracting 30 seconds of ECG signal from each stage and using them as input signals. The detection classification uses an optimized system that has been trained, verified, and tested. Deep learning technology involves building a detection model, establishing a dataset, and training, validating, and testing the model. Specifically, the dataset is used to train, validate, and test the deep learning model built using convolutional neural networks. A loss function and optimizer are used in conjunction with the deep learning model to obtain an optimized detection model. This optimized model is then used to calculate and analyze 30-second electrocardiogram (ECG) signals from three sleep stages of a subject to detect and classify whether the subject is suffering from insomnia, effectively improving detection accuracy. Simple Explanation of the Diagram

[0008] Figure 1 is a flowchart of a preferred embodiment of the present invention. Figure 2 is a flowchart illustrating the processing procedure of this preferred embodiment. Figure 3 is a schematic diagram of a typical sleep cycle of this preferred embodiment. Figure 4 is a schematic flowchart of the processing procedure of the preferred embodiment shown in Figure 2. Figure 5 is a flowchart of the processing procedure of the preferred embodiment shown in Figure 2. Figure 6 is a block diagram of the detection model of the preferred embodiment. Figure 7 is a block diagram of the deep learning model of this preferred embodiment. Figure 8 is an internal block diagram of one of the convolutional neural network blocks in the preferred embodiment of Figure 7. Figure 9 is an internal block diagram of the fully connected neural network block of the preferred embodiment shown in Figure 7. Implementation

[0009] The foregoing description and other technical contents, features and effects of this invention will become clear in the following detailed description of the preferred embodiments with reference to the accompanying drawings.

[0010] Referring to Figure 1, a preferred embodiment of the present invention, an insomnia detection method 3 based on electrocardiogram analysis of various sleep stages, is executed by computer software to detect whether the ECG signal input by the subject throughout the night constitutes an insomnia event. The insomnia detection method includes steps such as signal preprocessing 31 and detection classification 32. The signal preprocessing 31 step includes a processing program to process the received overnight sleep ECG signal. Since a normal adult sleep cycle is formed by alternating slow and fast cycles, a complete sleep cycle lasts approximately 90 to 120 minutes. Therefore, under normal circumstances, this cycle can repeat four to five times per night. Please refer to Figures 2 and 3 for further details. The processing program includes the following steps:

[0011] The first step involves classifying the ECG signals throughout the night into a slow-wave sleep phase and a rapid eye movement (REM) sleep phase. The slow-wave sleep phase, also known as non-rapid eye movement (NREM) sleep, is the first phase that begins when falling asleep. The REM sleep phase, also known as rapid eye movement (REM) sleep, is the transition from slow-wave sleep to REM sleep.

[0012] In the second step, the previously obtained slow-wave sleep phases are divided into the sleep onset phase (S1), the light sleep phase (S2), and the deep sleep phases (S3 and S4). Since the rapid eye movement (REM) sleep phase is between wakefulness and the sleep onset phase (S1), it is divided into the rapid eye movement (REM) phase (S5).

[0013] Step 3, referring to Figure 4, re-divide the aforementioned sleep periods into three main sleep stages, merging the S1 sleep onset period and the S2 light sleep period to represent the light sleep stage, merging the S3 and S4 deep sleep periods to represent the deep sleep stage, and categorizing the S5 REM sleep period as the REM sleep stage.

[0014] In step four, referring to Figure 5, 30 seconds of ECG signal are extracted from each of the three main sleep stages at a sampling frequency of 100Hz as input signals. Therefore, each 30-second ECG signal has 3000 sampling points, with a dimension of 3000×1. Thus, the 30-second ECG signals extracted from the three main sleep stages will be further parallelized into 3000×3 input signals.

[0015] In step 32 of the detection classification, an optimized deep learning technique that has been trained, validated, and tested is used, and this deep learning technique includes building a detection model, building a dataset, and training, validating, and testing the model; wherein:

[0016] Referring to Figures 6 and 7, the detection model uses a deep learning model based on convolutional neural networks (CNNs), along with loss functions and optimizers that work in conjunction with this deep learning model. As mentioned earlier, this deep learning model has a feature extraction stage, a flattening layer, and a classification stage from input to output. The feature extraction stage has five identical CNN blocks, each with three parameters representing the number of channels used, kernel size, and stride: (32, 16, 2), (16, 16, 2), (8, 16, 3), (4, 16, 3), and (1, 16, 3), respectively. Each CNN block further consists of a CNN layer with parameters C and K, and a batch positive... As shown in Figure 8, the convolutional neural network consists of a normalization layer, an activation layer using the ReLU function, a max pooling layer with a pooling size of 2, and a dropout layer with a dropout rate of 20%. This convolutional neural network layer is used to compute the feature vectors in the signal to obtain the required feature signal output. The batch normalization layer normalizes the feature signal data to be entered into the activation layer to improve the speed, performance, and stability of the neural network. The activation layer then computes the feature signal using the ReLU function. The purpose of the max pooling layer is to reduce the complexity of the network and the possibility of overfitting by selecting the maximum value in the neighborhood of neurons in the feature map. The dropout layer reduces overfitting by randomly omitting 20% ​​of the nodes.

[0017] Continuing from the above, the flattening layer is responsible for converting a 2D feature matrix into a 1D feature vector and providing it to the classification stage. This classification stage has a fully connected neural network block with 1024 neurons and a fully connected layer using the Softmax activation function. This fully connected neural network block is further composed of a fully connected layer, a batch normalization layer, an activation layer, and a dropout layer with a dropout rate of 20%, as shown in Figure 9. Therefore, the fully connected layer aggregates the feature vector map output by the flattening layer, the batch normalization layer normalizes it, the activation layer uses the ReLU function to calculate the normalized numbers, the dropout layer randomly omits 20% of the nodes, and finally, the fully connected layer using the Softmax activation function performs the classification to produce the classification result.

[0018] Furthermore, this loss function combines a cross-entropy loss and a contrastive loss. The cross-entropy measure is the difference between the predicted probability distribution and the actual probability distribution. It can be used to determine how close the model output is to the expected output. Therefore, the smaller the distance between the model's prediction and the actual output probability distribution, the smaller the cross-entropy value; conversely, the larger the distance between the model's prediction and the actual output probability distribution, the larger the cross-entropy value. The detection mode of this invention belongs to binary classification, and the classification result can be divided into two types: insomnia and non-insomnia. The definition of its cross-entropy loss is as follows:

[0019] Cross-Entropy Loss=-

[0020] This is the actual label (0 or 1).

[0021] It is the probability predicted by the model.

[0022] [, n , ] represents the number of samples, i.e. how many samples in the batch participated in the loss calculation; therefore, the cross-entropy loss calculates the loss on each sample and then takes the average loss of all samples.

[0023] When the true label = 1 (positive class, i.e., insomnia group), the loss is -log(). The closer the probability predicted by the model is to 1, the smaller the loss; conversely, the greater the loss is.

[0024] When the true label = 0 (negative class, i.e., non-insomnia group), the loss is -log(1- ). The closer the probability predicted by the model is to 0, the smaller the loss; conversely, the greater the loss is.

[0025] The purpose of contrastive loss is to bring samples of the same class as close as possible in the feature space, while maximizing the distance between samples of different classes. The definition of contrastive loss is as follows:

[0026] Contrastive Loss=

[0027] [, n , ] represents the number of sample pairs in the batch.

[0028] It is the label of the sample pair. If the two samples are from the same category, then =1 (positive sample pair); if they are from different categories, then =0 (negative sample pair).

[0029] [, d i , ] is the distance between two samples.

[0030] [, m , ] is a predefined threshold representing the minimum distance between negative sample pairs. If the distance between negative sample pairs is greater than , [, m If , ], then the loss is 0.

[0031] Therefore, the calculation of contrast loss can be explained as follows, assuming there are 3 samples in a batch: [, x , ] [ , 1, ] (insomnia) [, x , ] [ , 2, ] (insomnia), and [, x , ] [ , 3, ] (non-insomnia), each sample refers to a 30-second ECG signal from the three main sleep stages in parallel, with a dimension of 3000×3. Specifically, the sample [, x , ] The electrocardiogram signal of [ , 1, ] can be represented as [, x , ] [ , 1, ], [ , 1, ], [, x , ] [ , 1, ], [ , 2, ], [, x , ] [ , 1, ], [ , 3, ], corresponding to the three main sleep stages; similarly, the sample [, x , ] The electrocardiogram signal of [ , 2, ] can be represented as [, x , ] [ , 2, ], [ , 1, ], [, x , ] [ , 2, ], [ , 2, ], [, x , ] [ , 2, ], [ , 3, ], Sample [, x , ] The electrocardiogram signal of [ , 3, ] can be represented as [, x, ] [ , 3, ], [ , 1, ], [, x , ] [ , 3, ], [ , 2, ], [, x , ] [ , 3, ], [ , 3, ] indicates that these three samples will form three pairs of samples, which are:

[0032] ( [, x , , 1, ], [, x , , 2, ]): Positive sample pair, because both belong to the insomnia category.

[0033] ( [, x , , 2, ], [, x , , 3, ]): Negative sample pairs because they come from different categories (insomnia and non-insomnia).

[0034] ( [, x , , 1, ], [, x , , 3, ]): Negative sample pairs because they come from different categories (insomnia and non-insomnia).

[0035] Therefore, the calculation steps for contrast loss are as follows:

[0036] 1. Calculate the distance between three sample pairs:

[0037] [, d , ] [ , 1, ]= [‖] [‖] [, f , ] [( , x , ] [, 1,1, ] [)­­] [-] [ , f , ] [( , x , ] [ , 2,1 , ] [)] [‖]+ [‖] [ , f , ] [( , x , ] [ , 2,1 , ] [)] [-] [ , f , ] [( , x , ] [ , 2,2 , ] [)] [‖]+ [‖] [ , f , ] [( , x , ] [ , 1,3 , ] [)] [-] [ , f , ] [( , x , ] [ , 2,3 , ] [)] [‖] [‖] [­­]

[0038] [ , d , ] [ , 2, ]= [‖] [‖] [ , f , ] [( , x , ] [ , 2,1 , ] [)­­] [-] [ , f , ] [( , x , ] [ , 3,1 , ] [)] [‖]+ [‖] [ , f , ] [( , x , ] [ , 2,2 , ] [)] [-] [ , f , ] [( , x , ] [ , 3,2 , ] [)] [‖]+ [‖] [ , f , ] [( , x , ] [ , 2,3 , ] [)] [-] [ , f , ] [( , x , ] [ , 3,3 , ] [)] [‖] [‖]

[0039] [ , d , ] [ , 3, ]= [‖] [‖] [ , f , ] [( , x, ] [, 1,1 , ] [)] [-] [, f , ] [( , x , ] [, 3,1 , ] [)] [‖]+ [‖] [, f , ] [( , x , ] [, 1,2 , ] [)] [-] [, f , ] [( , x , ] [, 3,2 , ] [)] [‖]+ [‖] [, f , ] [( , x , ] [, 1,3 , ] [)] [-] [, f , ] [( , x , ] [, 3,3 , ] [)] [‖] [‖]

[0040] in [, f(x i , ] [, , j ) , ] represents the deep learning model from the samples [, x i The extracted first, ] [,j There are ] feature vectors, and in the deep learning model of this invention, their dimension is 28×1, while [‖.‖] represents the Euclidean distance of the vector.

[0041] 2. Calculate the loss for positive sample pairs (of the same class):

[0042] The first sample pair is a positive sample pair. [, x , , 1, ], [, x , , 2, ]), [y, 1, ]=1, loss is, desired distance [, d , ] The smaller the value of [ , 1, ], the better, in order to reduce the distance between samples of the same category.

[0043] 3. Calculate the loss for negative sample pairs (different classes):

[0044] The second sample pair is a negative sample pair. [, x , , 2, ], [, x , , 3, ]), [y, 2, ]=0, loss is max(0, [, m , ]- [, d , ] [ , 2, ]) [, 2 , ].

[0045] The third sample pair is a negative sample pair. [, x , , 1, ], [, x , , 3, ]) , [y, 3, ]=0, loss is max(0, [, m , ]- [, d , ] [ , 3, ]) [, 2 Therefore, it is hoped that these distances [, d , ] [ , 2, ] and [, d , ] The larger the value of [ , 3, ], the better; it should be at least greater than the preset threshold. [, m , ], to maximize the difference between samples of different categories.

[0046] 4. Calculate the total contrast loss:

[0047] Contrastive Loss=

[0048] There are 3 sample pairs in this example, therefore [, n , ]=3.

[0049] The optimizer used is the Adam (Adaptive Moment Estimation) optimizer to minimize the loss value. This optimizer is an adaptive learning rate optimization algorithm based on the first and second momentum of the gradient. It combines the advantages of momentum methods and RMSProp, resulting in strong convergence and stability when dealing with high-dimensional parameter spaces and large datasets. The core feature of the Adam optimizer is that it simultaneously tracks the mean gradient (momentum) and the mean squared gradient of each parameter, dynamically adjusting the learning rate of each parameter based on these estimates. Therefore, compared to traditional stochastic gradient descent methods, the Adam optimizer can adaptively adjust the learning rate according to different gradient characteristics, allowing the model to update parameters more flexibly under different gradient conditions, especially when gradient changes are drastic. Furthermore, the Adam optimizer introduces a bias correction mechanism. Since the initial estimates of gradient momentum and the squared gradient are small, leading to a slow learning pace, therefore… The Adam optimizer uses bias correction to offset this effect in the first few e iterations. This correction allows for faster and more accurate parameter updates during early training. Another important feature of the Adam optimizer is the inclusion of a very small constant in its update formula. This optimization mechanism prevents division by zero during computation, enhancing not only numerical stability but also overall training robustness. The adaptive nature of the Adam optimizer makes it perform exceptionally well in many deep learning tasks, especially when data is sparse or gradients change frequently. It effectively accelerates the convergence process. Compared to traditional gradient descent, the Adam optimizer can quickly adapt to changes in the learning rate and effectively improve module performance in the early stages of training. Furthermore, the Adam optimizer is highly adaptable to different tasks and network structures, requiring minimal learning rate adjustments. Therefore, it is widely used in various neural network architectures.

[0050] In this technique for establishing the dataset, electrocardiogram (ECG) signal data from different subjects is provided by a sleep database (Cyclic Alternating Patient (CAP). The data provided by the sleep database is classified into at least two groups: insomnia group and non-insomnia group. Specifically, 100,000 3000×3 ECG signals are obtained from both insomniacs and non-insomniacs in the sleep database. 70% of these signals are used as training set data, 15% as validation set data, and 15% as test set data for training, validation, and testing of the deep learning model.

[0051] In this training, validation, and testing model technique, the aforementioned training set, validation set, and test set data are first used to train, validate, and test the deep learning model. Specifically, 70% of the training set data, 15% of the validation set data, and 15% of the test set data are input sequentially to train, validate, and test the deep learning model. Training, validation, and testing are performed by acquiring 3000×3 electrocardiogram signals. The loss function and optimizer are then used in conjunction with the deep learning model's calculations to determine the closeness between the deep learning model's output and the expected output. Furthermore, the optimizer's bias correction mechanism further enhances the model's performance. The stability of strong computational values ​​not only helps in classifying the predicted probabilities of insomnia and non-insomnia, but also improves the accuracy of model predictions. After obtaining an optimized model, the subject's entire night's sleep ECG signal is input. After processing by this program, ECG signals from the three sleep stages are obtained. Through the detection and identification of the optimized detection model, the final detection and identification result of classifying the input subject's entire night's sleep ECG signal into insomnia or non-insomnia is effectively improved. This provides a mechanism for medical personnel to intervene, allowing them to provide corresponding medical treatment based on the subject's actual insomnia condition, effectively helping the subject improve the inconvenience caused by long-term insomnia.

[0052] In summary, this invention, an insomnia detection method based on electrocardiogram (ECG) analysis of various sleep stages, primarily detects the probability of whether the subject's overnight ECG signal constitutes insomnia. This is achieved through signal preprocessing and detection classification. The preprocessing step categorizes the overnight ECG signal into two different sleep phases, distinguishing five sleep periods, and then merging them into three sleep stages. Finally, 30 seconds of ECG signal are extracted from each stage and processed as input signals. The detection classification step utilizes deep learning techniques, including establishing a detection model, building a dataset, and training, validating, and testing the model. Specifically, it employs a deep learning model using convolutional neural networks, combined with a loss function and optimizer, to establish the detection model. A sleep database (Cyclic Alternating Current) is used. The Patient-Capable Detection and Detection (CAP) dataset, selected from electrocardiogram (ECG) signals of different subjects, is used to establish the necessary dataset for training, validating, and testing the deep learning model. After obtaining the optimized detection model, the model is used to classify the input subject's overnight sleep ECG signals to detect and identify the predicted probability of insomnia or non-insomnia, and to generate output results. This output provides medical personnel with a reference for intervention mechanisms and provides corresponding medical treatment based on the actual insomnia situation, effectively helping subjects improve the inconvenience caused by long-term insomnia.

[0053] However, the above description is only for illustrating preferred embodiments of the present invention and should not be construed as limiting the scope of the present invention. Any simple equivalent changes and modifications made in accordance with the scope of the patent application and the contents of the specification of the present invention should still fall within the scope of the patent of the present invention.

[0054] (This invention) 3: Insomnia Detection Method Based on Electrocardiogram Analysis of Different Sleep Stages 31: Signal Preprocessing 32: Detection Classification

Claims

1. An insomnia detection method based on electrocardiogram (ECG) analysis of various sleep stages, executed by computer software, to detect whether the ECG signals input by the subject throughout the night constitute an insomnia event. The detection method includes: a signal preprocessing step, which has a processing program. The processing program includes: Step 1, classifying the ECG signals throughout the night into a slow-wave sleep phase and a rapid eye movement (REM) sleep phase; Step 2, further dividing the obtained slow-wave sleep phase into S1 (sleep onset), S2 (light sleep), and S3 and S4 (deep sleep), while the REM sleep phase is further divided into S5 (rapid eye movement). Step 3 involves reclassifying the aforementioned sleep periods into three main sleep stages: S1 (sleep onset) and S2 (light sleep) are merged to represent the light sleep stage; S3 and S4 (deep sleep) are merged to represent the deep sleep stage; and S5 (REM sleep) is classified as the REM sleep stage. Step 4 involves extracting 30 seconds of ECG signal from each of the three main sleep stages at a sampling frequency of 100Hz as input signals. Therefore, each 30-second ECG signal contains 3000 samples, resulting in a dimension of 3000×1. This classifies the received overnight ECG signals into two different sleep phases, distinguishing five sleep periods. These sleep periods are then merged and segmented into three sleep stages, and 30 seconds of ECG signal are extracted from each stage, further juxtaposed as input signals. A detection and classification process is also employed, utilizing an optimized deep learning technique that has been trained, validated, and tested. This deep learning technique includes: establishing a detection model, which uses a deep learning model based on convolutional neural networks, and loss functions and optimizers that work in conjunction with this deep learning model. The deep learning model has a feature extraction stage, a flattening layer, and a classification stage from input to output. The feature extraction stage extracts and transforms feature values ​​from parallel input ECG signals to form a feature vector output. The classification stage reduces the network complexity and overfitting potential of the deep learning model to classify the output feature vector; the class with the higher probability is the classification result. The loss function combines cross-entropy loss and contrastive loss. The cross-entropy loss is defined as: Cross-Entropy Loss = -1 / n, where is the actual label (0 or 1); is the probability predicted by the model; n represents the number of samples, i.e., how many samples in the batch participate in the loss calculation; therefore, the cross-entropy loss is calculated on each sample, and then the average loss of all samples is taken. When the true label = 1 (positive class, i.e., insomnia group), the loss is -log(1 / n). If the probability predicted by the model is closer to 1, the loss is smaller, and vice versa. When the true label = 0 (negative class, i.e., non-insomnia group), the loss is -log(1- ). If the probability predicted by the model is closer to 0, the loss is smaller, and vice versa. The calculation of this contrastive loss is as follows: There are 3 samples in a batch: x1 (insomnia), x2 (insomnia), and x3 (non-insomnia). Each sample refers to the 30-second ECG signal of the three main sleep stages in parallel, with a dimension of 3000×3. The ECG signal of sample x1 can be represented as: x1,1, x1,2, x1,3, corresponding to the three main sleep stages respectively. The ECG signal of sample x2 can be represented as: x2,1, x2,2, x2,3, corresponding to the three main sleep stages respectively. The ECG signal of sample x3 can be represented as: x3,1, x3,2, x3,3, corresponding to the three main sleep stages; (x1,x2): positive sample pair, because both belong to the insomnia category; (x2,x3): negative sample pair, because they come from different categories (insomnia and non-insomnia); and (x1,x3): negative sample pair, because they come from different categories (insomnia and non-insomnia); A dataset is established using ECG signal data from different subjects provided by the Cyclic Alternating Patient (CAP) sleep database. The data provided by the sleep database includes at least two categories: insomnia group and non-insomnia group. That is, 100,000 3000×3 ECG signals are obtained from insomniacs and non-insomniacs in the sleep database, and 70% of the obtained signals are used as training set data, 15% as validation set data, and 15% as test set data for training, validation, and testing of the deep learning model;A training, validation, and testing model is established. The aforementioned training, validation, and testing sets are used to train, validate, and test the deep learning model. The loss function and optimizer work together to calculate the approximation between the deep learning model's output and the expected output. The optimizer has a bias correction mechanism, which enhances the stability of the calculated values. After obtaining an optimized model, the subject's entire night's sleep ECG signal is input. The optimized model's prediction probability is then used to detect the probability and generate a final classification as either insomnia or non-insomnia.

2. The insomnia detection method based on electrocardiogram analysis of each sleep stage as described in request item 1, wherein, The feature extraction stage has five convolutional neural network blocks with the same structure. Each convolutional neural network block has three parameters, which represent the number of channels used, core size, and stride (32,16,2), (16,16,2), (8,16,3), (4,16,3), and (1,16,3), respectively. In addition, the flat layer is responsible for converting the 2-dimensional feature matrix into a 1-dimensional feature vector and providing it to the classification stage. Furthermore, the classification stage has a fully connected neural network block with 1024 neurons and a fully connected layer using the Softmax activation function.

3. The insomnia detection method based on electrocardiogram analysis of each sleep stage as described in claim 2, wherein, Each convolutional neural network block is further composed of a convolutional neural network layer with parameters C and K, a batch normalization layer, an activation layer, a max pooling layer with a pooling size of 2, and a dropout layer with a dropout rate of 20%, connected in series. The aforementioned parameters C is the number of channels and K is the core size.

4. The insomnia detection method based on electrocardiogram analysis of each sleep stage as described in claim 2, wherein, The fully connected neural network block is further composed of a fully connected layer, a batch normalization layer, an activation layer, and a dropout layer with a dropout rate of 20%.

5. The insomnia detection method based on electrocardiogram analysis of each sleep stage as described in request item 1, wherein, The steps for calculating the contrast loss are as follows:

1. Calculate the distances between the three sample pairs: d1 = |||f(x1,1)-f(x2,1)|| + ||f(x2,1)-f(x2,2)|| + ||f(x1,3)-f(x2,3)|| d2 = ||f(x2,1)-f(x3,1)|| + ||f(x2,2)-f(x3,2)|| + ||f(x2,3)-f(x3,3)|| d3 = ||f(x1,1)-f(x3,1)|| + ||f(x1,2)-f(x3,2)|| + ||f(x1,3)-f(x3,3)|| Where f(xi,j) represents the j-th feature vector extracted by the deep learning model from sample xi, and in the deep learning model of this invention, its dimension is 28×1, while ‖.‖ represents the Euclidean distance of the vector; 2. Calculate the loss of positive sample pairs (same class): The first sample pair is the positive sample pair (x1,x2), y1=1, and the loss is, we hope that this distance d1 is as small as possible, so as to reduce the distance between samples of the same class; 3. Calculate the loss for negative sample pairs (different classes): The second sample pair is a negative sample pair (x2, x3), y2 = 0, and the loss is max(0, m - d2)2; The third sample pair is a negative sample pair (x1, x3), y3 = 0, and the loss is max(0, m - d3)2. Therefore, it is desirable for these distances d2 and d3 to be as large as possible, at least greater than the preset threshold m, in order to maximize the difference between samples of different classes; and 4. Calculate the total contrastive loss: Contrastive Loss = ; In this example, there are 3 sample pairs, so n = 3.

Citation Information

Patent Citations

  • A Sleep State Classification Method and System Based on Entropy Features and Support Vector Machines

    CN108968915B

  • Sleep awakening analysis method based on deep learning

    CN110811558A

  • Sleep signal automatic staging method based on improved deep learning algorithm model

    CN114366038A

  • Sleep staging method and device, electronic equipment and storage medium

    CN118177740A

  • Sleep state determining method and apparatus

    WO2020133536A1