A method for generating electrocardiogram based on diffusion model synthesis customizable cardiac cycle

By combining a deep generative model based on a diffusion model with ECG semantic labels and noise, a customizable ECG signal is generated, which solves the problems of data imbalance and poor privacy protection in existing technologies, achieves high-quality, customizable ECG generation, expands the scope of application and enhances privacy protection.

CN118948293BActive Publication Date: 2025-10-10HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)

Patent Information

Application Number
CN202411056546.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-02
Publication Date
2025-10-10
Estimated Expiration
2044-08-02

AI Technical Summary

Technical Problem

Existing ECG generation methods suffer from data imbalance, poor privacy protection, and inability to generate specific pathological signals. In particular, there are challenges in customization and synthesis of specific pathological signals.

Method used

A deep generative model based on a diffusion model is used to generate ECG signals by inputting ECG semantic labels and noise, combining an encoder, decoder, convolution module, and normalization module. The trained and optimized deep generative model is used to perform parameter optimization on the ECG dataset, and the ECG semantic labels are manually set to fine-tune the cardiac cycle phase to generate a customizable ECG.

Benefits of technology

It improves the clinical relevance and customizability of ECG generation, can accurately generate ECG signals under various cardiac conditions, enhances patient privacy protection, expands the application scope of ECG generation, and verifies the authenticity of the generated signal through the segmentation model, solving the problems of data scarcity and privacy protection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118948293B_ABST
    Figure CN118948293B_ABST
Patent Text Reader

Abstract

The application discloses a method for generating electrocardiogram based on a diffusion model and synthesizing a customizable cardiac cycle, relates to an electrocardiogram generation method, and aims at solving the problems of the existing electrocardiogram generation method, such as data imbalance, poor privacy protection and the incapability of generating specific pathological signals. The application takes electrocardiogram semantic labels as conditional input, simultaneously inputs noise and diffusion time steps into a deep generation model, and generates electrocardiogram; the deep generation model takes a diffusion model as an overall architecture, introduces a converter model to learn long-term dependencies in electrocardiogram signals, and simultaneously introduces a semantic electrocardiogram batch normalization module to accurately learn local ECG semantic features. The electrocardiogram signal generated by the application can accurately follow the provided electrocardiogram semantic information, customize electrocardiogram with real physiological significance, and improve the data imbalance problem and the privacy protection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for generating an electrocardiogram. Background Art

[0002] Cardiovascular disease is one of the major health challenges facing the world. Its impact on morbidity and mortality is significant, placing enormous pressure on public health and medical systems. Electrocardiogram (ECG), as a non-invasive, painless and easy-to-use technology for recording cardiac electrophysiological activity, has been widely used in the diagnosis and monitoring of heart disease. ECG signals are usually quasi-periodic, consisting of a series of repetitive heartbeats, including P waves, QRS complexes (including Q waves, R waves and S waves), T waves, and sometimes U waves. Doctors can evaluate cardiac function and diagnose cardiovascular disease by analyzing these waveform changes, but this method is limited by high costs and high specialization. In recent years, the development of artificial intelligence technology has significantly reduced the professional requirements and costs of ECG analysis, but this progress relies on large-scale datasets. Existing ECG databases still face problems of low data availability and data imbalance, which limits the application of deep learning technology in automated heart disease diagnosis, and establishing a complete large-scale ECG dataset is time-consuming and labor-intensive. Data augmentation through ECG generation is an effective solution to this problem. Some ECG signal generation methods mainly focus on simulating cardiac dynamics and cardiac mechanics, but these methods are costly and inefficient, making it difficult to generate diverse ECG signals on a large scale; ECG signals generated by signal processing and simple machine learning methods have limited variability and cannot ensure patient privacy; in recent years, deep learning has shown great potential in ECG signal generation, especially methods based on deep generative models, such as variational autoencoders and generative adversarial networks; these methods can generate high-quality samples, but still face the problems of mode collapse, training instability, and inability to generate clinically credible ECG signals; diffusion models have been applied to ECG generation in recent years, which can effectively capture the long-term dependencies of ECG data and generate clinically credible ECG signals that are stably trained; however, existing methods do not take into account detailed physiological characteristics and cardiac cycle conditions, and due to the scarcity of rare disease data, existing ECG generation methods still face many challenges in customization and synthesis of specific pathological signals; therefore, there is an urgent need for a solution that can overcome these shortcomings to further expand the application scope of synthetic ECG. Summary of the Invention

[0003] The purpose of the present invention is to solve the problems of data imbalance, poor privacy protection and inability to generate specific pathological signals in the electrocardiogram signals generated by existing electrocardiogram generation methods. An electrocardiogram generation method based on diffusion model synthesis with customizable cardiac cycles is proposed.

[0004] The present invention provides a method for generating an electrocardiogram (ECG) based on a diffusion model to synthesize a customizable cardiac cycle. The method comprises:

[0005] The ECG semantic label is input as the input sequence, and the noise and diffusion time step are input to the deep generative model to generate the ECG;

[0006] The deep generative model includes a converter model, an embedding layer, a third linear layer, a normalization module, a gate processing module, a first convolution module, a second convolution module and an adder;

[0007] The converter model includes an encoder and a decoder;

[0008] An encoder, used to encode the input noise to generate an encoded noise signal;

[0009] The embedding layer includes a first linear layer and a second linear layer;

[0010] The first linear layer and the second linear layer are used to encode the time information of the input diffusion time step and obtain the time step embedding vector;

[0011] The third linear layer is used to match the time step embedding vector to the same length as the encoded noise signal, and add it to the encoded noise signal element by element to fuse the time step information to obtain the noisy signal fused with the time embedding vector;

[0012] The first convolution module is used to apply a convolution layer to the noisy signal fused with the time embedding vector to change the number of channels and obtain a convolution-processed signal;

[0013] Normalization module, which is used to input the convolution processing signal and the semantic information label corresponding to the input ECG data, and output a vector embedded with semantic information;

[0014] A gated processing module is used to perform gated hyperbolic tangent nonlinear processing on the vector embedded with semantic information to obtain a gated processing signal;

[0015] The second convolution module is used to perform convolution processing on the gated processing signal, project the residual channel back to the original channel dimension, and obtain the output signal of the current layer;

[0016] An adder, configured to add the output signal of the current layer and the encoded noise signal element-wise to form a residual, and connect the residual as input to the next residual block to obtain predicted noise;

[0017] The decoder is used to obtain the denoised signal by using the predicted noise, and decode the denoised signal to generate an electrocardiogram.

[0018] Furthermore, the parameters of the deep generative model are determined through training optimization, and the specific optimization steps are:

[0019] Step 1: Divide the ECG dataset into a training set and a test set, annotate the ECG dataset, and generate an ECG semantic label corresponding to each ECG record based on the annotation results;

[0020] Step 2: Using the training set as input and the ECG semantic label as a condition, the parameters of the initial deep generative model are optimized to obtain the final deep generative model.

