ECG sleep apnea detection method and system based on time series contrast learning
By employing a time-series contrastive learning approach, using a Transformer encoder and contrastive learning, the problems of noise interference and gradient vanishing in single-channel ECG signal detection were solved, achieving more efficient sleep apnea detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING UNIV OF TECH
- Filing Date
- 2024-02-27
- Publication Date
- 2026-07-14
AI Technical Summary
When using single-channel ECG signals for sleep apnea detection, feature extraction is easily affected by noise, making it difficult for the model to accurately extract relevant features. Furthermore, introducing temporal context may lead to gradient vanishing or exploding, resulting in serious class confusion and affecting detection performance.
A time-series-based contrastive learning approach is adopted, which integrates contextual features through a Transformer encoder, assigns weights to feature information, and uses contrastive learning during the classification process to enhance the feature similarity of samples of the same class, reduce the feature similarity of samples of different classes, and improve the classification and detection performance.
It effectively prevents gradient vanishing or exploding during the learning process, improves the similarity of features among samples of the same class, reduces the similarity of features among samples of different classes, improves the problem of easy confusion between normal samples and sleep apnea samples, and achieves better classification and detection results.
Smart Images

Figure CN117838062B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electrocardiogram signal processing technology, and in particular to an ECG sleep apnea detection method and a ECG sleep apnea detection system based on time-series contrastive learning. Background Technology
[0002] The goal of sleep apnea detection is to effectively detect the occurrence of breathing pauses during an individual's sleep. Polysomnography (PSG), because it includes signals from multiple channels, can reflect an individual's sleep state from multiple perspectives, and is therefore often used for sleep apnea detection. However, when acquiring PSG signals, subjects need to wear multiple devices to enter sleep, which has disadvantages such as the subject's sleep state being easily affected and the acquisition equipment being expensive. Therefore, many researchers have begun to use single-channel signals for sleep apnea detection. Among these, electrocardiogram (ECG) signals can reflect the increase in systemic blood pressure and pulmonary artery pressure caused by breathing pauses, and have attracted much attention from researchers. However, using single-channel ECG signals for sleep apnea detection is less robust and easily affected by information loss due to noise. How to train an efficient sleep apnea detection model under the condition that ECG signals are contaminated with noise has become an urgent problem to be solved in the current medical and scientific communities.
[0003] In existing sleep apnea detection methods using electrocardiogram (ECG) signals, the feature extraction process is easily affected by noise in the signal due to the use of only a single-channel signal, making it difficult for the model to accurately extract features related to apnea detection. Some studies have used the method of introducing temporal context into the input segment into the model. This method can provide more features on a time scale, reduce the impact of noise on the target segment, and improve the accuracy of sleep apnea detection. However, introducing a large amount of temporal context can lead to the model over-focusing on features unrelated to apnea and ignoring effective features, potentially causing gradient vanishing or exploding during the learning process. On the other hand, it can blur the distinction between normal segments and apnea segments, easily leading to class confusion. This makes it difficult for the model to learn apnea-related features even with the introduction of temporal context.
[0004] Based on the above analysis, gradient vanishing or exploding and class confusion caused by excessive temporal context are the key problems faced by current sleep apnea detection methods using ECG signals. These problems affect the model's learning process and limit the detection performance. Summary of the Invention
[0005] To address the aforementioned issues, this invention provides an ECG sleep apnea detection method and system based on time-series contrastive learning. By fusing contextual features through a Transformer encoder and assigning weights to feature information, gradient vanishing or exploding during the learning process is prevented. Contrastive learning is used during classification to enhance the feature similarity of samples of the same class and reduce the feature similarity of samples of different classes, further constraining the features. This improves the problem of easy confusion between normal samples and sleep apnea samples, achieving better classification and detection results.
[0006] To achieve the above objectives, this invention provides an ECG sleep apnea detection method based on time-series contrastive learning, comprising:
[0007] Acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data;
[0008] The ECG feature data is processed using a multi-scale contextual CNN-LSTM module to obtain branch features;
[0009] A weighted feature is obtained by assigning weights to the branch features using a Transformer encoder, and a joint feature is obtained based on the branch features and the weighted feature.
[0010] The loss function is obtained by performing comparative learning analysis on the joint features, and the parameters of the classifier are optimized.
[0011] The combined features are input into the classifier to obtain the detection result of whether sleep apnea exists.
[0012] In the above technical solution, preferably, the specific process of preprocessing the electrocardiogram signal data to obtain electrocardiogram feature data includes:
[0013] The electrocardiogram (ECG) signal data is bandpass filtered, and the filtered ECG signal data is segmented into data segments using a sliding window.
[0014] Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude;
[0015] Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain electrocardiogram feature data that meets the preset standards.
[0016] In the above technical solution, preferably, the specific process of processing the ECG feature data using a multi-scale contextual CNN-LSTM module to obtain branch features includes:
[0017] The electrocardiogram feature data is divided into segments containing contexts at different scales;
[0018] The CNN-LSTM module includes a branch structure, with each branch consisting of a dilated convolution module with different dilation coefficients and a bidirectional LSTM module.
[0019] The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the inputs of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
[0020] In the above technical solution, preferably, the step of using a Transformer encoder to assign weights to the branch features to obtain weighted features, and obtaining joint features based on the branch features and the weighted features, specifically includes:
[0021] The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence.
[0022] The feature sequence is input into the attention module to calculate the attention weight matrix of the feature sequence;
[0023] Multiplying the attention weight matrix by the feature sequence yields weighted features;
[0024] The weighted features are added to the branch features and then subjected to layer normalization to obtain the joint features at all scales.
[0025] In the above technical solution, preferably, the step of performing comparative learning analysis on the joint features to obtain a loss function and optimizing the parameters of the classifier specifically includes:
[0026] The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated.
[0027] The contrastive loss is calculated using the branch features, and the squared hinge loss and the contrastive loss are combined as a loss function to optimize the parameters of the classifier.
[0028] This invention also proposes an ECG sleep apnea detection system based on time-series contrastive learning, which applies the ECG sleep apnea detection method based on time-series contrastive learning disclosed in any of the above technical solutions, including:
[0029] The data preprocessing module is used to acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data.
[0030] The feature data segmentation module is used to process the ECG feature data using a multi-scale context CNN-LSTM module to obtain branch features;
[0031] The feature weighted fusion module is used to assign weights to the branch features using a Transformer encoder to obtain weighted features, and to obtain joint features based on the branch features and the weighted features.
[0032] The comparison classification optimization module is used to perform comparative learning analysis on the joint features to obtain a loss function and optimize the parameters of the classifier;
[0033] The data result classification module is used to input the joint features into the classifier to obtain the detection result of whether sleep apnea exists.
[0034] In the above technical solution, preferably, the data preprocessing module is specifically used for:
[0035] The electrocardiogram (ECG) signal data is bandpass filtered, and the filtered ECG signal data is segmented into data segments using a sliding window.
[0036] Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude;
[0037] Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain electrocardiogram feature data that meets the preset standards.
[0038] In the above technical solution, preferably, the feature data segmentation module is specifically used for:
[0039] The electrocardiogram feature data is divided into segments containing contexts at different scales;
[0040] The CNN-LSTM module includes a branch structure, with each branch consisting of a dilated convolution module with different dilation coefficients and a bidirectional LSTM module.
[0041] The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the inputs of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
[0042] In the above technical solution, preferably, the feature weighted fusion module is specifically used for:
[0043] The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence.
[0044] The feature sequence is input into the attention module to calculate the attention weight matrix of the feature sequence;
[0045] Multiplying the attention weight matrix by the feature sequence yields weighted features;
[0046] The weighted features are added to the branch features and then subjected to layer normalization to obtain the joint features at all scales.
[0047] In the above technical solution, preferably, the comparison and classification optimization module is specifically used for:
[0048] The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated.
[0049] The contrastive loss is calculated using the branch features, and the squared hinge loss and the contrastive loss are combined as a loss function to optimize the parameters of the classifier.
[0050] Compared with the prior art, the beneficial effects of the present invention are as follows: by fusing contextual features through the Transformer encoder and assigning weights to feature information, gradient vanishing or exploding during the learning process is prevented; contrastive learning is used in the classification process to enhance the feature similarity of samples of the same class and reduce the feature similarity of samples of different classes, further constraining features, thereby improving the problem of easy confusion between normal samples and sleep apnea samples, and achieving better classification and detection results. Attached Figure Description
[0051] Figure 1 This is a flowchart illustrating an ECG sleep apnea detection method based on time-series contrastive learning, as disclosed in one embodiment of the present invention.
[0052] Figure 2 This is a schematic flowchart of a preprocessing procedure disclosed in one embodiment of the present invention;
[0053] Figure 3 This is a schematic diagram of the multi-scale contextual CNN-LSTM processing flow disclosed in one embodiment of the present invention;
[0054] Figure 4 This is a schematic diagram of the processing flow of the Transformer encoder fusion module disclosed in one embodiment of the present invention;
[0055] Figure 5 This is a schematic diagram of the comparison learning classification process disclosed in one embodiment of the present invention;
[0056] Figure 6 This is a schematic diagram of a module of an ECG sleep apnea detection system based on time-series contrastive learning, as disclosed in one embodiment of the present invention.
[0057] In the diagram, the correspondence between the components and the reference numerals is as follows:
[0058] 1. Data preprocessing module; 2. Feature data segmentation module; 3. Feature weighted fusion module; 4. Comparison and classification optimization module; 5. Data result classification module. Detailed Implementation
[0059] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0060] The present invention will now be described in further detail with reference to the accompanying drawings:
[0061] like Figure 1 As shown, the ECG sleep apnea detection method based on time-series contrastive learning according to the present invention includes:
[0062] Acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data;
[0063] The ECG feature data is processed using a multi-scale contextual CNN-LSTM module to obtain branch features;
[0064] A Transformer encoder is used to assign weights to branch features to obtain weighted features, and joint features are obtained based on branch features and weighted features.
[0065] The loss function is obtained by comparative learning analysis of the joint features, and the parameters of the classifier are optimized.
[0066] The combined features are input into the classifier to obtain the detection results of whether sleep apnea exists.
[0067] In this implementation, a single-channel electrocardiogram signal is used to detect apnea. Contextual features are fused through a Transformer encoder, and weights are assigned to the feature information to prevent gradient vanishing or exploding during the learning process. Contrastive learning is used during classification to enhance the feature similarity of samples of the same class, further constrain the features, and reduce the feature similarity of samples of different classes. This improves the problem of easy confusion between normal samples and apnea samples, and achieves better classification and detection results.
[0068] Specifically, during preprocessing, sleep apnea-related features are extracted from single-channel electrocardiogram (ECG) signals. During training, convolutional neural networks (CNNs) and bidirectional long short-term memory (LSTM) neural networks are used to extract features from contexts at different scales, learning the weights of associated features over longer time spans to obtain feature sequences for different contexts. The model then assigns different weights to the features using a Transformer encoder to increase the importance of effective features. Finally, through contrastive learning, the extracted weighted features are detected, ultimately completing the model's feature extraction and sleep apnea detection.
[0069] To achieve highly accurate sleep apnea detection, the model first needs to be provided with R-peak correlation features from electrocardiogram (ECG) signals. These features reflect elevated systemic blood pressure and pulmonary artery pressure, which are associated with the occurrence of apnea. Subsequently, a multi-scale contextual CNN-LSTM module is used to further extract correlated features from contexts at different scales. Then, a Transformer encoder fusion module is used to assign different weights to the correlated features at different scales. Finally, a contrastive classification module is used to learn the similarity distribution of sample features, which not only has temporal correlation characteristics but also reflects the importance of different features to apnea.
[0070] like Figure 2 As shown, in the above embodiment, preferably, the specific process of preprocessing the electrocardiogram signal data to obtain electrocardiogram feature data includes:
[0071] Bandpass filtering is applied to the ECG signal data, and a sliding window is used to segment the filtered ECG signal data into data segments.
[0072] Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude;
[0073] Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain ECG feature data that meets the preset standards.
[0074] Specifically, during bandpass filtering, the original ECG signal can be processed using an FIR bandpass filter with a minimum frequency of 3Hz and a maximum frequency of 45Hz. Using a sliding window method, the signal can be divided into 5-minute time segments. During the removal of abnormal segments, all segments with heart rates exceeding 200 or below 30 can be eliminated. During resampling, cubic interpolation can be used for shorter segments, and pruning can be used for longer segments, thus resampling all segments to a fixed length.
[0075] like Figure 3As shown, in the above embodiment, preferably, the specific process of processing ECG feature data using a multi-scale contextual CNN-LSTM module to obtain branch features includes:
[0076] The electrocardiogram feature data was divided into segments containing contexts at different scales;
[0077] The CNN-LSTM module includes a branch structure, with each branch consisting of dilated convolutional modules with different dilation coefficients and bidirectional LSTM modules;
[0078] The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the input of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
[0079] In this implementation, the goal of the process is to capture correlated features within different temporal contexts at different scales. Specifically, the fixed-length correlated features obtained in the above implementation are divided into three different scales: short, medium, and long, each containing or not containing different contexts. Features at different scales serve as input to their respective branches. Each branch consists of four dilated convolutional modules divided into two classes and one bidirectional LSTM module. Average pooling is used between the convolutional modules to reduce dimensionality. The final branch outputs a correlated feature sequence X. output .
[0080] x m1 =Avg(CE(x)+x)
[0081] x m2 =Avg(CO(x) m1 )+x m1 )
[0082] x m3 =Avg(CO(x) m2 )+x m2 )
[0083] x m4 =CE(x) m3 )+x m3
[0084] x output =BiLSTM(x m4 )
[0085] In this context, CE and CO represent two types of dilated convolution modules, BiLSTM represents a bidirectional LSTM module, and Avg represents the average pooling operation.
[0086] Both types of dilated convolution modules have the same structure, consisting of four sets of repeated steps. The only difference between them is the dilation coefficient during convolution. Each step includes four operations: dilated convolution, batch normalization, activation, and discarding.
[0087] x1 = Conv(w,x,p) dilation )+b
[0088] x2=γNorm(x1)+β
[0089] STEP(x,p dilation = Drop(f(x2))
[0090] Where Conv represents the dilated convolution operation, w and b represent its weights and biases respectively, Norm represents the batch normalization operation, γ and β represent its translation and scaling parameters respectively, f(x) represents the activation operation using the ReLU function, and Drop represents the drop operation.
[0091] Finally, the outputs of the three branches are concatenated to obtain the context feature sequence f.
[0092] f = catch(x) short ,x middle ,x long )
[0093] Where catch represents the concatenation operation, x short x middle x long These represent the branch outputs corresponding to the short, medium, and long time contexts, respectively.
[0094] As shown in Table 1 below, the method of the present invention has better performance than the latest method using ECG. As shown in Table 2 below, the method of the present invention performs best when using time contexts at 1-minute, 3-minute, and 5-minute scales.
[0095] Table 1 Comparison of the effects of this invention with other different models.
[0096] method years Accuracy (%) Shen Deep learning 2021 89.4 Hemrajani Deep learning 2023 89.5 Indrawati Machine Learning 2021 84.64 Qin Deep learning 2022 91.1 Yeo Deep learning 2022 86 Zhou Deep learning 2022 90.93 Chen Deep learning 2022 89.84 Feng Deep learning 2021 85.1 Bernardini Deep learning 2021 88.48 This invention Deep learning 91.5
[0097] Table 2 Comparison of the effects of time context of different lengths
[0098]
[0099]
[0100] like Figure 4As shown, in the above embodiment, preferably, a Transformer encoder is used to assign weights to the branch features to obtain weighted features, and joint features are obtained based on the branch features and weighted features. The specific process includes:
[0101] The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence.
[0102] The feature sequence is input into the self-attention module, and the attention weight matrix of the feature sequence is calculated.
[0103] Multiply the attention weight matrix by the feature sequence to obtain the weighted features;
[0104] The weighted features and branch features are added together and then processed using layer normalization to obtain the joint features at all scales.
[0105] In this embodiment, the feature sequence f is positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence:
[0106]
[0107]
[0108] Where PE represents the element's position information, i represents the element's scale, pos represents the element's position within the scale, and F represents the total number of scales. This represents the feature sequence after adding location information.
[0109] Then, the obtained feature sequence is input into four repeated self-attention modules, and a weighting matrix of the feature sequence is calculated in each module to finally obtain the encoder output:
[0110] f′ i =TransformerEncoder(f′) i-1 ), 1≤i≤4
[0111] When i = 1
[0112] In each self-attention module, the input feature sequence f′ is changed. i-1 The shape is obtained by dividing Q, K, and V into three matrices. Q, K, and V are divided into H segments, called H heads. A self-attention mechanism is used to obtain the attention calculation results for each head, and the calculation results of each head are concatenated into a weighted feature sequence f′. i :
[0113] Q = K = V = f′ i-1
[0114]
[0115] f′ i =catch(Attention(Q) h ,K h V h ),1≤h≤H
[0116] Where h represents the h-th head, and d is f′ i-1 Dimensions.
[0117] Finally, the weighted feature sequence f′4 is compared with... Add them together and perform layer normalization to obtain the joint feature f′ across all scales:
[0118]
[0119] LayerNorm represents the layer normalization operation.
[0120] Table 3 below shows a comparison of the effects of the Transformer encoding used in this invention compared to other fusion mechanisms in the prior art.
[0121] Table 3 Comparison of the effects of different fusion mechanisms
[0122]
[0123] like Figure 5 As shown, in the above implementation, preferably, a loss function is obtained by performing contrastive learning analysis on the joint features, and the parameters of the classifier are optimized. The specific process includes:
[0124] The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated.
[0125] The contrastive loss is calculated using branch features, and the squared hinge loss and contrastive loss are combined as the loss function to optimize the parameters of the classifier.
[0126] In this implementation, the feature sequence f′ is input into the classifier to obtain the detection result of apnea:
[0127] f″ = Drop(ReLU(f′))
[0128] Output = Softmax(f″)
[0129] Here, ReLU represents the activation operation using the ReLU function. Drop represents the drop operation. Softmax represents the activation operation using the softmax function.
[0130] Then, in order to train the model, a combination of squared hinge loss and contrastive loss is used as the loss function to measure the difference between the classification result and the true label, thereby optimizing the model parameters.
[0131]
[0132]
[0133] L(y pred ,y true )=0.1×L1(y pred ,y true )+L2(y pred ,y true )
[0134] Where N represents the total sample size, y pred y represents the predicted value of the sample. true N represents the actual value of the sample. j This represents the number of samples of the same class as j. `bool` is used to determine whether two samples belong to the same class. i,j Indicates feature i With feature j The similarity loss.
[0135] feature=x short
[0136]
[0137] Among them, feature i To represent the features of sample i, the feature sequence x is used in this invention. short As a sample feature, sim represents cosine similarity, and τ is the hyperparameter comparison temperature.
[0138] Table 4 below shows a comparison of the effects of the loss function used in this invention with other loss functions in the prior art.
[0139] Table 4 Comparison of the effects of different loss functions
[0140]
[0141] The ECG automatic sleep apnea detection method based on time-series contrastive learning disclosed in the above embodiments improves upon the problems of gradient explosion or vanishing and category ambiguity caused by the introduction of temporal context when using ECG data in traditional detection models by using a Transformer encoder during the fusion process and contrastive learning during the classification process. Compared with existing technologies, the Transformer encoder introduced in this method can assign weights to features extracted from the temporal context, causing feature information to concentrate in local areas relevant to the target. In addition, the contrastive learning introduced in this invention can increase the feature similarity of samples of the same class and reduce the feature similarity of samples of different classes, thus constraining the sample features. Therefore, this method not only achieves efficient and accurate detection of sleep apnea, but also supports detection tasks in scenarios where ECG signals are interfered with by noise.
[0142] like Figure 6 As shown, this invention also proposes an ECG sleep apnea detection system based on time-series contrastive learning, which applies the ECG sleep apnea detection method based on time-series contrastive learning disclosed in any of the above embodiments, including:
[0143] Data preprocessing module 1 is used to acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data;
[0144] Feature data segmentation module 2 is used to process ECG feature data using a multi-scale contextual CNN-LSTM module to obtain branch features;
[0145] Feature weighted fusion module 3 is used to assign weights to branch features using a Transformer encoder to obtain weighted features, and to obtain joint features based on branch features and weighted features.
[0146] The contrast classification optimization module 4 is used to perform contrastive learning analysis on the joint features to obtain the loss function and optimize the parameters of the classifier;
[0147] Data result classification module 5 is used to input joint features into the classifier to obtain the detection result of whether sleep apnea exists.
[0148] In this implementation, the Transformer encoder fuses contextual features and assigns weights to feature information, preventing gradient vanishing or exploding during the learning process. Contrastive learning is used in the classification process to enhance the feature similarity of samples of the same class, further constrain the features, and reduce the feature similarity of samples of different classes. This improves the problem of easy confusion between normal samples and sleep apnea samples, and achieves better classification and detection results.
[0149] In the above embodiments, preferably, the data preprocessing module 1 is specifically used for:
[0150] Bandpass filtering is applied to the ECG signal data, and a sliding window is used to segment the filtered ECG signal data into data segments.
[0151] Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude;
[0152] Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain ECG feature data that meets the preset standards.
[0153] In the above embodiments, preferably, the feature data partitioning module 2 is specifically used for:
[0154] The electrocardiogram feature data was divided into segments containing contexts at different scales;
[0155] The CNN-LSTM module includes a branch structure, with each branch consisting of dilated convolutional modules with different dilation coefficients and bidirectional LSTM modules;
[0156] The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the input of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
[0157] In the above embodiments, preferably, the feature weighted fusion module 3 is specifically used for:
[0158] The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence.
[0159] The feature sequence is input into the self-attention module, and the attention weight matrix of the feature sequence is calculated.
[0160] Multiply the attention weight matrix by the feature sequence to obtain the weighted features;
[0161] The weighted features and branch features are added together and then processed using layer normalization to obtain the joint features at all scales.
[0162] In the above embodiments, preferably, the comparison and classification optimization module 4 is specifically used for:
[0163] The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated.
[0164] The contrastive loss is calculated using branch features, and the squared hinge loss and contrastive loss are combined as the loss function to optimize the parameters of the classifier.
[0165] According to the ECG sleep apnea detection system based on time series contrastive learning disclosed in the above embodiments, the functions to be implemented by each module correspond to the steps of the ECG sleep apnea detection method based on time series contrastive learning disclosed in the above embodiments. In the implementation process, refer to the above embodiments for operation, and will not be repeated here.
[0166] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for detecting ECG sleep apnea based on time-series contrastive learning, characterized in that, include: Acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data; The ECG feature data is processed using a multi-scale contextual CNN-LSTM module to obtain branch features; A weighted feature is obtained by assigning weights to the branch features using a Transformer encoder, and a joint feature is obtained based on the branch features and the weighted feature. The loss function is obtained by performing comparative learning analysis on the joint features, and the parameters of the classifier are optimized. The combined features are input into the classifier to obtain the detection result of whether sleep apnea exists.
2. The ECG sleep apnea detection method based on time-series contrastive learning according to claim 1, characterized in that, The specific process of preprocessing the electrocardiogram signal data to obtain electrocardiogram feature data includes: The electrocardiogram (ECG) signal data is bandpass filtered, and the filtered ECG signal data is segmented into data segments using a sliding window. Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude; Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain electrocardiogram feature data that meets the preset standards.
3. The ECG sleep apnea detection method based on time-series contrastive learning according to claim 1, characterized in that, The specific process of using the CNN-LSTM module with multi-scale context to process the ECG feature data to obtain branch features includes: The electrocardiogram feature data is divided into segments containing contexts at different scales; The CNN-LSTM module includes a branch structure, with each branch consisting of a dilated convolution module with different dilation coefficients and a bidirectional LSTM module. The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the inputs of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
4. The ECG sleep apnea detection method based on time-series contrastive learning according to claim 1, characterized in that, The process of assigning weights to the branch features using a Transformer encoder to obtain weighted features, and obtaining joint features based on the branch features and the weighted features, specifically includes: The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence. The feature sequence is input into the attention module to calculate the attention weight matrix of the feature sequence; Multiplying the attention weight matrix by the feature sequence yields weighted features; The weighted features are added to the branch features and then subjected to layer normalization to obtain the joint features at all scales.
5. The ECG sleep apnea detection method based on time-series contrastive learning according to claim 1, characterized in that, The process of performing comparative learning analysis on the joint features to obtain the loss function and optimizing the parameters of the classifier includes: The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated. The contrastive loss is calculated using the branch features, and the squared hinge loss and the contrastive loss are combined as a loss function to optimize the parameters of the classifier.
6. An ECG sleep apnea detection system based on time-series contrastive learning, characterized in that, The ECG sleep apnea detection method based on time-series contrastive learning as described in any one of claims 1 to 5 includes: The data preprocessing module is used to acquire single-channel electrocardiogram (ECG) signal data and preprocess the ECG signal data to obtain ECG feature data. The feature data segmentation module is used to process the ECG feature data using a multi-scale context CNN-LSTM module to obtain branch features; The feature weighted fusion module is used to assign weights to the branch features using a Transformer encoder to obtain weighted features, and to obtain joint features based on the branch features and the weighted features. The comparison classification optimization module is used to perform comparative learning analysis on the joint features to obtain a loss function and optimize the parameters of the classifier; The data result classification module is used to input the joint features into the classifier to obtain the detection result of whether sleep apnea exists.
7. The ECG sleep apnea detection system based on time-series contrastive learning according to claim 6, characterized in that, The data preprocessing module is specifically used for: The electrocardiogram (ECG) signal data is bandpass filtered, and the filtered ECG signal data is segmented into data segments using a sliding window. Find all R-peaks in the segmented data fragments and extract features by calculating the RR interval and R-peak amplitude; Abnormal segments that exceed the preset range are removed, and the data segments are resampled to obtain electrocardiogram feature data that meets the preset standards.
8. The ECG sleep apnea detection system based on time-series contrastive learning according to claim 7, characterized in that, The feature data partitioning module is specifically used for: The electrocardiogram feature data is divided into segments containing contexts at different scales; The CNN-LSTM module includes a branch structure, with each branch consisting of a dilated convolution module with different dilation coefficients and a bidirectional LSTM module. The same branching structure is used to process the segments. The ECG feature data of segments at different scales are used as the inputs of their respective branches, and the outputs of each branch are spliced together to obtain the branch features.
9. The ECG sleep apnea detection system based on time-series contrastive learning according to claim 8, characterized in that, The feature weighted fusion module is specifically used for: The branch features are positionally encoded to obtain the position information of all elements in the feature sequence, and the position information is added to the feature sequence. The feature sequence is input into the attention module to calculate the attention weight matrix of the feature sequence; Multiplying the attention weight matrix by the feature sequence yields weighted features; The weighted features are added to the branch features and then subjected to layer normalization to obtain the joint features at all scales.
10. The ECG sleep apnea detection system based on time-series contrastive learning according to claim 9, characterized in that, The comparison and classification optimization module is specifically used for: The joint features are classified using excitation and discard operations, and the squared hinge loss is calculated. The contrastive loss is calculated using the branch features, and the squared hinge loss and the contrastive loss are combined as a loss function to optimize the parameters of the classifier.
Citation Information
Patent Citations
Sleep data processing method and system driven by fusion of polysleep monitoring signals
CN116649903A
Multi-modal data enhancement and coding method for unsupervised comparative learning
CN116843013A