A sleep apnea detection method, system, electronic device and storage medium
By employing a multi-scale cross-attention framework and dynamic feature fusion technology, the problem of insufficient multi-scale feature fusion in sleep apnea detection is solved, achieving high-precision and robust sleep apnea detection suitable for portable devices.
Patent Information
- Application Number
- CN202510991899.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2045-07-18
AI Technical Summary
Existing deep learning methods have failed to effectively integrate multi-scale features in sleep apnea detection, resulting in insufficient detection accuracy and generalization ability. Traditional ECG detection methods rely on manual feature extraction and are susceptible to individual differences and noise interference.
A multi-scale cross-attention framework is adopted to extract deep features from ECG and respiratory signals through a parallel feature extraction network, and feature fusion is performed by using a cross-scale dynamic weight correction attention mechanism. The improved Q-Former module is combined for feature compression and classification.
It achieves accurate detection of sleep apnea events, improves the robustness and detection accuracy of the model, is suitable for home monitoring with portable devices, and overcomes the limitations of traditional methods.
Smart Images

Figure CN120477748B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of deep learning and medical signal processing technology, and in particular to a sleep apnea detection method, system, electronic device and storage medium utilizing multi-scale feature extraction and cross-attention mechanism. Background Technology
[0002] Sleep apnea (SA) is a common and serious sleep disorder characterized by recurrent episodes of apnea or hypopnea during sleep. These events can lead to intermittent hypoxemia, hypercapnia, and disrupted sleep structure. Without effective treatment, it can significantly increase the risk of various chronic diseases such as hypertension, cardiovascular disease, and type 2 diabetes, and in severe cases, may even cause sudden nocturnal death.
[0003] Currently, polysomnography (PSG) is the gold standard for diagnosing sleep apnea. PSG comprehensively monitors multiple physiological parameters, including electroencephalography (EEG), electrooculography (EOG), electromyography (EMG), electrocardiography (ECG), respiratory airflow, and blood oxygen saturation, resulting in high diagnostic accuracy. However, PSG also has significant drawbacks: First, it requires a specialized sleep laboratory with expensive and complex equipment, necessitating overnight monitoring by professional technicians; second, patients must wear multiple sensors throughout their body overnight, which can cause discomfort, disrupt normal sleep, and potentially distort diagnostic results; finally, the high cost and limited medical resources make it difficult to popularize in primary healthcare institutions and home settings, resulting in a large number of potential patients not receiving timely screening and diagnosis.
[0004] To overcome the limitations of PSG, researchers have turned to developing alternative diagnostic techniques based on more convenient physiological signals. Among these, electrocardiography (ECG) has become a hot topic in sleep apnea screening research due to its non-invasiveness, ease of acquisition, low cost, and the widespread availability of related equipment. Sleep apnea events affect the cardiovascular system through the autonomic nervous system, and these effects leave specific imprints on ECG signals, such as periodic changes in heart rate variability (HRV) and fluctuations in R wave amplitude.
[0005] Traditional ECG-based detection methods rely heavily on machine learning algorithms, typically involving three steps: signal preprocessing, manual feature extraction, and classifier design. For example, time-domain, frequency-domain, or nonlinear dynamic features such as RR intervals, R-peak amplitude, and QRS group morphology are extracted and then input into classifiers like Support Vector Machines (SVM) or Random Forests for discrimination. The performance of these methods is highly dependent on the quality of feature engineering; the selected features may lack universality and are easily affected by individual differences and signal noise, making it difficult to capture the complex dynamic changes exhibited by SA events at different time scales.
[0006] In recent years, with the rise of deep learning technology, especially convolutional neural networks (CNNs) and recurrent neural networks (RNNs), automatic detection methods based on ECG have shown great potential. Deep learning models can automatically learn discriminative hierarchical features from raw signals, avoiding the tedious and subjective manual feature extraction process. However, existing deep learning methods still face a key challenge: insufficient multi-scale feature fusion. The performance of SA in ECG signals varies significantly over time: in the short term (e.g., within 1 minute), it may manifest as a sharp change in heart rate, while in the medium term (e.g., 3–5 minutes), it may reflect periodic fluctuations in heart rate caused by respiratory rhythm disturbances. Existing models typically use a single fixed-length signal segment for analysis, or simply splice or add features extracted at different scales. This approach ignores the inherent correlation and dynamic interaction between features at different scales, leading to the loss of key discriminative information and limiting the detection accuracy and generalization ability of the model.
[0007] Therefore, there is an urgent need to develop an ECG analysis method that can intelligently integrate multi-scale features to detect sleep apnea events more accurately and robustly, providing core technical support for the development of portable devices suitable for clinical and home monitoring. Summary of the Invention
[0008] To address the aforementioned technical problems, this invention proposes a method, system, electronic device, and storage medium for detecting sleep apnea. The core of this method lies in achieving collaborative analysis and intelligent fusion of ECG signals and respiratory signals at different time scales through an innovative multi-scale cross-attention framework.
[0009] In a first aspect, the present invention provides a method for detecting sleep apnea, comprising the following steps:
[0010] S1: Acquire synchronously collected electrocardiogram (ECG) signals and respiratory signals, preprocess the ECG signals and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a dual-modal multi-scale dataset containing ECG sequences and respiratory signal sequences;
[0011] S2: For the signal segments at the at least two different time scales, a parallel feature extraction network is used to extract deep features of the corresponding scales from the electrocardiogram sequence and the respiratory signal sequence, and a cross-modal feature is generated for each scale.
[0012] S3: A cross-scale dynamic weight correction attention mechanism is adopted to interact and fuse the cross-modal features at multiple scales. The cross-scale dynamic weight correction attention mechanism dynamically corrects the attention weights according to the vector differences between features at different scales, so as to adaptively aggregate the most discriminative information at each scale.
[0013] S4: The fused features are input into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features.
[0014] As an optional implementation of the first aspect of this application, in step S1, the at least two different preset time scales are 1 minute, 3 minutes and 5 minutes; the preprocessing specifically includes: applying a bandpass filter of 3 to 45 Hz to the electrocardiogram signal, and using the Hamiltonian algorithm to locate the R peak to extract the RR interval and R peak amplitude features; applying a bandpass filter of 0.1 to 1 Hz to the respiratory signal to extract the respiratory amplitude and the rate of change features calculated by numerical differentiation.
[0015] As an optional implementation of the first aspect of this application, in step S2, the parallel feature extraction network is a parallel bimodal dilated convolutional neural network; step S2 specifically includes: for each time scale, setting dilated convolutional network branches for electrocardiogram sequences and respiratory signal sequences respectively, the dilated convolutional network branches extracting multi-level waveform and rhythm features through dilated convolutional layers with adjustable dilation rates and adaptive pooling layers; projecting the features extracted by the electrocardiogram network branch and the respiratory signal network branch at each scale onto a preset dimension and then splicing them together to form the cross-modal features.
[0016] As an optional implementation of the first aspect of this application, in step S3, the implementation of the cross-scale dynamic weight correction attention mechanism includes: generating query matrices, key matrices, and value matrices for the cross-modal features at different scales; when calculating the attention score between the query matrix at any scale and the key matrix at another scale, introducing a correction factor based on the Euclidean distance between the feature vectors of the two scales, and processing the correction factor using the ReLU activation function to enhance the interaction weights for significantly different features; normalizing the attention score after superimposing the correction factor using the Softmax function to obtain the final attention weights, and using the attention weights to perform a weighted summation on the corresponding value matrices to fuse cross-scale information.
[0017] As an optional implementation of the first aspect of this application, in step S4, the feature compression module is an improved Q-Former module, and the classifier is a multilayer perceptron; step S4 specifically includes: concatenating the fused features from all scales along the sequence dimension to form a high-dimensional concatenated feature; inputting the high-dimensional concatenated feature into the improved Q-Former module, wherein the improved Q-Former module uses a query vector to perform multi-head attention interaction with the high-dimensional concatenated feature to achieve feature compression and dimensionality reduction; and inputting the low-dimensional feature vector output by the improved Q-Former module into the multilayer perceptron for final classification.
[0018] As an optional implementation of the first aspect of this application, the query vector of the improved Q-Former module is a learnable query vector, and an auxiliary query vector is introduced, which is calculated from the feature entropy values of the electrocardiogram sequence and the respiratory signal sequence. The auxiliary query vector is used to enhance the model's sensitivity to the detection of abnormal signal states.
[0019] As an optional implementation of the first aspect of this application, the method further includes a model training step, wherein the model training step employs the Adam optimizer and uses a bimodal cross-entropy loss function to train the model end-to-end; the bimodal cross-entropy loss function is a combination of classification loss based on electrocardiogram features and classification loss based on respiratory signal features.
[0020] Secondly, embodiments of this application provide a sleep apnea detection system, comprising:
[0021] The dataset construction module is used to acquire synchronously collected electrocardiogram (ECG) signals and respiratory signals, preprocess the ECG signals and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a dual-modal multi-scale dataset containing ECG sequences and respiratory signal sequences.
[0022] The parallel feature extraction module is used to extract deep features of corresponding scales from the electrocardiogram sequence and the respiratory signal sequence respectively for the signal segments of the at least two different time scales using a parallel feature extraction network, and generate a cross-modal feature for each scale.
[0023] The cross-scale feature fusion module is used to interact and fuse the cross-modal features of multiple scales by adopting a cross-scale dynamic weight correction attention mechanism. The cross-scale dynamic weight correction attention mechanism dynamically corrects the attention weights according to the vector differences between features of different scales, so as to adaptively aggregate the most discriminative information in each scale.
[0024] The compression classification module is used to input the fused features into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features.
[0025] Thirdly, embodiments of this application provide an electronic device, which includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the steps of the method described in the first aspect.
[0026] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0027] Compared with existing technologies, the beneficial effects of this invention's proposed sleep apnea detection method utilizing multi-scale feature extraction and cross-attention mechanisms are as follows:
[0028] (1) This invention achieves comprehensive feature capture of electrocardiogram (ECG) signals through a multi-timescale collaborative analysis framework. This method decomposes ECG signals into analysis segments of different time lengths, enabling the system to simultaneously identify instantaneous ECG waveform abnormalities, mid-term respiratory rhythm disturbances, and long-term physiological trend changes. This multi-scale analysis method overcomes the limitations of traditional single-scale detection and can more comprehensively reflect the complex physiological manifestations of sleep apnea, especially showing better identification ability for atypical or intermittent cases.
[0029] (2) A unique cross-scale dynamic weight correction attention mechanism constructs an intelligent interaction channel between features at different scales. This mechanism achieves dynamic fusion of local and global features through adaptive weight allocation, enabling the system to autonomously discover and strengthen the most diagnostically valuable information combinations. This feature fusion method not only improves the model's sensitivity to key features but also effectively suppresses noise interference, significantly enhancing the system's robustness while maintaining high accuracy.
[0030] (3) A specially optimized signal processing workflow was adopted to accurately extract key features such as the R-peak position and RR interval from the raw ECG signal. Through innovative filtering algorithms and peak detection technology, the accuracy and stability of feature extraction were ensured, providing a reliable data foundation for subsequent analysis. This preprocessing step was specifically optimized for common ECG signal interference during sleep, effectively overcoming problems such as baseline drift and electromyographic interference.
[0031] (4) The overall solution features a complete lightweight processing architecture, enabling efficient processing from signal acquisition to analysis result output. Through modular design and computational optimization, the algorithm is designed to run stably on portable devices, meeting the application needs of home monitoring and mobile healthcare. Attached Figure Description
[0032] Figure 1 This is a flowchart of a sleep apnea detection method according to an embodiment of the present invention;
[0033] Figure 2 This is a diagram of a parallel bimodal dilated convolutional neural network architecture according to an embodiment of the present invention;
[0034] Figure 3 This is a schematic diagram of a sleep apnea detection system provided in an embodiment of the present invention. Detailed Implementation
[0035] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0036] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0037] Example 1
[0038] Please see Figure 1 This is a flowchart illustrating a sleep apnea detection method provided in an embodiment of the present invention. The method may include the following steps:
[0039] S1: Acquire synchronously collected electrocardiogram (ECG) signals and respiratory signals, preprocess the ECG signals and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a dual-modal multi-scale dataset containing ECG sequences and respiratory signal sequences.
[0040] This step aims to build a bimodal, multi-scale dataset suitable for subsequent model training and validation.
[0041] Specifically, single-lead ECG signals during patient sleep were collected from the public PhysioNet Apnea-ECG dataset, with simultaneous acquisition of respiratory signals such as chest wall motion or nasal airflow. The sampling rate was set to 100Hz for both. This dataset includes a number of synchronized ECG-respiratory signal recordings, each ranging from 7 to 10 hours in length, with each minute of data labeled by medical experts as either "apnea (A)" or "normal (N)". In the raw signal preprocessing stage, the ECG signals were first processed using a 3–45Hz bandpass filter to remove baseline drift and high-frequency noise, and the Hamiltonian algorithm was used to detect the R-peak and extract the RR interval and R-peak amplitude. The respiratory signals were processed using a 0.1–1Hz bandpass filter to remove motion artifacts, and the respiratory amplitude and rate of change were extracted (calculated through numerical differentiation). Subsequently, both types of signals were smoothed using median filtering, and time synchronization calibration was performed to ensure temporal alignment between the ECG and respiratory signals. Finally, the preprocessed ECG and respiratory signals were divided into segments of three scales: 1 minute, 3 minutes, and 5 minutes according to the time dimension. Each segment contained a synchronized ECG sequence and a respiratory signal sequence, thus constructing an ECG-respiratory bimodal multiscale dataset.
[0042] S2: For the signal segments at the at least two different time scales, a parallel feature extraction network is used to extract deep features of the corresponding scales from the electrocardiogram sequence and the respiratory signal sequence, and a cross-modal feature is generated for each scale.
[0043] This step utilizes parallel deep neural networks to extract deep features from bimodal data at different scales. For example... Figure 2 As shown, the core of this module is a parallel dual-modal dilated convolutional neural network (Dilated CNN) architecture.
[0044] Specifically, a parallel bimodal dilated convolutional neural network was built using the PyTorch framework, corresponding to synchronized ECG and respiratory signal sequences of 1 minute, 3 minutes, and 5 minutes, respectively. For sequences of length... Synchronized ECG sequences and respiratory signal sequences Two different modal signals are input into a parallel dilated convolutional neural network with the same structure to form a dual-modal feature extraction architecture.
[0045] Inside a CNN network, the first step is through a dilated convolutional layer. The dilated convolutional layer passes through a convolutional kernel. Perform a sliding convolution operation on the input signal. The convolution operation formula is as follows:
[0046]
[0047] in, For expansion rate, This indicates the position of the output signal after convolution. The value, The kernel size is [size]. For the convolution kernel at position The weight value, For the input signal at position The value of . By stacking multiple convolutional layers, local waveform features at different levels can be extracted.
[0048] By stacking multiple dilated convolutional layers, local waveform features and global rhythmic patterns at different levels are extracted. Then, adaptive pooling replaces fixed max pooling, dynamically adjusting the pooling window size based on input features to reduce data dimensionality while preserving key features. After several dilated convolutional and adaptive pooling layers, the network output is connected to a fully connected layer. The fully connected layer uses a weight matrix... and bias vector The formula for mapping features to the target feature space is:
[0049]
[0050] in, The feature vector output by the fully connected layer. For activation function, This is the weight matrix of the fully connected layer. This is the feature vector output from the previous layer. This is the bias vector for the fully connected layer.
[0051] By adjusting the network parameters and training the neural network, two parallel neural network branches extract features from ECG sequences and respiratory signal sequences at corresponding time scales, respectively. and The extracted features are then projected onto the dimension through fully connected layers. The target feature space is used to concatenate the features of synchronized ECG sequences and respiratory signal sequences to form 256-dimensional cross-modal feature pairs (such as...). Ultimately, cross-modal feature pairs are formed. , , .
[0052] S3: A cross-scale dynamic weight correction attention mechanism is adopted to interact and fuse the cross-modal features at multiple scales. The cross-scale dynamic weight correction attention mechanism dynamically corrects the attention weights according to the vector differences between features at different scales, so as to adaptively aggregate the most discriminative information at each scale.
[0053] This is the core step of the invention, which specifically employs a cross-scale dynamic weight correction attention mechanism, aiming to adaptively fuse information from different scales.
[0054] Specifically, for the cross-modal characteristics of ECG sequences and respiratory signal sequences at three scales... , , (in , This generates a query, key, and value matrix for each scale feature. (The last part, "using feature pairs," appears to be an error and doesn't translate directly.) For example, using the weight matrix , , Perform a linear transformation to generate the corresponding matrix:
[0055]
[0056]
[0057]
[0058] in, , , feature pairs The generated query, key, and value matrix , , This is a learnable weight matrix. Feature pairs are generated in the same way. and feature pairs corresponding , , and , , matrix.
[0059] When calculating attention weights between features at different scales, Query For example, attention scores are calculated using dot products, while a cross-scale dynamic weight correction factor is introduced:
[0060]
[0061] in, for right Attention score The Euclidean distance between feature vectors is used to enhance the interaction weights of significantly different features through the ReLU function. Key matrix The attention score is normalized using the Softmax function to obtain the attention weights.
[0062]
[0063] in, for right The attention weight matrix. The attention weights are used to... Value matrix Perform a weighted summation to obtain From Additional information obtained:
[0064]
[0065] Similarly, calculate from Supplementary information obtained .Will The inherent characteristics are integrated with the acquired supplementary information:
[0066]
[0067] Through the above process, the following can be achieved. By query and It obtains supplementary information from keys and values, and through a soft alignment mechanism, achieves multi-scale feature interaction and fusion in the time and morphological dimensions. and Similar operations were performed to ultimately obtain the fused multi-scale features. .
[0068] S4: The fused features are input into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features.
[0069] This step efficiently compresses the fused features and performs the final classification.
[0070] Specifically, the dual-modal features output by the cross-scale dynamic weight correction attention mechanism module are... (1-minute scale) (3-minute scale) (On a 5-minute scale) Concatenation is performed along the sequence dimension to obtain concatenated features. (Total dimensions 768), where [;] represents the splicing operation along the sequence dimensions, which aims to preserve complementary information at different time scales.
[0071] It should also be noted that the original Q-Former (Query-based Transformer) module is typically used for feature compression and cross-modal interaction, and its core structure includes:
[0072] Learnable query vectors (Query): used to extract key information from input features;
[0073] Multi-Head Attention: Calculates the interaction weights between the query and the key and value to achieve feature fusion;
[0074] Dimensionality reduction output: Compress high-dimensional features to reduce computational load.
[0075] The original Q-Former module has certain limitations: the query vector only depends on learnable parameters and lacks dynamic adaptation to the characteristics of the input signal itself; it does not consider the entropy information of multi-scale features, which may affect the sensitivity to abnormal states (such as sleep apnea); and the cross-modal interaction mode is relatively fixed, which may not be able to fully explore the dynamic correlation between ECG and respiratory signals.
[0076] Therefore, this embodiment proposes an improved Q-Former module, the core improvements of which include:
[0077] 1. Introduction of auxiliary query vector: The entropy values of ECG and respiratory signal features at various scales are used as additional query vectors. )and ), and learnable query vectors The data are concatenated to form an enhanced query matrix. By quantifying the disorder of signal features using entropy values, the model's sensitivity to abnormal states (such as sleep apnea events) is enhanced, improving its ability to detect non-stationary signals.
[0078] 2. Cross-modal feature interaction optimization: In the improved Q-Former module's multi-head attention mechanism, entropy information from ECG and respiratory modalities is explicitly fused, and attention weight allocation is dynamically adjusted. This avoids the limitation of the original Q-Former module relying solely on learnable query vectors, and guides cross-modal information fusion through modality-specific features (entropy).
[0079] 3. Lightweight Compression Design: While preserving the correlation between multi-scale features, an attention mechanism is used to reduce the dimensionality of the high-dimensional stitched features (768 dimensions), thereby reducing the computational load. This adapts to the deployment requirements of embedded devices, achieving millisecond-level response times.
[0080] Therefore, the query vector of the original Q-Former module is usually fixed or learnable, while this scheme introduces the signal entropy value (reflecting the degree of signal disorder) as part of the query, which is an improvement for the non-stationary characteristics of ECG-respiratory signals.
[0081] Specifically, an improved Q-Former module is used to compress long sequence features, and the probability distribution entropy value of each scale feature is used as an auxiliary query vector to enhance sensitivity to abnormal states. The improved Q-Former module contains learnable query vectors. (N is the number of query vectors, (For the query vector dimension), attention mechanism is used to extract concatenated features. Extract key information from it. The specific process is as follows: [The text abruptly ends here, likely due to an incomplete sentence The input multi-head self-attention layer interacts with the query vector Q, calculates the attention weights, and sums them by weight to obtain the compressed features. The calculation logic is as follows:
[0082]
[0083]
[0084]
[0085] in, For learnable query vectors, These represent the characteristics of ECG sequences at different scales. These represent the characteristics of respiratory signal sequences at different scales. (•) is the function for calculating the entropy value of the characteristic probability distribution. These are the key matrix and the value matrix, respectively. , This is the weight matrix. The dimension of the key matrix is [value]. This operation reduces the computational load by decreasing the feature dimension while preserving key cross-scale association information.
[0086] Furthermore, the compressed features The input is a multilayer perceptron (MLP), which contains three linear layers, in the following order:
[0087] First linear layer: , used to introduce nonlinear transformations.
[0088] Second linear layer: The structure is similar to the first layer, and further abstract features are extracted.
[0089] Third linear layer (output layer): , The predicted probability distribution is mapped to the classification probability of "apnea" or "normal" using the Softmax function.
[0090] The above , and This is the weight matrix. , and For bias vectors, It is the ReLU activation function. and These are the outputs of the first linear layer and the second linear layer, respectively.
[0091] Finally, the above structure is implemented using the PyTorch framework, with the cross-entropy loss function. For supervised training, the loss function formula is:
[0092]
[0093] in, N For the sample size, For the number of categories, For the sample The true label (0 or 1). Samples predicted by the model Category The probability of.
[0094] Classification results combining ECG and respiratory signals:
[0095]
[0096] in, and Cross-entropy loss for ECG and respiratory signals, respectively.
[0097] In an optional embodiment, step S5 is also included: model training.
[0098] Model training utilizes the PyTorch framework to implement an end-to-end learning process, running on an NVIDIA GeForce RTX 4090 GPU for accelerated computation. The Adam optimizer is used to iteratively update network parameters, with the initial learning rate set to a reasonable range suitable for model convergence. The batch size is set to 128 to balance memory usage and gradient update stability. A dynamic learning rate adjustment strategy is implemented during training: by monitoring the validation set loss curve, when the loss value does not show a decreasing trend over multiple consecutive training epochs, a learning rate decay mechanism is automatically triggered, reducing the learning rate by a preset ratio to avoid the model getting stuck in local optima and accelerate the convergence process. In the training loop, preprocessed ECG and respiratory signal sequences are first input into the model. After feature extraction, cross-attention fusion, and classification, a predicted probability distribution is generated. Then, the difference between the predicted value and the true label is calculated using the cross-entropy loss function, and gradients are backpropagated to update the network parameters of each layer. The entire training process continues until the loss function converges and the validation set performance metrics stabilize, ensuring the model has good generalization ability while learning multi-scale feature associations.
[0099] In an optional embodiment, step S6 is also included: model evaluation and deployment.
[0100] A standardized process was established for the model evaluation phase to verify the effectiveness of multi-scale analysis. At the fragment level, the test set was divided into sample units at different time scales, which were then input into the trained model. By comparing the prediction results with expert-annotated labels, the contribution of feature representation to classification performance at each scale was analyzed. The evaluation process covered scenarios with different noise levels and individual physiological differences to verify the robustness of the model in real clinical settings.
[0101] The deployment phase focuses on clinical applicability, integrating the trained model into portable medical devices. The device acquires ECG and respiratory signals through a real-time acquisition module. After bandpass filtering, R-peak detection, and multi-scale segmentation by a preprocessing module, the embedded inference engine performs feature extraction, cross-attention fusion, and classification prediction. Finally, it generates real-time warning signals based on preset clinical thresholds. Model compression technology is used during deployment to optimize computational efficiency, ensuring millisecond-level response on low-power hardware platforms. Encrypted transmission protocols ensure the security of medical data during acquisition, processing, and transmission, providing reliable technical support for early screening and real-time monitoring of sleep apnea.
[0102] In summary, in this embodiment, the present invention proposes a sleep apnea detection method utilizing multi-scale feature extraction and cross-attention mechanism. This method focuses on the ECG-breathing bimodal detection task of sleep apnea and constructs an intelligent detection model framework driven by a cross-scale dynamic weight correction attention mechanism. It mainly includes six modules: ECG sleep apnea detection dataset construction (S1), multi-scale bimodal feature extraction module design (S2), cross-scale dynamic weight correction attention mechanism module design (S3), feature fusion and classification module design (S4), model training and optimization (S5), and model evaluation and deployment (S6).
[0103] In step S1, ECG and respiratory signals are simultaneously acquired based on the PhysioNet Apnea-ECG dataset. ECG signals are preprocessed by bandpass filtering from 3 to 45 Hz, and respiratory signals are processed by bandpass filtering from 0.1 to 1 Hz. The RR interval, R peak amplitude, respiratory amplitude and rate of change features are extracted to construct an ECG-respiratory dual-modality multi-scale dataset with diverse time dimensions.
[0104] In step S2, a parallel dilated convolutional neural network architecture is designed to process ECG and respiratory signal segments of 1 minute, 3 minutes, and 5 minutes in length, respectively. Local waveform features and global rhythm patterns are extracted through multi-layer dilated convolution and adaptive pooling. The dual-modal features are projected onto a 128-dimensional target feature space and spliced to form a 256-dimensional cross-modal feature pair.
[0105] In step S3, a dynamic weight correction factor based on Euclidean distance is introduced. Cross-scale attention weights are calculated through a learnable query-key-value transformation matrix to achieve spatiotemporal dynamic fusion and soft alignment enhancement of 1-minute high-resolution features and 3-minute and 5-minute long-range features.
[0106] In step S4, an improved Q-Former architecture is used to fuse three-scale features. The entropy values of each modality feature are used as auxiliary query vectors to enhance the sensitivity of anomaly detection. After dimensionality reduction through a multi-head attention mechanism, the data is input into a three-layer MLP classifier to predict the probability of sleep apnea.
[0107] In step S5, a dynamic training strategy supervised by bimodal cross-entropy loss is designed based on the Adam optimizer. The convergence process is optimized by adaptive adjustment of the learning rate driven by the validation set, and end-to-end training is achieved in the PyTorch framework.
[0108] In step S6, a clinically oriented assessment system is constructed to verify the effectiveness of multi-scale features at the fragment level and test robustness in noisy environments at the system level. Finally, embedded device deployment is achieved through model compression technology to complete real-time dual-modal signal acquisition, multi-scale analysis, and sleep apnea early warning functions.
[0109] Example 2
[0110] Please see Figure 3 The diagram shown is a schematic representation of a sleep apnea detection system according to a second embodiment of this application. The system includes the following key modules:
[0111] The dataset construction module 100 is used to acquire synchronously collected electrocardiogram (ECG) signals and respiratory signals, preprocess the ECG signals and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a dual-modal multi-scale dataset containing ECG sequences and respiratory signal sequences.
[0112] The parallel feature extraction module 200 is used to extract deep features of corresponding scales from the electrocardiogram sequence and the respiratory signal sequence respectively for the signal segments of the at least two different time scales using a parallel feature extraction network, and generate a cross-modal feature for each scale.
[0113] The cross-scale feature fusion module 300 is used to interact and fuse the cross-modal features of multiple scales by adopting a cross-scale dynamic weight correction attention mechanism. The cross-scale dynamic weight correction attention mechanism dynamically corrects the attention weights according to the vector differences between features of different scales, so as to adaptively aggregate the most discriminative information in each scale.
[0114] The compression classification module 400 is used to input the fused features into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features.
[0115] The sleep apnea detection system in this application embodiment can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. For example, mobile electronic devices can be mobile phones, tablets, laptops, PDAs, in-vehicle electronic devices, wearable devices, ultra-mobile personal computers (UMPCs), netbooks, or personal digital assistants (PDAs), etc., while non-mobile electronic devices can be servers, network-attached storage (NAS), personal computers (PCs), etc. This application embodiment does not impose specific limitations.
[0116] One embodiment of the sleep apnea detection system in this application can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application does not specifically limit the specific operating system used.
[0117] The sleep apnea detection system provided in this application embodiment can achieve... Figure 1 The various processes implemented in the method embodiment of the sleep apnea detection method are not described in detail here to avoid repetition.
[0118] Optionally, embodiments of this application also provide an electronic device, including a processor, a memory, and a program or instructions stored in the memory and executable on the processor. When the program or instructions are executed by the processor, they implement the various processes of the above-described embodiment of a sleep apnea detection method and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0119] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described embodiment of a sleep apnea detection method and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0120] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0121] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0122] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0123] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A sleep apnea detection system, characterized in that, include: A dataset construction module is used to acquire synchronously collected electrocardiogram (ECG) and respiratory signals, preprocess the ECG and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a bimodal multiscale dataset containing ECG and respiratory signal sequences; the at least two different preset time scales are 1 minute, 3 minutes, and 5 minutes; the preprocessing specifically includes: applying a 3-45Hz bandpass filter to the ECG signal and using the Hamiltonian algorithm to locate the R-peak to extract the RR interval and R-peak amplitude features; applying a 0.1-1Hz bandpass filter to the respiratory signal to extract the respiratory amplitude and the rate of change features calculated by numerical differentiation; The parallel feature extraction module is used to extract deep features of corresponding scales from the electrocardiogram sequence and the respiratory signal sequence respectively for the signal segments of the at least two different preset time scales using a parallel feature extraction network, and generate a cross-modal feature for each scale. A cross-scale feature fusion module is used to interact and fuse cross-modal features at multiple scales using a cross-scale dynamic weight correction attention mechanism. This mechanism dynamically adjusts attention weights based on vector differences between features at different scales to adaptively aggregate the most discriminative information from each scale. The implementation of this mechanism includes: generating query matrices, key matrices, and value matrices for the cross-modal features at different scales; introducing a correction factor based on the Euclidean distance between the feature vectors of the two scales when calculating the attention score between the query matrix at one scale and the key matrix at another scale, and processing the correction factor using the ReLU activation function to enhance the interaction weights for significantly different features; normalizing the attention score after superimposing the correction factor using the Softmax function to obtain the final attention weights, and then using these attention weights to perform a weighted summation of the corresponding value matrices to fuse cross-scale information. A compression classification module is used to input the fused features into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features. The compression classification module is an improved Q-Former module. The query vector of the improved Q-Former module is formed by concatenating a learnable query vector and an auxiliary query vector calculated from the feature entropy values of the electrocardiogram sequence and the respiratory signal sequence. The auxiliary query vector is used to enhance the model's sensitivity to the detection of abnormal signal states.
2. A method for processing physiological signals to assist in the identification of sleep apnea events, characterized in that, Includes the following steps: S1: Acquire synchronously collected electrocardiogram (ECG) and respiratory signals, preprocess the ECG and respiratory signals, and segment the preprocessed signals according to at least two different preset time scales to construct a dual-modal multi-scale dataset containing ECG and respiratory signal sequences; the at least two different preset time scales are 1 minute, 3 minutes, and 5 minutes; the preprocessing specifically includes: applying a 3-45Hz bandpass filter to the ECG signal and using the Hamiltonian algorithm to locate the R-peak to extract the RR interval and R-peak amplitude features; applying a 0.1-1Hz bandpass filter to the respiratory signal to extract the respiratory amplitude and the rate of change features calculated by numerical differentiation; S2: For the signal segments of the at least two different preset time scales, a parallel feature extraction network is used to extract deep features of the corresponding scales from the electrocardiogram sequence and the respiratory signal sequence, and a cross-modal feature is generated for each scale. S3: A cross-scale dynamic weight correction attention mechanism is adopted to interact and fuse the cross-modal features at multiple scales. The cross-scale dynamic weight correction attention mechanism dynamically corrects the attention weights based on the vector differences between features at different scales to adaptively aggregate the most discriminative information at each scale. The implementation of the cross-scale dynamic weight correction attention mechanism includes: generating query matrices, key matrices, and value matrices for the cross-modal features at different scales; when calculating the attention score between the query matrix at any scale and the key matrix at another scale, a correction factor based on the Euclidean distance between the feature vectors of the two scales is introduced, and the ReLU activation function is used to process the correction factor to enhance the interaction weights for significantly different features; the attention score after superimposing the correction factor is normalized using the Softmax function to obtain the final attention weights, and the attention weights are used to perform a weighted summation of the corresponding value matrices to fuse cross-scale information. S4: The fused features are input into a feature compression module for dimensionality reduction, and a classifier outputs a probability prediction of sleep apnea events based on the dimensionality-reduced features. The compression classification module is an improved Q-Former module. The query vector of the improved Q-Former module is formed by concatenating a learnable query vector and an auxiliary query vector calculated from the feature entropy values of the electrocardiogram sequence and the respiratory signal sequence. The auxiliary query vector is used to enhance the model's sensitivity to detecting abnormal signal states.
3. The method according to claim 2, characterized in that, In step S2, the parallel feature extraction network is a parallel bimodal dilated convolutional neural network; step S2 specifically includes: For each time scale, dilated convolutional network branches are set up for electrocardiogram sequences and respiratory signal sequences. The dilated convolutional network branches extract multi-level waveform and rhythm features through dilated convolutional layers with adjustable dilation rates and adaptive pooling layers. The features extracted from the ECG network branch and the respiratory signal network branch at each scale are projected onto a preset dimension and then stitched together to form the cross-modal features.
4. The method according to claim 2, characterized in that, In step S4, the feature compression module is an improved Q-Former module, and the classifier is a multilayer perceptron; step S4 specifically includes: Features from all scales, after fusion, are concatenated along the sequence dimension to form a high-dimensional concatenated feature. The high-dimensional concatenated features are input into the improved Q-Former module, which uses the query vector to perform multi-head attention interaction with the high-dimensional concatenated features to achieve feature compression and dimensionality reduction. The low-dimensional feature vector output by the improved Q-Former module is input into the multilayer perceptron for final classification.
5. The method according to claim 2, characterized in that, The method further includes a model training step, which employs the Adam optimizer and uses a bimodal cross-entropy loss function to train the model end-to-end; the bimodal cross-entropy loss function is a combination of classification loss based on electrocardiogram features and classification loss based on respiratory signal features.
6. An electronic device, characterized in that, The method includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein when the program or instructions are executed by the processor, they implement the steps of a method for processing physiological signals to assist in sleep apnea event identification as described in any one of claims 2-5.
7. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of a method for processing physiological signals to assist in sleep apnea event identification as described in any one of claims 2-5.
Citation Information
Patent Citations
Multi-scale respiratory event automatic positioning method and device based on bimodal feature learning
CN117503056A
Sleep apnea detection method based on multi-scale time convolution
CN118285812A
Cited By
Single-channel electroencephalogram sleep analysis method and related equipment
CN121971042A
A single-channel electroencephalogram sleep analysis method and related device
CN121971042B