[0021] Furthermore, the specific method of dividing the electrocardiogram dataset in step 1 is: dividing it into a training set and a test set in a ratio of 7.5:2.5.

[0022] Furthermore, the specific method for annotating the electrocardiogram data set is: dividing each electrocardiogram record in the electrocardiogram data set into a P wave area, a T wave area, a QRS complex area and other partial areas; wherein the P wave area is marked as 1; the T wave area is marked as 2; the QRS complex area is marked as 3; and the other partial areas are marked as 0.

[0023] Furthermore, in step 2, before optimizing the parameters of the initial deep generative model, the training set and the ECG semantic labels are subjected to Hank processing; wherein each ECG record in the training set is denoted as X; and the ECG semantic label corresponding to each ECG record is denoted as Y;

[0024] The Hank conversion process is to convert the electrocardiogram record X in the training set into a two-dimensional Hank matrix x; and to convert the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hank matrix y.

[0025] Furthermore, the specific process of converting the electrocardiogram record X in the training set into a two-dimensional Hank matrix x is:

[0026] Each ECG record X in the training set is a one-dimensional sequence d of length N, denoted as X = {d1, d2, d3, ..., d N}; where d1 is the first element in the one-dimensional sequence d, d2 is the second element in the one-dimensional sequence d, d3 is the third element in the one-dimensional sequence d, and d N is the Nth element in the one-dimensional sequence d;

[0027] Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix x is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix x is represented by an element of the one-dimensional sequence d as:

[0028] x ij =di+j-1 , where 1≤i≤L, 1≤j≤K;

[0029] Therefore, we get the two-dimensional Hank matrix x:

[0030]

[0031] In the two-dimensional Hank matrix x, the elements on each anti-diagonal line are the same.

[0032] Furthermore, the specific process of converting the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hank matrix y is as follows:

[0033] The ECG semantic label Y corresponding to each ECG record is a one-dimensional sequence f of length N, denoted as Y = {f1,f2,f3,...,f N}; where f1 is the first element in the one-dimensional sequence f, f2 is the second element in the one-dimensional sequence f, f3 is the third element in the one-dimensional sequence f, and f N is the Nth element in the one-dimensional sequence f;

[0034] Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix y is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix y is represented by an element of the one-dimensional sequence f as:

[0035] y ij =f i+j-1 , where 1≤i≤L, 1≤j≤K;

[0036] Therefore, we get the two-dimensional Hank matrix y:

[0037]

[0038] In the two-dimensional Hank matrix y, the elements on each anti-diagonal line are the same.

[0039] Furthermore, the specific method for optimizing the parameters of the initial deep generative model in step 2 is:

[0040] Step (1), for the two-dimensional Hank matrix x, from noise-free x0 to pure Gaussian noise x T , generate multiple noise signals x t ; Among them, α t is the scaling factor at each time step t in the forward process of the diffusion model; t is the diffusion time step; β is the diffusion rate;

[0041] Step (2): For each corresponding diffusion time step t, the time information is encoded through the time embedding layer; the output of the time embedding layer is obtained by transforming the formula 1; the formula 1 is:

[0042] TE=Swish(Linear2(Swish(Linear1(TimeEmbed(t))))) Formula 1

[0043] Where TimeEmbed is the time embedding layer; Linear1 is the first linear layer; Linear2 is the second linear layer; TE is the time step embedding vector; Swish(·) is the first activation function, which is defined as:

[0044] Step (3): Use the encoder to input the noise signal x t Encode and generate the encoded noise signal x′ t ;

[0045] Step (4): The time step embedding vector TE is matched to the encoded noise signal x′ through the third linear layer. t The same length as the encoded noise signal x′ t Add element by element to fuse the time step information; get the noisy signal z that fuses the time embedding vector t ;

[0046] z t =x′ t +Linear3(TE)

[0047] Among them, Linear3 is the third linear layer;

[0048] Step (5) is to obtain the noisy signal z fused with the time embedding vector t Apply the convolution layer to change the number of channels and obtain the convolution processing signal z′ t ;

[0049] z′ t =Conv1D(z t )

[0050] Among them, Conv1D is the convolution operator symbol;

[0051] Step (6): convolution processing signal z′ t The semantic information label y corresponding to the ECG in the training set after Hank processing is passed to the normalization module, and the normalization module outputs the vector z″ embedded with semantic information t ;

[0052] Step (7), the normalization module outputs the vector z″ embedded with semantic information tAfter gated hyperbolic tangent nonlinear processing, the gated processing signal is obtained

[0053]

[0054] Among them, tanh(·) is the second activation function, σ(·) is the third activation function,

[0055] Step (8), gated processing signal The residual channel is projected back to the original channel dimension through the convolution layer to obtain the output signal of the current layer

[0056] Step (9): the output signal of the current layer and the processed noise signal x′ generated in step (3) t Add element-wise to form the residual residual Connected to the next residual block as input;

[0057] in:

[0058] Step (10), after passing through multiple layers of residual blocks, the features transferred from different residual blocks are fused element by element through skip connections to obtain a prediction noise ∈ θ (x t ,t), where θ is the diffusion model parameter; the training goal is to minimize the loss function, that is, to minimize the mean square error between the predicted noise and the real noise; the specific calculation formula of the training goal is:

[0059]

[0060] in, is the loss function, ∈ is the real noise; x0~D represents the noise-free x0 sampled from the training data distribution D; represents the real noise ∈ sampled from a standard normal distribution with mean 0 and variance 1; t~U(1,T) represents the time step t sampled from the uniform distribution U(1,T);

[0061] Step (11) uses back propagation and gradient descent algorithms to optimize the diffusion model parameters θ to obtain the final deep generative model.

[0062] Furthermore, the specific formula for the decoder to obtain the denoised signal using the predicted noise is:

[0063]

[0064] Among them, α tis a scaling factor for each time step t in the diffusion process, is the cumulative product of the alpha parameters from time step 1 to time step t, s is a cumulative product variable; sigma t is the coefficient of random noise introduced in the denoising process.

[0065] Further, the specific calculation formula of the training target in step (10) is obtained by the following method:

[0066] The diffusion model includes two processes: a forward process and a reverse process;

[0067] In the forward process, the diffusion model gradually introduces noise in the form of a Markov chain, and the parameterization formula of this process is as follows:

[0068]

[0069] where x0 is the original data sample without noise interference, and x T is the data after T times of noise introduction steps, and T is the diffusion step number; the specific noise introduction formula is as follows: where beta t is the noise variance of the forward process; is a normal distribution; I represents an identity matrix; and x t is expressed as follows:

[0070]

[0071] In the reverse process, the diffusion model gradually removes noise to reconstruct the original data from the given data sample; the specific reconstruction process is as follows: the model is trained using an objective function; and the parameterization formula of the reverse process is as follows:

[0072]

[0073] where x T obeys a standard normal distribution; and the loss function is used to train the neural network in the reverse process, so that the neural network can obtain the predicted noise epsilon t (x θ ,t) under the condition of a given diffusion time step t and a current noise signal x t , and thus the specific calculation formula of the training target is as follows:

[0074]

[0075] Compared with the prior art, the present application has the following beneficial effects:

[0076] The present invention uses a deep generative model based on a diffusion model to synthesize customizable biomedical ECG signals. By embedding ECG semantic information (including the positions of P waves, QRS waves, and T waves), the ECG generation method effectively improves the clinical relevance of the model. The ECG generation method is a method that incorporates key cardiac information such as cardiac cycle phase and waveform position into the conditional labels of the deep generative model. Unlike previous ECG generation methods, the ECG generation method can manually set the ECG semantic labels when annotating the ECG dataset and generating the ECG semantic labels corresponding to each ECG record based on the annotation results. Manually setting the ECG semantic labels allows fine-tuning of the cardiac cycle phase and accurately generates ECG signals under various cardiac conditions, thereby achieving higher customizability. This advancement effectively expands the application scope of synthetic ECGs, further strengthens patient privacy protection, and promotes the development of personalized medicine. The generation method described in the present invention can synthesize ECG signals that accurately follow the real cardiac cycle information and outperforms existing methods in terms of quality and authenticity. By calculating distance-based and correlation-based indicators, the quality of the customized ECG model is quantitatively analyzed from different perspectives. In addition, the authenticity evaluation of the ECG generation method also includes using a segmentation model to verify whether the generated ECG waveform accurately follows the provided cardiac cycle information and can effectively replace the real signal in training. The results show that the ECG generation method can not only accurately customize the cardiac cycle phase, but also has obvious advantages in generating ECGs. The ECG generation method described in the present invention can synthesize ECG signals that accurately follow the real cardiac cycle information and outperform existing methods in terms of quality and authenticity. The generation method can generate accurate and interpretable ECG waveforms under various cardiac conditions such as different heart rates and QTc intervals, which highlights its potential in clinical relevance. By modulating the cardiac cycle phase and generating ECGs under rare physiological conditions, it addresses the major challenges of data scarcity and patient privacy. By synthesizing tailored ECG signals, deep generative models provide valuable tools for medical research and applications. Therefore, the ECG signals generated by the ECG generation method described in the present invention are data-balanced and privacy-protected. At the same time, the ECG generation method can generate specific pathological signals. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] Figure 1 This is a schematic diagram of the specific structure of the deep generative model described in the first embodiment;

[0078] Figure 2 Schematic diagram of parameter optimization process of deep generative model in specific implementation method 2;

[0079] Figure 3 Schematic diagram of the structure of the normalization module in the eighth specific implementation mode;

[0080] Figure 4 It is a schematic diagram of the directed graph structure of the diffusion model in the tenth specific implementation method. DETAILED DESCRIPTION

[0081] Specific implementation method 1. Combination Figure 1 This embodiment describes a method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle. The electrocardiogram generation method is as follows:

[0082] The ECG semantic label is input as the input sequence, and the noise and diffusion time step are input to the deep generative model to generate the ECG;

[0083] The deep generative model includes a converter model, an embedding layer, a third linear layer, a normalization module, a gate processing module, a first convolution module, a second convolution module and an adder;

[0084] The converter model includes an encoder and a decoder;

[0085] An encoder, used to encode the input noise to generate an encoded noise signal;

[0086] The embedding layer includes a first linear layer and a second linear layer;

[0087] The first linear layer and the second linear layer are used to encode the time information of the input diffusion time step and obtain the time step embedding vector;

[0088] The third linear layer is used to match the time step embedding vector to the same length as the encoded noise signal, and add it to the encoded noise signal element by element to fuse the time step information to obtain the noisy signal fused with the time embedding vector;

[0089] The first convolution module is used to apply a convolution layer to the noisy signal fused with the time embedding vector to change the number of channels and obtain a convolution-processed signal;

[0090] Normalization module, which is used to input the convolution processing signal and the semantic information label corresponding to the input ECG data, and output a vector embedded with semantic information;

[0091] A gated processing module is used to perform gated hyperbolic tangent nonlinear processing on the vector embedded with semantic information to obtain a gated processing signal;

[0092] The second convolution module is used to perform convolution processing on the gated processing signal, project the residual channel back to the original channel dimension, and obtain the output signal of the current layer;

[0093] An adder, configured to add the output signal of the current layer and the encoded noise signal element-wise to form a residual, and connect the residual as input to the next residual block to obtain predicted noise;

[0094] The decoder is used to obtain the denoised signal by using the predicted noise, and decode the denoised signal to generate an electrocardiogram.

[0095] In this embodiment, if Figure 1 As shown in the figure, the specific structure of the resulting deep generative model is given. The deep generative model uses a diffusion model as its overall architecture and introduces a transformer model to learn long-term dependencies in ECG signals. At the same time, a semantic electrocardiogram batch normalization module (SEBN) is introduced to accurately learn local ECG semantic features. The transformer model consists of two parts: an encoder and a decoder. The encoder is used to process the input sequence, and the decoder is used to generate the output sequence. The encoder uses a multi-head self-attention mechanism to enable the model to focus on different positions in the input sequence. A feedforward neural network is then applied independently to each position. Each sub-layer is followed by a residual connection and layer normalization. To prevent overfitting, a dropout layer is added between the sub-layer and the feedforward network. The decoder has a similar structure to the encoder, where the self-attention mechanism uses a mask to block future positions. The input of the encoder-decoder attention mechanism is the decoder's self-attention output and the encoder's output.

[0096] The ECG generation method is the first method to incorporate key cardiac information such as cardiac cycle phase and waveform position into the conditional labels of a deep generative model. Unlike previous ECG generation methods, this ECG generation method can manually set the ECG semantic labels corresponding to each ECG record when annotating the ECG dataset and generating them based on the annotation results. Manually setting the ECG semantic labels allows fine-tuning of the cardiac cycle phase and accurately generates ECG signals under various cardiac conditions, thereby achieving higher customizability. This advancement effectively expands the application scope of synthetic ECGs, further strengthens patient privacy protection, and promotes the development of personalized medicine. The generation method described in the present invention can synthesize ECG signals that accurately follow the real cardiac cycle information, and is superior to existing methods in terms of quality and authenticity. By calculating distance-based and correlation-based indicators, the quality of the customized ECG model is quantitatively analyzed from different perspectives. In addition, the authenticity evaluation of the ECG generation method also includes using a segmentation model to verify whether the generated ECG waveform accurately follows the provided cardiac cycle information and can effectively replace the real signal in training; the results show that the ECG generation method can not only accurately customize the cardiac cycle phase, but also has obvious advantages in generating ECGs. The ECG generation method described in the present invention can synthesize ECG signals that accurately follow the real cardiac cycle information and outperform existing methods in terms of quality and authenticity; the generation method can generate accurate and interpretable ECG waveforms under various cardiac conditions such as different heart rates and QTc intervals, which highlights its clinical relevance; by modulating the cardiac cycle phase and generating ECGs under rare physiological conditions, it solves the major challenges of data scarcity and patient privacy; by synthesizing tailored ECG signals, deep generative models provide valuable tools for medical research and applications. Therefore, the ECG signals generated by the ECG generation method described in the present invention are data-balanced and privacy-protected, and the ECG generation method can also generate specific pathological signals.

[0097] Specific implementation method 2: Figure 2 This embodiment further defines the method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle described in the first embodiment. In this embodiment, the parameters of the deep generative model are determined through training optimization. The specific optimization steps are as follows:

[0098] Step 1: Divide the ECG dataset into a training set and a test set, annotate the ECG dataset, and generate an ECG semantic label corresponding to each ECG record based on the annotation results;

[0099] Step 2: Using the training set as input and the ECG semantic label as a condition, the parameters of the initial deep generative model are optimized to obtain the final deep generative model.

[0100] In the embodiment, the training set and the electrocardiogram semantic label are taken as the input and the condition, the parameters of the initial deep generation model are optimized through step-by-step noise training, and the final deep generation model is generated.

[0101] Specific embodiment three, the embodiment is a further limitation of the electrocardiogram generation method based on the diffusion model to synthesize the customizable cardiac cycle according to the second specific embodiment. In the embodiment, the specific method for dividing the electrocardiogram data set in step one is: dividing into a training set and a test set according to a ratio of 7.5:2.5.

[0102] In the embodiment, the training set and the test set are divided according to the above-mentioned ratio, which not only meets the purpose of training the deep generation model, but also enables the deep generation model to output the customizable ECG with real physiological significance when the test set and the electrocardiogram semantic label corresponding to each electrocardiogram record are input into the obtained deep generation model.

[0103] Specific embodiment four, the embodiment is a further limitation of the electrocardiogram generation method based on the diffusion model to synthesize the customizable cardiac cycle according to the second specific embodiment. In the embodiment, the specific method for annotating the electrocardiogram data set is: dividing each electrocardiogram record in the electrocardiogram data set into a P-wave region, a T-wave region, a QRS complex region, and other partial regions; wherein the P-wave region is marked as 1; the T-wave region is marked as 2; the QRS complex region is marked as 3; and the other partial regions are marked as 0.

[0104] In the embodiment, each electrocardiogram record in the electrocardiogram data set is reasonably annotated, and then participates in the training of the diffusion model, thereby enhancing the physiological significance of the ECG signal generated by the deep generation model.

[0105] Specific embodiment five, the embodiment is a further limitation of the electrocardiogram generation method based on the diffusion model to synthesize the customizable cardiac cycle according to the second specific embodiment. In the embodiment, the training set and the electrocardiogram semantic label are Hankelized before the parameters of the initial deep generation model are optimized in step two; wherein each electrocardiogram record in the training set is denoted as X; and the electrocardiogram semantic label corresponding to each electrocardiogram record is denoted as Y.

[0106] The Hankelization processing is to convert the electrocardiogram record X in the training set into a two-dimensional Hankel matrix x; and convert the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hankel matrix y.

[0107] In this embodiment, the one-dimensional ECG signal and the ECG semantic label corresponding to each ECG record are converted into a two-dimensional matrix form using the Hankelization method, thereby enhancing the model's ability to learn the semantic information of the ECG signal.

[0108] Specific embodiment 6: This embodiment further limits the method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle described in specific embodiment 5. In this embodiment, the specific process of converting the electrocardiogram record X in the training set into a two-dimensional Hank matrix x is as follows:

[0109] Each ECG record X in the training set is a one-dimensional sequence d of length N, denoted as X = {d1, d2, d3, ..., d N}; where d1 is the first element in the one-dimensional sequence d, d2 is the second element in the one-dimensional sequence d, d3 is the third element in the one-dimensional sequence d, and d N is the Nth element in the one-dimensional sequence d;

[0110] Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix x is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix x is represented by an element of the one-dimensional sequence d as:

[0111] x ij =d i+j-1 , where 1≤i≤L, 1≤j≤K;

[0112] Therefore, we get the two-dimensional Hank matrix x:

[0113]

[0114] In the two-dimensional Hank matrix x, the elements on each anti-diagonal line are the same.

[0115] In this embodiment, the electrocardiogram record X is Hank-ized in this way, so that it becomes a two-dimensional Hank matrix x, so as to facilitate the next step of diffusion model training and signal generation.

[0116] Specific embodiment 7. This embodiment further defines the method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle described in specific embodiment 6. In this embodiment, the specific process of converting the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hank matrix y is as follows:

[0117] The ECG semantic label Y corresponding to each ECG record is a one-dimensional sequence f of length N, denoted as Y = {f1,f2,f3,...,f N}; where f1 is the first element in the one-dimensional sequence f, f2 is the second element in the one-dimensional sequence f, f3 is the third element in the one-dimensional sequence f, and f N is the Nth element in the one-dimensional sequence f;

[0118] Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix y is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix y is represented by an element of the one-dimensional sequence f as:

[0119] y ij =f i+j-1 , where 1≤i≤L, 1≤j≤K;

[0120] Therefore, we get the two-dimensional Hank matrix y:

[0121]

[0122] In the two-dimensional Hank matrix y, the elements on each anti-diagonal line are the same.

[0123] In this embodiment, the ECG semantic label Y corresponding to each ECG record is Hank-ized in this way, so that it becomes a two-dimensional Hank matrix y for the next step of diffusion model training and signal generation.

[0124] Specific implementation method 8. Combination Figure 3 This embodiment further defines the method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle described in the seventh embodiment. In this embodiment, the specific method for obtaining the deep generative model in step 2 is as follows:

[0125] Step (1), for the two-dimensional Hank matrix x, from noise-free x0 to pure Gaussian noise x T , generate multiple noise signals x t ; Among them, α t is the scaling factor at each time step t in the forward process of the diffusion model; t is the diffusion time step; β is the diffusion rate;

[0126] Step (2): For each corresponding diffusion time step t, the time information is encoded through the time embedding layer; the output of the time embedding layer is obtained by transforming the formula 1; the formula 1 is:

[0127] TE=Swish(Linear2(Swish(Linear1(TimeEmbed(t))))) Formula 1

[0128] wherein TimeEmbed is a time embedding layer; Linear1 is a first linear layer; Linear2 is a second linear layer; TE is a high-dimensional time step embedding vector; Swish(·) is a first activation function defined as:

[0129] Step (3), encoding the input noise signal x t using the converter model to generate the encoded noise signal x' t ;

[0130] Step (4), matching the high-dimensional time step embedding vector TE to the same length as the encoded noise signal x' t through a third linear layer, and adding the encoded noise signal x' t element by element to fuse the time step information; obtaining a noise signal z t fused with the time embedding vector;

[0131] z t = x' t + Linear3(TE)

[0132] wherein Linear3 is a third linear layer;

[0133] Step (5), applying a convolution layer to change the number of channels to obtain a first convolution processing signal z' t ;

[0134] z' t = Conv1D(z t )

[0135] wherein Conv1D is a convolution operator;

[0136] Step (6), inputting the convolution processing signal z' t and the semantic information label y corresponding to the electrocardiogram in the Hankel processing training set into the normalization module, and the normalization module outputs a vector z" t embedding semantic information; so that the deep generation model can adapt to the input semantic content and spatial layout;

[0137] Step (7), the normalization module outputs a vector z" t embedding semantic information, and the vector z t embedding semantic information is subjected to a gated hyperbolic tangent nonlinear processing to obtain a gate processing signal

[0138]

[0139] wherein tanh(·) is a second activation function, σ(·) is the third activation function,

[0140] Step (8), gated processing signal The residual channel is projected back to the original channel dimension through the convolution layer to obtain the output signal of the current layer

[0141] Step (9): the output signal of the current layer and the processed noise signal x generated in step (3) t 'Add element by element to form the residual residuals Connected to the next residual block as input; alleviates the gradient vanishing problem and helps the model train deeper networks;

[0142] in:

[0143] Step (10), after passing through multiple layers of residual blocks, the features transferred from different residual blocks are fused element by element through skip connections to obtain a prediction noise ∈ θ (x t ,t), where θ is the diffusion model parameter; the training goal is to minimize the loss function, that is, to minimize the mean square error between the predicted noise and the real noise; the specific calculation formula of the training goal is:

[0144]

[0145] in, is the loss function, ∈ is the real noise; x0~D represents the noise-free x0 sampled from the training data distribution D; represents the real noise ∈ sampled from a standard normal distribution with mean 0 and variance 1; t~U(1,T) represents the time step t sampled from the uniform distribution U(1,T);

[0146] Step (11) uses back propagation and gradient descent algorithms to optimize the diffusion model parameters θ, and finally obtains a deep generative model.

[0147] In this embodiment, the specific structure of the normalization module is as follows: Figure 3As shown in the figure, the normalization module learns the P wave, QRS complex, and T wave information in the electrocardiogram signal by adjusting the normalization parameters, thereby enhancing the physiological significance of the generated ECG signal. First, the normalization module projects the input Hankelized ECG semantic information mask into an embedding space, and generates a first modulation parameter γ and a second modulation parameter δ with spatial awareness through a convolution operation; the generated first modulation parameter γ and second modulation parameter δ tensor are element-wise multiplied and added with the normalized activation value. This operation enhances the spatial details and contextual information in the output; the formula is as follows:

[0148] z″ t =γ·z norm +δ

[0149] Among them, z norm is the normalized activation value, z″ t is the output of the normalization module.

[0150] By adaptively adjusting the normalization parameters, the normalization module enables the deep generative model to adapt to the semantic content and spatial layout of the input. This adaptability improves the realism and accuracy of the generated ECG signal. The design of the normalization module enables the deep generative model to finely control each phase of the cardiac cycle and synthesize ECG signals with specific cardiac information. This feature greatly enhances the performance of the deep generative model in ECG generation tasks, allowing it to provide physiologically meaningful ECG signals, enhance fine-grained control over different cardiac cycle phases, effectively improve the realism and accuracy of the generated signal, and make the output of the deep generative model more consistent with clinical practice.

[0151] Specific embodiment 9: This embodiment further limits the electrocardiogram generation method based on the diffusion model synthesis of customizable cardiac cycles described in specific embodiment 8. In this embodiment, the specific formula for the decoder to obtain the denoised signal using the predicted noise is:

[0152]

[0153] Among them, α t is the scaling factor at each time step t during the diffusion process, is the cumulative product of the α parameters from time step 1 to time step t, s is the cumulative product variable; σ t is the coefficient of random noise introduced during the denoising process.

[0154] In this embodiment, the denoised signal output by the decoder is de-Hankeled to complete the generation of the ECG. By de-Hankeling the output, the generated two-dimensional matrix is ​​converted into a one-dimensional synthetic ECG signal that accurately follows the semantic information of the test set ECG label and has real physiological significance. De-Hankelization is the inverse process of Hankelization, which restores the Hankel matrix to its original data form.

[0155] Specific implementation method 10. Combination Figure 4 This embodiment further defines the electrocardiogram generation method based on a diffusion model to synthesize a customizable cardiac cycle described in Specific Embodiment 6. In this embodiment, the specific calculation formula of the training target in step (10) is obtained by the following method:

[0156] The diffusion model includes two processes: forward process and reverse process;

[0157] In the forward process, the diffusion model gradually introduces noise in the manner of a Markov chain. The parameterization formula of this process is as follows:

[0158]

[0159] Among them, the noise-free x0 is the original data sample without noise interference, and the pure Gaussian noise x T is the data after T noise addition steps, where T is the number of diffusion steps; the specific noise introduction formula is: Among them, β t is the noise variance of the forward process; is a normal distribution; I represents the identity matrix; x t Use the following formula:

[0160]

[0161] In the reverse process, the diffusion model gradually removes noise and reconstructs the original data from the given data sample. The specific reconstruction process is: the model is trained using the objective function. The parameterization formula of the reverse process is as follows:

[0162]

[0163] Among them, x T Obey the standard normal distribution; loss function It is used to train the neural network in the reverse process so that the neural network can be used to train the neural network in the given diffusion time step t and the current noise signal x. t The prediction noise ∈ θ (x t,t), the specific calculation formula of the training target is as follows:

[0164]

[0165] In this embodiment, the diffusion model includes two processes: a forward process and a reverse process, such as Figure 4 As shown in Figure 2, in the forward process, the diffusion model gradually introduces noise in a Markovian manner. In contrast, in the reverse process, the diffusion model gradually removes noise to reconstruct the original data from the given data sample.

[0166] The following is a detailed description of the technical effects of the present invention:

[0167] Embodiment 1:

[0168] 1. Preprocessing: The open ECG dataset QT database in PhysioNet was selected, which contains 105 15-minute dual-channel ECG records sampled at 250Hz; ECG experts annotated the start, peak, and end of the P wave, QRS complex, and T wave of each record. Semantic information labels are generated for each ECG record based on the annotations, that is, the P wave area is marked as 1, the QRS complex is marked as 3, the T wave is marked as 2, and the other parts are marked as 0. The data is downsampled to 125Hz and divided into sample segments with 500 sampling points. The dataset is divided into training and test sets in a ratio of 7.5:2.5, with 17,379 and 5,757 ECG segments respectively, which are used for model training and test generation of ECGs. Each ECG record and label is a one-dimensional sequence of length N=500. The ECG record X is denoted as: X={d1,d2,d3,...,d 500}; ECG semantic label Y is recorded as: Y = {f1,f2,f3,...,f 500}; Then, perform Hank processing on the ECG record X and the ECG semantic label Y. The ECG record X in the training set is converted into a two-dimensional Hank matrix x; and the ECG semantic label Y corresponding to each ECG record is converted into a two-dimensional Hank matrix y. Select a window length L = 201, and the size of the two-dimensional Hank matrix x and the two-dimensional Hank matrix y will both be L × K, where K = N - L + 1 = 300. The two-dimensional Hank matrix x and the two-dimensional Hank matrix y are obtained:

[0169]

[0170]

[0171] The elements on each anti-diagonal line in the two-dimensional Hank matrix x and the two-dimensional Hank matrix y are the same. In this way, the raw data and labels are pre-processed and Hankified for the next step of diffusion model training and signal generation.

[0172] 2. Model training: The Hank-processed training set signals and labels are used as input and conditions, and the deep generative model is trained by gradually adding noise.

[0173] The specific deep generative model training process is as follows:

[0174] (1) Step (1), for the two-dimensional Hank matrix x, from noise-free x0 to pure Gaussian noise x T , generate multiple noise signals x t ; Among them, α t is the scaling factor at each time step t in the forward process of the diffusion model; t is the diffusion time step; β is the diffusion rate; specifically, 600 diffusion time steps were used, and the β value was 0.0001 to 0.02.

[0175] Step (2): For each corresponding diffusion time step t, the time information is encoded through the time embedding layer; the output of the time embedding layer is obtained by transforming the equation 1; the model includes three stages of diffusion embedding, with dimensions of 128, 201, and 201 respectively; the equation 1 is:

[0176] TE=Swish(Linear2(Swish(Linear1(TimeEmbed(t))))) Formula 1

[0177] Where TimeEmbed is the time embedding layer; Linear1 is the first linear layer; Linear2 is the second linear layer; TE is the high-dimensional time step embedding vector; Swish(·) is the first activation function, which is defined as:

[0178] Step (3): input noise signal x t Apply the converter model to generate the processed noise signal x′ t Specifically, the converter model includes 5 attention heads, a feedforward network with 2048 hidden units, a dropout probability of 0.1, and a 5-layer stacking structure.

[0179] Step (4) matches the high-dimensional time step embedding vector TE to the processed noise signal x′ through the third linear layer t The same length and the processed noise signal x′ tAdd element by element to fuse the time step information; get the noisy signal z that fuses the time embedding vector t ;

[0180] z t =x′ t +Linear3(TE)

[0181] Among them, Linear3 is the third linear layer;

[0182] Step (5) is to obtain the noisy signal z fused with the time embedding vector t Apply the convolution layer to change the number of channels and obtain the convolution processing signal z′ t ;

[0183] z′ t =Conv1D(z t )

[0184] Among them, Conv1D is the convolution operator symbol;

[0185] Step (6): convolution processing signal z′ t The semantic information label y corresponding to the ECG in the training set after Hank processing is passed to the normalization module, and the normalization module outputs the vector z″ embedded with semantic information t ;

[0186] Step (7), the normalization module outputs the vector z″ embedded with semantic information t After gated hyperbolic tangent nonlinear processing, the gated processing signal is obtained

[0187]

[0188] Among them, tanh(·) is the second activation function, σ(·) is the third activation function,

[0189] Step (8), gated processing signal The residual channel is projected back to the original channel dimension through the convolution layer to obtain the output signal of the current layer

[0190] Step (9): the output signal of the current layer and the processed noise signal x′ generated in step (3) t Add element-wise to form the residual residuals Connected as input to the next residual block; the specific deep generation model has 36 residual layers and 201 residual and skip channels;

[0191] in:

[0192] Step (10), after passing through multiple layers of residual blocks, the features transferred from different residual blocks are fused element by element through skip connections to obtain a prediction noise ∈ θ (x t ,t), where θ is the diffusion model parameter; the training goal is to minimize the loss function, that is, to minimize the mean square error between the predicted noise and the real noise; the specific calculation formula of the training goal is:

[0193]

[0194] in, is the loss function, ∈ is the real noise; x0~D represents the noise-free x0 sampled from the training data distribution D; represents the real noise ∈ sampled from a standard normal distribution with mean 0 and variance 1; t~U(1,T) represents the time step t sampled from the uniform distribution U(1,T);

[0195] Step (11) uses back propagation and gradient descent algorithms to optimize the diffusion model parameters θ, and finally obtains a deep generative model; specifically, the learning rate of the Adam optimizer is 2×10 -4 .

[0196] 3. Signal generation:

[0197] Step 3. Generate pure Gaussian noise x with the same size as the noise-free x0 T , remove noise step by step from diffusion time step T to 1;

[0198] Step 3.2: The current noise signal x t Combined with the corresponding diffusion time step t, we can get the noisy signal z that is fused with the time embedding vector t , and the semantic information label y corresponding to the ECG in the test set after Hank processing, the model predicts the noise ∈ θ (x t ,t), calculate the denoised signal x using the predicted noise t-1

[0199]

[0200] Among them, α t is the scaling factor at each time step t during the diffusion process, is the cumulative product of the α parameters from time step 1 to time step t, s is the cumulative product variable; σ t is the coefficient of random noise introduced in the denoising process;

[0201] Step 3. Obtain the final denoised output through the converter model, and perform de-Hanker processing on the denoised output to generate an electrocardiogram.

[0202] Quality Evaluation: To comprehensively assess the quality of synthesized ECGs, the proposed final deep generative model was quantitatively evaluated. Commonly used distance and correlation-based metrics, including Maximum Mean Difference (MMD) and Pearson Correlation Coefficient (PC), were used to comprehensively evaluate the performance of the ECGs generated by the model from different perspectives and dimensions.

[0203] The Maximum Mean Difference (MMD) measures the difference between two data distributions. It calculates the maximum difference in the means of these distributions in a specific feature space, and its formula is as follows:

[0204]

[0205] Among them, the Gaussian kernel function Smaller MMD values ​​indicate greater similarity in the distributions.

[0206] The Pearson correlation coefficient (PC) measures the linear correlation between two variables, with a value range between -1 and 1. Its formula is:

[0207]

[0208] Among them, x i and y i represent the data points of synthetic and real signals respectively, and is their mean. The closer the PC value is to 1, the stronger the correlation.

[0209] This ECG generation method uses the test set labels to generate synthetic ECGs and compares them with the corresponding real ECGs. The average of all similarity results is used as the final evaluation result. Before calculating the metric, the synthetic and real ECGs are normalized to eliminate the influence of amplitude differences and accurately reflect morphological similarity. The results are shown in Table 1.

[0210]

[0211] The results show that the deep generative model used in this paper performs well in terms of distance and correlation metrics, demonstrating its superior ability to generate physiologically meaningful ECG signals adapted to the cardiac cycle. For MMD, the value of the deep generative model is 9.33×10 -3This indicates that the model more accurately captures the data distribution. When evaluating PC, the correlation coefficient of the model reaches 0.7357, indicating that the model is close to the true signal in morphological correlation. This highlights the excellent ability of the invented model to learn ECG semantic information and customize the cardiac cycle.

[0212] Realism evaluation: To verify whether the generated ECG waveform accurately follows the provided cardiac cycle information, a realism evaluation is conducted in two parts. First, the segmentation model trained on the real signal is used to segment the generated signal, and the segmentation prediction is compared with the P, QRS and T segment positions generated by the guide signal. High matching degree indicates that the generated ECG signal accurately follows the provided instructions. Second, a segmentation model is trained using the generated signal and the real segment position as labels, and then the real signal is segmented using this model, and the prediction result is compared with the real label. If the prediction result is close to the real label, it means that the generated signal can effectively train the model for real signal segmentation. The segmentation effectiveness evaluation results are shown in Table 2.

[0213]

[0214] Table 2 shows that when using real ECG to train the segmentation model and using synthetic ECG for testing, high recall and precision are achieved in the start point and end point detection, which are 93.45% and 94.24%, and 95.20% and 96.78% respectively. This indicates that the deep generation model accurately follows the provided cardiac cycle information, enhancing clinical relevance and diagnostic accuracy. When using synthetic ECG to train the segmentation model and using real ECG for testing, the model has a recall rate of 98.20% and a precision of 97.33% at the start point, and a recall rate of 96.67% and a precision of 97.59% at the end point, achieving a segmentation effect close to real ECG. This indicates that pre-training synthetic data can achieve a performance close to real data, which is of great significance for ECG analysis algorithms under strict privacy requirements.

[0215] Customizing Cardiac Cycle Phases: By accurately reproducing ECG semantic information, the deep generative model is able to precisely customize cardiac cycle phases and accurately generate ECGs under various cardiac conditions, including varying heart rates and QTc intervals. The model synthesizes customized ECGs based on waveform segmentation, interval lengths, and other information embedded in the labels. The model can synthesize ECGs with normal heart rates (60-100 bpm), bradycardia (less than 60 bpm), and tachycardia (greater than 100 bpm), demonstrating its ability to generate high-quality ECGs with pathological features. Furthermore, the model can synthesize both normal (QTc 350-470 milliseconds) and abnormal QTc intervals, highlighting its significant advantage in synthesizing ECGs for rare physiological conditions. Despite being primarily trained on normal ECGs, the final deep generative model performed well in generating abnormal ECGs, demonstrating its ability to generalize beyond the training set. By manually setting label information, this ECG generation method can customize ECGs for specific conditions, thereby addressing data scarcity while ensuring a high degree of patient privacy.

[0216] In summary, a deep generative model based on a diffusion model was used to synthesize customizable biomedical ECG signals. By embedding ECG semantic information (including the positions of the P wave, QRS complex, and T wave), this ECG generation method effectively improved the clinical relevance of the model. This is the first method to incorporate key cardiac information, such as cardiac cycle phase and waveform position, into the conditional labels of a deep generative model. Unlike previous ECG generation methods, the ECG dataset can be annotated and the ECG semantic labels corresponding to each ECG record generated based on the annotation results can be manually set. Manually setting the ECG semantic labels allows fine-tuning of the cardiac cycle phase and accurately generates ECG signals under various cardiac conditions, thus achieving higher customizability. This advancement effectively expands the application scope of synthetic ECGs, further strengthens patient privacy protection, and promotes the development of personalized medicine. The present invention can synthesize ECG signals that accurately follow the real cardiac cycle information and outperform existing methods in terms of quality and authenticity. By calculating distance- and correlation-based metrics, the quality of the customized ECG model was quantitatively analyzed from different perspectives. In addition, the authenticity evaluation of the ECG generation method also includes the use of a segmentation model to verify whether the generated ECG waveform accurately follows the provided cardiac cycle information and can effectively replace the real signal during training. The results show that the ECG generation method can not only accurately customize the cardiac cycle phase, but also has obvious advantages in generating ECGs. The present invention can synthesize ECG signals that accurately follow the real cardiac cycle information and outperform existing methods in terms of quality and authenticity. The method can generate accurate and interpretable ECG waveforms under various cardiac conditions such as different heart rates and QTc intervals, which highlights its clinical relevance. By manipulating the cardiac cycle phase and generating ECGs under rare physiological conditions, it addresses the major challenges of data scarcity and patient privacy. By synthesizing tailored ECG signals, the model provides a valuable tool for medical research and applications, and helps to develop more powerful and effective ECG generation methods.

[0217] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.

Claims

1. A method for generating an electrocardiogram based on a diffusion model to synthesize a customizable cardiac cycle, characterized in that: The electrocardiogram generation method is: The ECG semantic label is input as the input sequence, and the noise and diffusion time step are input to the deep generative model to generate the ECG; The deep generative model includes a converter model, an embedding layer, a third linear layer, a normalization module, a gate processing module, a first convolution module, a second convolution module and an adder; The converter model includes an encoder and a decoder; An encoder, used to encode the input noise to generate an encoded noise signal; The embedding layer includes a first linear layer and a second linear layer; The first linear layer and the second linear layer are used to encode the time information of the input diffusion time step and obtain the time step embedding vector; The third linear layer is used to match the time step embedding vector to the same length as the encoded noise signal, and add it to the encoded noise signal element by element to fuse the time step information to obtain the noisy signal fused with the time embedding vector; The first convolution module is used to apply a convolution layer to the noisy signal fused with the time embedding vector to change the number of channels and obtain a convolution-processed signal; Normalization module, which is used to input the convolution processing signal and the semantic information label corresponding to the input ECG data, and output a vector embedded with semantic information; A gated processing module is used to perform gated hyperbolic tangent nonlinear processing on the vector embedded with semantic information to obtain a gated processing signal; The second convolution module is used to perform convolution processing on the gated processing signal, project the residual channel back to the original channel dimension, and obtain the output signal of the current layer; An adder, configured to add the output signal of the current layer and the encoded noise signal element-wise to form a residual, and connect the residual as input to the next residual block to obtain predicted noise; The decoder is used to obtain the denoised signal by using the predicted noise, and decode the denoised signal to generate an electrocardiogram.

2. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 1, characterized in that: The parameters of the deep generative model are determined through training optimization. The specific optimization steps are: Step 1: Divide the ECG dataset into a training set and a test set, annotate the ECG dataset, and generate an ECG semantic label corresponding to each ECG record based on the annotation results; Step 2: Using the training set as input and the ECG semantic label as a condition, the parameters of the initial deep generative model are optimized to obtain the final deep generative model.

3. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 2, characterized in that: The specific method of dividing the ECG dataset in step 1 is: dividing it into a training set and a test set in a ratio of 7.5:2.

5.

4. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 2, characterized in that: The specific method for annotating the electrocardiogram data set is: dividing each electrocardiogram record in the electrocardiogram data set into a P wave area, a T wave area, a QRS complex area, and other partial areas; wherein the P wave area is marked as 1; the T wave area is marked as 2; the QRS complex area is marked as 3; and the other partial areas are marked as 0.

5. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 2, characterized in that: In step 2, the training set and the ECG semantic labels are Hank-ized before the parameters of the initial deep generative model are optimized; each ECG record in the training set is denoted as X; the ECG semantic label corresponding to each ECG record is denoted as Y; The Hank conversion process is to convert the electrocardiogram record X in the training set into a two-dimensional Hank matrix x; and to convert the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hank matrix y.

6. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 5, characterized in that: The specific process of converting the electrocardiogram record X in the training set into a two-dimensional Hank matrix x is: Each ECG record X in the training set is a one-dimensional sequence d of length N, denoted as X = {d1, d2, d3, ..., d N }; where d1 is the first element in the one-dimensional sequence d, d2 is the second element in the one-dimensional sequence d, d3 is the third element in the one-dimensional sequence d, and d N is the Nth element in the one-dimensional sequence d; Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix x is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix x is represented by an element of the one-dimensional sequence d as: x ij =d i+j-1 , where 1≤i≤L, 1≤j≤K; Therefore, we get the two-dimensional Hank matrix x: In the two-dimensional Hank matrix x, the elements on each anti-diagonal line are the same.

7. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 6, characterized in that: The specific process of converting the electrocardiogram semantic label Y corresponding to each electrocardiogram record into a two-dimensional Hank matrix y is as follows: The ECG semantic label Y corresponding to each ECG record is a one-dimensional sequence f of length N, denoted as Y = {f1,f2,f3,...,f N }; where f1 is the first element in the one-dimensional sequence f, f2 is the second element in the one-dimensional sequence f, f3 is the third element in the one-dimensional sequence f, and f N is the Nth element in the one-dimensional sequence f; Choose a window length L, where 1≤L≤N; the size of the two-dimensional Hank matrix y is L×K, where K is the number of windows and K=N-L+1; each element of the two-dimensional Hank matrix y is represented by an element of the one-dimensional sequence f as: y ij =f i+j-1 , where 1≤i≤L, 1≤j≤K; Therefore, we get the two-dimensional Hank matrix y: In the two-dimensional Hank matrix y, the elements on each anti-diagonal line are the same.

8. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 7, characterized in that: The specific method for optimizing the parameters of the initial deep generative model in step 2 is: Step (1), for the two-dimensional Hank matrix x, from noise-free x0 to pure Gaussian noise x T , generate multiple noise signals x t ; Among them, α t is the scaling factor at each time step t in the forward process of the diffusion model; t is the diffusion time step; β is the diffusion rate; Step (2): For each corresponding diffusion time step t, the time information is encoded through the time embedding layer; the output of the time embedding layer is obtained by transforming the formula 1; the formula 1 is: TE=Swish(Linear2(Swish(Linear1(TimeEmbed(t))))) Formula 1 Where TimeEmbed is the time embedding layer; Linear1 is the first linear layer; Linear2 is the second linear layer; TE is the time step embedding vector; Swish(·) is the first activation function, which is defined as: Step (3): Use the encoder to input the noise signal x t Encode and generate the encoded noise signal x′ t ; Step (4): The time step embedding vector TE is matched to the encoded noise signal x′ through the third linear layer. t The same length as the encoded noise signal x′ t Add element by element to fuse the time step information; get the noisy signal z that fuses the time embedding vector t ; Among them, Linear3 is the third linear layer; Step (5) is to obtain the noisy signal z fused with the time embedding vector t Apply the convolution layer to change the number of channels and obtain the convolution processing signal z′ t ; With' t =Conv1D(z t ) Among them, Conv1D is the convolution operator symbol; Step (6): convolution processing signal z′ t The semantic information label y corresponding to the ECG in the training set after Hank processing is passed to the normalization module, and the normalization module outputs the vector z″ embedded with semantic information t ; Step (7), the normalization module outputs the vector z″ embedded with semantic information t After gated hyperbolic tangent nonlinear processing, the gated processing signal is obtained Among them, tanh(·) is the second activation function, σ(·) is the third activation function, Step (8), gated processing signal The residual channel is projected back to the original channel dimension through the convolution layer to obtain the output signal of the current layer Step (9): the output signal of the current layer and the processed noise signal x′ generated in step (3) t Add element-wise to form the residual residual Connected to the next residual block as input; in: Step (10), after passing through multiple layers of residual blocks, the features transferred from different residual blocks are fused element by element through skip connections to obtain a prediction noise ∈ θ (x t ,t), where θ is the diffusion model parameter; the training goal is to minimize the loss function, that is, to minimize the mean square error between the predicted noise and the real noise; the specific calculation formula of the training goal is: in, is the loss function, ∈ is the real noise; x0~D represents the noise-free x0 sampled from the training data distribution D; represents the real noise ∈ sampled from a standard normal distribution with mean 0 and variance 1; t~U(1,T) represents the time step t sampled from the uniform distribution U(1,T); Step (11) uses back propagation and gradient descent algorithms to optimize the diffusion model parameters θ to obtain the final deep generative model.

9. The electrocardiogram generation method based on diffusion model synthesis of customizable cardiac cycles according to claim 8, characterized in that: The specific formula for the decoder to obtain the denoised signal using the predicted noise is: Among them, α t is the scaling factor at each time step t during the diffusion process, is the cumulative product of the α parameters from time step 1 to time step t, s is the cumulative product variable; σ t is the coefficient of random noise introduced during the denoising process.

10. The electrocardiogram generation method based on diffusion model synthesis and customizable cardiac cycle according to claim 8, characterized in that: The specific calculation formula of the training target in step (10) is obtained by the following method: The diffusion model includes two processes: forward process and reverse process; In the forward process, the diffusion model gradually introduces noise in the manner of a Markov chain. The parameterization formula of this process is as follows: Among them, the noise-free x0 is the original data sample without noise interference, and the pure Gaussian noise x T is the data after T noise addition steps, where T is the number of diffusion steps; the specific noise introduction formula is: Among them, β t is the noise variance of the forward process; is a normal distribution; I represents the identity matrix; x t Use the following formula: In the reverse process, the diffusion model gradually removes noise and reconstructs the original data from the given data sample. The specific reconstruction process is: the model is trained using the objective function. The parameterization formula of the reverse process is as follows: Among them, x T Obey the standard normal distribution; loss function It is used to train the neural network in the reverse process so that the neural network can be used to train the neural network in the given diffusion time step t and the current noise signal x. t The prediction noise ∈ θ (x t ,t), the specific calculation formula of the training target is as follows:

Citation Information

Patent Citations

  • Electrocardiogram generation system and method based on deep learning algorithm

    CN116744850A

  • Method and system for removing random mixed noise in dynamic electrocardiogram

    CN117009743A

Cited By

  • A hierarchical rule-guided twelve-lead long-term electrocardiogram generation method

    CN122510389A