A machine learning-based electrocardiogram p-wave recognition method
By collecting, segmenting, randomly adjusting, and splicing electrocardiogram (ECG) signals, a deep learning network was constructed to optimize the processing of P-wave position labels, thus solving the accuracy and cost problems of P-wave identification in ECGs and achieving efficient and low-cost P-wave identification.
Patent Information
- Application Number
- CN202310793742.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-30
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2043-06-30
AI Technical Summary
Existing technologies for identifying P waves in electrocardiograms struggle to balance accuracy and cost, suffering from signal interference, P wave morphology variations, and the influence of heart disease. Furthermore, image-based analysis methods are costly and have high hardware requirements.
By acquiring and filtering ECG signals, segmenting PQRST waveforms, randomly adjusting and splicing signals, constructing deep learning networks and convolutional neural networks, adding simulated noise, optimizing the processing of P wave position labels, generating training datasets, and reducing hardware requirements and computational costs.
It improves the accuracy of P-wave identification, reduces computational costs, simplifies the calculation process, adapts to P-wave morphological changes in different populations and at different times, and solves the problem of noise interference.
Smart Images

Figure CN116807492B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, specifically to a method for recognizing P waves in electrocardiograms based on machine learning. Background Technology
[0002] The P wave in an electrocardiogram (ECG) represents the contraction of the heart's atria. When the atria contract, they transmit an electrical signal to the ventricles, which is recorded on the ECG as a small peak called the P wave. The P wave usually appears at the beginning of the ECG, before the QRS complex, and its shape is typically positive. The duration of the P wave is usually less than 0.08 seconds, and its amplitude is usually less than 2.5 millivolts (mV). The morphology of the P wave can reflect the size, shape, and conduction of the atria. Abnormal P waves may indicate atrial hypertrophy, conduction abnormalities, or other heart problems. The P wave on an ECG is very important for assessing heart health, so in some cases, technicians need to locate the specific P wave position in the ECG data to achieve detailed analysis of the ECG data, similar to marking the P wave position on a waveform diagram, such as... Figure 1 As shown.
[0003] However, current methods for identifying P waves are difficult to achieve ideal accuracy, mainly for the following reasons:
[0004] 1) Signal interference: ECG signals are susceptible to various interferences, such as electromyography (EMG) signals, electrode displacement, and baseline drift. These interferences can mask the P wave signal, making it difficult to identify accurately. 2) Differences in P wave morphology: The morphology and amplitude of the P wave may vary among different populations, and even within the same person at different times, the P wave morphology may change, increasing the difficulty of P wave identification. 3) Heart disease: Heart disease can lead to pathological changes such as atrial enlargement and myocardial infarction. These pathological changes affect the morphology and amplitude of the P wave. In cases of atrial fibrillation and premature ventricular contractions (PVCs), a P wave may not be produced, making it even more difficult to identify accurately.
[0005] With technological advancements, some technicians, similar to those described in patent application number 2020105966856, have proposed image analysis methods. These methods utilize neural networks, machine learning, and other techniques to construct image recognition models that identify waveforms in electrocardiogram (ECG) images, pinpointing the corresponding P and R waves. However, this method of identifying waveform positions in ECGs based on image analysis requires... Figure 1 The exported ECG data is first converted into graphic data, which is a complicated data preprocessing process. Moreover, image data recognition requires extensive training of the recognition model, which takes a lot of time. In addition, the computation of graphic data has high hardware performance requirements. All of these factors contribute to the high cost of the P-wave recognition method. Summary of the Invention
[0006] To address the issue that existing methods for P-wave identification in electrocardiograms cannot balance accuracy and cost, this invention provides a machine learning-based P-wave identification method for electrocardiograms that can accurately locate the P-wave in the electrocardiogram at a lower cost.
[0007] The technical solution of this invention is as follows: a method for recognizing P waves in electrocardiograms based on machine learning, characterized by comprising the following steps:
[0008] S1: Based on historical data, collect raw electrocardiogram (ECG) signal data, filter out interference noise in the raw ECG signal data, and obtain effective ECG signal data;
[0009] S2: Segment each of the valid ECG signals to obtain the P wave, QRS wave and T wave, forming the PQRST signal set;
[0010] S3: Randomly adjust each waveform signal in the PQRST signal set using a random adjustment function to obtain the adjusted signal set;
[0011] The random adjustment function X_random is:
[0012] X_random=f(X,length_X,length_random)*a
[0013] Where X is the original waveform, f(X) is the linear interpolation function, length_X is the width of the original waveform X, length_random is a random number representing the target width, and a is a random number;
[0014] S4: Randomly select various types of waveform signals from the adjusted signal set, and splice the electrocardiogram signal according to the preset electrocardiogram signal waveform rules to obtain: spliced signal set;
[0015] The electrocardiogram waveform rules include: normal electrocardiogram rules, atrioventricular block electrocardiogram rules, and premature ventricular contractions electrocardiogram rules;
[0016] S5: Randomly add simulated interference noise to each ECG signal data in the spliced signal set to obtain: ECG signal set to be verified;
[0017] S6: A deep learning network built on an encoder-decoder architecture, denoted as: a data validator;
[0018] S7: Train the data validator using real raw electrocardiogram signal data to obtain the trained data validator;
[0019] The loss function used during training is:
[0020]
[0021] Where x is the input waveform data, y is the output waveform data, and n is the waveform length;
[0022] S8: Preset a simulation threshold;
[0023] S9: Extract each signal data from the set of ECG signals to be verified one by one, and denot it as: signal data to be verified;
[0024] The signal data to be verified is fed into the trained data validator pair for verification.
[0025] During the verification process, if the loss function corresponding to the signal data to be verified is less than the simulation threshold, the signal data to be verified is determined to be valid data and stored in the training dataset.
[0026] Otherwise, the signal data to be verified is determined to be invalid, and the data is deleted;
[0027] S10: Constructing a recognizer based on a convolutional neural network;
[0028] The output of the identifier is a p-wave position label that has the same waveform length as the waveform of the input signal data. The p-wave position label is an identifier indicating whether the waveform at the corresponding position of the input signal data is a p-wave.
[0029] S11: Train the recognizer based on the training dataset to obtain the trained recognizer;
[0030] S12: Acquire the ECG signal to be identified, and send the ECG signal to be identified into the trained recognizer for identification;
[0031] The presence of a mark on the p-wave position label output by the identifier indicates that the waveform at the corresponding position of the ECG signal to be identified is a p-wave.
[0032] Its further features are:
[0033] It also includes optimization processing operations, which organize each P-wave position label based on the optimization processing operations, specifically including the following steps:
[0034] a1: 1 represents the P-wave label on the P-wave location label, and 0 represents a non-P-wave;
[0035] Traverse the P-wave location labels to confirm the position and number of 0s and 1s on the P-wave location labels;
[0036] a2: Preset oscillation threshold N;
[0037] Find all consecutive 0 segments and 1 segments, count the number of consecutive 0s and consecutive 1s, and if they are greater than or equal to N, then denote these segments as stationary segments.
[0038] All segments other than the stationary segments are denoted as: oscillating segments;
[0039] Confirm the number of 0s and 1s in each oscillation segment. If the number of 1s is greater than the number of 0s, reset all 0s in the oscillation segment to 1; otherwise, reset all 1s in the oscillation segment to 0.
[0040] The reset P-wave position label is denoted as: stationary data label;
[0041] a3: Preset fixed threshold F;
[0042] The stable data labels are traversed again to find all consecutive segments of 1, and the number of 1s in each segment is counted. If the number of 1s is less than F, the 1s in the corresponding segment are reset to 0.
[0043] The organized tags are denoted as: Fixed Data Tags;
[0044] a4: Preset interval threshold G;
[0045] All consecutive segments of 1 are denoted as: P-wave segments;
[0046] The fixed data labels are traversed again to find all consecutive 0 segments located between two P-wave segments, denoted as: intermediate segments;
[0047] a5: Confirm the number of consecutive 0s s0 in each of the intermediate segments;
[0048] If the intermediate segment exists that satisfies: s0>G, then all the corresponding intermediate segments are recorded as: reconfirmation segments, and then step a6 is executed;
[0049] Otherwise, if all the intermediate segments satisfy s0≤G, then proceed to step a8;
[0050] a6: After enhancing the heartbeat data corresponding to the reconfirmed segment, replace the original data in the ECG signal to be identified, and send it into the trained recognizer for secondary confirmation. The P wave position label output by the recognizer is denoted as: enhanced P wave position label.
[0051] a7: Confirm the number of secondary confirmations in the recognizer. If the number of secondary confirmations has met the preset secondary confirmation threshold, then execute step a8;
[0052] Otherwise, based on the enhanced p-wave position label, loop and implement steps a1 - a6;
[0053] a8: Denote the finally obtained p-wave position label as: the label to be filtered;
[0054] a9: Preset the noise filtering threshold Nos;
[0055] Traverse the label to be filtered, find all segments of consecutive 1s, and denote them as: p-wave segments;
[0056] Calculate the average height h of the corresponding electrocardiogram data signal for each p-wave segment, and compare h with Nos;
[0057] If there exists h < Nos, then reset all 1s in the corresponding p-wave segment to 0;
[0058] a10: Output the finally obtained p-wave position label as the final result of the optimization process;
[0059] The oscillation threshold N = 10, the fixed threshold F = 14, the enhancement threshold S = 2, and the noise filtering threshold Nos = 0.2;
[0060] In step S3, the value range of length_random is [length_X * 0.9, length_X * 1.1], that is, if length_X is equal to 100, the value range of length_random is [90, 110]; the value range of a is [0.9, 1.1];
[0061] The electrocardiogram signal waveform rules define the waveform types and waveform sequences included in each type of electrocardiogram;
[0062] The normal electrocardiogram rules and waveform sequences are as follows:
[0063] n1: P wave: The waveform generated by atrial contraction;
[0064] n2: PR segment: The time period between the end of the P wave and the start of the Q wave; the interval is 0.12 - 0.2 seconds;
[0065] n3: Q wave: The start of ventricular depolarization;
[0066] n4: R wave: The main waveform of ventricular depolarization;
[0067] n5: S wave: A small downward wave peak following the R wave;
[0068] n6: ST segment: The time period between the end of the R wave and the beginning of the T wave; its duration is 0.08-0.12 seconds;
[0069] n7: T wave: The waveform of ventricular repolarization; it appears as a small upward peak on an electrocardiogram, lasting about 0.16 seconds.
[0070] n8: TP segment: The time period between the end of the T wave and the beginning of the P wave; its duration is 0.2-0.4 seconds;
[0071] The atrioventricular block includes: first-degree atrioventricular block, second-degree atrioventricular block, and third-degree atrioventricular block; the specific rules are as follows:
[0072] First-degree atrioventricular block; in first-degree atrioventricular block, the PR interval between the P wave and the QRS complex is prolonged, but the morphology and interval of the QRS complex are normal.
[0073] Second-degree atrioventricular block includes: Mobitz type I and Mobitz type II;
[0074] Mobitz type I: In this case, the PR interval between the P wave and the QRS complex gradually lengthens until the QRS complex is suddenly absent; then, the interval between the P wave and the QRS complex will restart, and so on.
[0075] Mobitz type II: In this case, the PR interval between the P wave and the QRS complex remains relatively constant, but the QRS complex is suddenly absent; in this case, the interval between the P wave and the QRS complex is irregular.
[0076] The third-degree atrioventricular block: In this case, the relationship between the P wave and the QRS wave is completely broken, so a regular PQRST waveform interval cannot be formed;
[0077] The electrocardiogram of the premature ventricular contractions (PVCs) includes: premature beats and ventricular tachycardia.
[0078] The ECG rules for premature beats are as follows: P waves appear randomly; and if a P wave appears, the PR interval between it and the QRS complex is usually shorter than normal.
[0079] The electrocardiographic rules for ventricular tachycardia include the presence of no P waves.
[0080] The simulated interference noise includes: Gaussian noise;
[0081] In step S1, the method for filtering out interference noise in the original electrocardiogram signal data includes:
[0082] Interference noise in the original electrocardiogram signal data is filtered out using a bandpass filter ranging from 0.5 Hz to 50 Hz.
[0083] The recognizer uses cross-entropy as the loss function during the recognition process;
[0084] The enhancement operation in step a6 is as follows: a preset enhancement threshold S is set, and the heartbeat data corresponding to the reconfirmed segment is multiplied by the preset enhancement threshold S respectively.
[0085] This application provides a machine learning-based electrocardiogram (ECG) P-wave recognition method. It obtains raw ECG signal data by collecting P-wave and QRS wave morphologies from different populations at different times. After segmentation, P-waves, QRS waves, and T-waves are obtained. Various types of ECG data are then generated according to preset ECG waveform rules, ensuring that the training dataset includes normal and pathological ECG curves from different populations at different times. Random noise is added to the generated curves, and then random combinations with added noise are used to obtain the ECG signal set to be validated, improving the robustness of the training. A data validator is constructed to remove non-compliant ECG signal data, resulting in the training dataset. The method for generating the training dataset in this application can generate a large amount of new data even when real data is lacking, and it covers all situations that may affect P-wave recognition, reducing the cost of the method. Simultaneously, the data validator ensures that it can simulate different pathological ECGs from different populations at different times, even if the individual's ECG... Figure 1 This method uses a normal electrocardiogram (ECG) to address the issue of varying P-wave morphology across different populations and time periods, thus improving the accuracy of calculations. By adding noise to simulate the noise present in a real ECG, it effectively solves problems such as P-wave recognition failure caused by noise interference, further enhancing the accuracy of calculations. The recognizer is trained on a training dataset constructed using this method, ensuring accurate location of the P-wave in the ECG data. Furthermore, this method performs subsequent P-wave location recognition based on the acquired ECG signal data, eliminating the need to convert the ECG signal data into graphical data, simplifying the calculation process, significantly improving calculation speed, reducing hardware performance requirements, and consequently lowering the overall cost of the method. Attached Figure Description
[0086] Figure 1 Examples of the locations of various waveforms in electrocardiogram (ECG) data;
[0087] Figure 2 Example of complete electrocardiogram (ECG) signal data for a normal heartbeat;
[0088] Figure 3This is an example of obtaining valid ECG signal data after bandpass filtering of ECG signal data;
[0089] Figure 4 Examples of p waves, QRS waves, and T waves segmented from valid electrocardiogram (ECG) signal data;
[0090] Figure 5 Example of the original qrs waveform and the qrs waveform obtained after processing with the X_random function;
[0091] Figure 6 An example of stitching together ECG image segments after randomly adding simulated interference noise;
[0092] Figure 7 Example 2 is a p-wave location tag identification based on this method;
[0093] Figure 8 This is a schematic diagram of a machine learning-based electrocardiogram P-wave recognition method.
[0094] Figure 9 A flowchart for optimizing the processing operation;
[0095] Figure 10 This is the waveform diagram corresponding to the electrocardiogram signal to be identified in Example 1;
[0096] Figure 11 In Example 1, the pair is based on the trained recognizer. Figure 10 The P-wave location label is obtained after identifying the data;
[0097] Figure 12 For Example 1 Figure 11 The final result is obtained after optimizing the P-wave position labels. Detailed Implementation
[0098] like Figure 2 As shown, a complete normal heartbeat begins with pacing at the sinoatrial node, generating a P wave, which conducts downwards from the atrium to the atrioventricular junction. The conduction velocity then slows abruptly, and the P wave rapidly descends to the ventricles via the atrioventricular bundle and left and right bundle branches. Upon reaching the ventricles, a QRS wave is generated, followed by ventricular-atrial depolarization, producing a T wave. However, in some cardiac diseases, such as atrioventricular block, the P wave generated after pacing at the sinoatrial node is blocked at the atrioventricular junction and cannot reach the ventricles; therefore, only the P wave is present, without the subsequent QRS wave. In premature ventricular contractions (PVCs) or atrial fibrillation, the P wave disappears, with no obvious P wave. Therefore, traditional algorithms cannot solve the problem of P wave identification in pathological electrocardiograms.
[0099] like Figure 8 As shown, this application includes a machine learning-based electrocardiogram P-wave recognition method, which includes the following steps.
[0100] S1: Based on historical data, collect raw electrocardiogram (ECG) signal data, filter out interference noise in the raw ECG signal data, and obtain effective ECG signal data.
[0101] In this embodiment, the method for filtering out interference noise in the original electrocardiogram signal data includes:
[0102] Bandpass filtering from 0.5Hz to 50Hz was used to filter out interference noise in the raw ECG signal data.
[0103] Electrocardiogram (ECG) signals typically contain multiple frequency components. Therefore, bandpass filtering can effectively remove some unwanted frequency components while retaining the signal within the frequency range of interest. The principle of bandpass filtering is to select a frequency band in the filter's frequency response curve. By allowing signals within this band to pass through, other frequency components are blocked or attenuated, thus achieving signal filtering. Bandpass filtering can effectively solve signal interference problems, filter out abnormal signals, and resolve issues such as EMG signal interference, electrode shift, and baseline drift. Typically, the P wave frequency range is 0.5 Hz to 5 Hz; the QRS wave frequency range is 10 Hz to 50 Hz; and the T wave frequency range is 1 Hz to 7 Hz.
[0104] When the frequency is less than 0.5 Hz, it is considered low-frequency noise, mostly manifesting as baseline drift. When the frequency is greater than 50 Hz, it is considered high-frequency noise, mostly caused by electromyographic signal interference, electrode displacement, etc. Therefore, in this embodiment, a bandpass filter from 0.5 Hz to 50 Hz is used, which can effectively filter out noise interference in the original ECG signal and retain useful information such as the pqrst wave in the ECG curve. Specifically, as follows... Figure 3 As shown.
[0105] S2: Each valid ECG signal is segmented to obtain the P wave, QRS wave and T wave, forming the PQRST signal set.
[0106] P, QRS, and T waves are segmented from ECG curves of different populations at different time periods. Specific examples of P, QRS, and T waves segmented from valid ECG signal data are as follows: Figure 4 As shown.
[0107] S3: Randomly adjust each waveform signal in the PQRST signal set using a random adjustment function to obtain the adjusted signal set;
[0108] The random adjustment function X_random is:
[0109] X_random=f(X,length_X,length_random)*a
[0110] Where X is the original waveform, f(X) is the linear interpolation function, length_X is the width of the original waveform X, length_random is a random number representing the target width, and a is a random number.
[0111] To prevent the randomly adjusted waveform from differing too much from the original waveform, the changes in width via linear interpolation f(X) and the changes in height via random number a are limited to a certain range. In this embodiment, the value range of length_random is [length_X*0.9, length_X*1.1], that is, if length_X equals 100, the value range of length_random is [90, 110]; the value range of a is [0.9, 1.1]. Specific implementation of the adjustment is as follows: Figure 5 As shown.
[0112] In this method, each waveform signal in the PQRST signal set is randomly adjusted to ensure that the training set can be expanded. At the same time, it prevents the PQRST waveforms used in the subsequently generated ECG curves from being the original collected waveforms with poor randomness, which would lead to overfitting of the data when using the recognizer for machine learning training.
[0113] S4: Randomly select various types of waveform signals from the adjusted signal set, and splice the ECG signal according to the preset ECG signal waveform rules to obtain: spliced signal set;
[0114] The waveform rules of electrocardiogram (ECG) signals include: the normal ECG pattern, the ECG pattern of atrioventricular block, and the ECG pattern of premature ventricular contractions (PVCs).
[0115] This method defines the waveform types and their order in each type of electrocardiogram based on the waveform rules of electrocardiogram signals.
[0116] The normal electrocardiogram (ECG) pattern and waveform sequence are as follows:
[0117] n1: P wave: The waveform produced by atrial contraction;
[0118] n2: PR segment: the time interval between the end of the P wave and the beginning of the Q wave; the interval is 0.12-0.2 seconds;
[0119] n3: Q wave: the onset of ventricular depolarization;
[0120] n4: R wave: The main waveform of ventricular depolarization;
[0121] n5: S wave: A small downward peak that follows the R wave;
[0122] n6: ST segment: The time period between the end of the R wave and the beginning of the T wave; its duration is 0.08-0.12 seconds;
[0123] n7: T wave: The waveform of ventricular repolarization; it appears as a small upward peak on an electrocardiogram, lasting about 0.16 seconds.
[0124] n8: TP segment: The time period between the end of the T wave and the beginning of the P wave; its duration is 0.2-0.4 seconds.
[0125] In cases of atrioventricular block, the intervals and sequence of the PQRST waveforms may vary depending on the degree of atrioventricular conduction. Below are the PQRST waveform intervals and sequences for different types of atrioventricular block: Atrioventricular block includes first-degree, second-degree, and third-degree atrioventricular block; the specific rules are as follows:
[0126] First-degree atrioventricular block; in first-degree atrioventricular block, the PR interval between the P wave and the QRS complex is prolonged, but the morphology and interval of the QRS complex are normal.
[0127] Second-degree atrioventricular block includes: Mobitz type I and Mobitz type II;
[0128] Mobitz type I: In this case, the PR interval between the P wave and the QRS complex gradually lengthens until the QRS complex is suddenly absent; then, the interval between the P wave and the QRS complex will restart, and so on.
[0129] Mobitz type II: In this case, the PR interval between the P wave and the QRS complex remains relatively constant, but the QRS complex is suddenly absent; in this case, the interval between the P wave and the QRS complex is irregular.
[0130] Third-degree atrioventricular block: In this case, the relationship between the P wave and the QRS complex is completely broken, so a regular PQRST waveform interval cannot be formed.
[0131] The PQRST waveform intervals and sequence of premature ventricular contractions (PVCs) can vary depending on the specific type and timing of the PVC. Typically, the ECG of PVCs includes premature beats and ventricular tachycardia.
[0132] ECG rules for premature beats: P waves appear randomly; and if a P wave appears, the PR interval between it and the QRS complex is usually shorter than normal.
[0133] ECG rules for ventricular tachycardia: The absence of P waves is present;
[0134] In practice, if processing ECG data for ventricular tachycardia, since the P wave is absent, the above optimization process for the P wave position label can be omitted.
[0135] S5: Randomly add simulated interference noise to each ECG signal data in the spliced signal set to obtain: ECG signal set to be verified.
[0136] Simulated interference noise includes: Gaussian noise;
[0137] Based on the above ECG signal waveform rules, various types of waveform signals are randomly selected from the adjusted signal set and randomly spliced together, i.e., the pqrst wave is randomly selected, and then spliced into fixed-length ECG image segments according to different rules. Random Gaussian noise is then added to simulate interference from electromyography signals, electrode displacement, etc.; the resulting randomly spliced segments are shown below. Figure 6 As shown.
[0138] S6: Build a deep learning network based on encoder-decoder, denoted as: data validator.
[0139] S7: Train the data validator using real raw ECG signal data to obtain a trained data validator;
[0140] The loss function used during training is:
[0141]
[0142] Where x is the input waveform data, y is the output waveform data, and n is the waveform length.
[0143] This method constructs a data validator based on a deep learning network model with an encoder-decoder architecture. During the training process of the encoder-decoder model, the original data is encoded, and then the encoded data is decoded. By training the original data and the decoded data to be consistent, the model can effectively extract the main information components of the original data.
[0144] This method uses Euclidean distance as the loss function because, theoretically, the range of ECG data values is [-∞, +∞]. Euclidean distance can calculate the distance between any two values, while other methods, such as cross-entropy, can only calculate the distance within the range [0,1].
[0145] S8: Preset a simulation threshold.
[0146] In practical applications, the simulation threshold is set based on empirical values. If the simulation threshold is too large, the generated spliced segment data will be distorted and will not match the normal electrocardiogram segments. If it is too small, the generated spliced segment data will be too few, and a large amount of generated data will be deleted.
[0147] S9: Extract each signal data from the ECG signal set to be verified one by one, and denot it as: signal data to be verified;
[0148] The signal data to be verified is fed into a trained data validator pair for verification.
[0149] During the verification process, if the loss function corresponding to the signal data to be verified is less than the simulation threshold, the signal data to be verified is judged as valid data and stored in the training dataset.
[0150] Otherwise, the signal data to be verified is deemed invalid and deleted.
[0151] This method generates a training dataset that effectively expands the training dataset, producing a large amount of new data even when real-world data is lacking, and covering all situations that can affect P-wave recognition. Furthermore, it can simulate different pathological electrocardiograms from different populations at different times, even if the individual's electrocardiogram... Figure 1 This method provides a normal electrocardiogram (ECG) and resolves the issue of varying P-wave morphology across different individuals and time periods. Furthermore, by adding noise to simulate the noise present in a real ECG, it effectively addresses problems such as P-wave recognition failure caused by noise interference.
[0152] S10: Constructing a recognizer based on a convolutional neural network;
[0153] The output of the identifier is a P-wave position label that has the same waveform length as the waveform of the input signal data. The P-wave position label is an identifier indicating whether the waveform at the corresponding position of the input signal data is a P-wave.
[0154] During the recognition process, the recognizer uses cross-entropy as the loss function.
[0155] This method uses a CNN model to build the recognizer because recognizing the P wave in an electrocardiogram (ECG) is a local event. The first P wave is unrelated to data 20 seconds later or even 20 seconds earlier; it is only related to the current heartbeat. Therefore, a CNN model is used to extract local information through convolution. Compared to other models such as RNNs or transformers, which primarily analyze global relationships, CNNs are more suitable for this method's temporal recognition.
[0156] S11: Train the recognizer based on the training dataset to obtain a trained recognizer.
[0157] In this method, if the encoder-decoder trained with real data can also successfully encode and decode the randomly generated data, it can be proven that the principal components of the randomly generated data are consistent with the real data, and thus it is considered to be valid data.
[0158] S12: Acquire the ECG signal to be identified and send the ECG signal to be identified into the trained recognizer for identification;
[0159] The location marked on the p-wave position label output by the identifier indicates that the waveform at the corresponding position of the ECG signal to be identified is a p-wave.
[0160] Because the results generated directly using convolutional neural networks are not smooth enough and have gaps in the middle, this patent constructs a post-processing algorithm: an optimization operation, to optimize the results of the deep learning model based on convolutional neural networks. Based on the optimization operation, the label of each P-wave position is organized, such as... Figure 9 As shown, the specific steps include:
[0161] a1: 1 represents the P-wave label on the P-wave location label, and 0 represents a non-P-wave.
[0162] Iterate through the P-wave position labels to determine the position and number of 0s and 1s on the P-wave position labels.
[0163] Assume the ECG data corresponding to the ECG signal to be identified in this embodiment is as follows:
[0164] [-0.658630949 -1.044912722 -1.250818214 -1.31711169 -1.329159629 -1.309778593 -1.272811293 -1.236460052 -1.214105535 -1.186982767 -1.164628251-1.150785541 -1.144992594 -1.147249409 -1.149760845 -1.143452445 -1.116276269-1.080387072 -1.068700571 -1.061367475] -1.050190217 -1.018861848 -0.9971768 -1.024151763 -1.092862279 -1.192794345 -1.300053298 -1.372648963 -1.431917372-1.431389498 -1.340934316 -1.275316519 -1.225785826 -1.17636195 -1.134987836-1.09668781 -1.061307856 -0.994385901 -0.904049956 -0.852890928 -0.824127404 -0.801163039 -0.785217529 -0.78640245 -0.803017428 -0.820603693 -0.842958209 -0.859720992 -0.875826726 -0.89704352 -0.770279326 -0.166162117 0.9351673352.112536672 2.738582372 2.504400243 1.366570503 0.120513008 -0.769526641 -1.071670326 -1.17132293 -1.23535338 -1.280109611 -1.31681608】.
[0165] The corresponding waveform is as follows Figure 10 As shown. After the data to be identified is fed into the trained recognizer, the resulting P-wave location label is a 0-1 label of the same length as the ECG signal to be identified: [0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0. 0.0.0.0.0.0.0.0.0.1.0.1.0.1.1.1.1.1.0.1.0.1.1.1.0.
[0168] 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0., The graph of the p-wave location label is as follows: Figure 11 As shown.
[0169] a2: Preset oscillation threshold N; Find all consecutive 0 segments and 1 segments, count the number of consecutive 0s and consecutive 1s, and if they are greater than or equal to N, then record these segments as: stationary segments.
[0170] All segments other than the stationary segments are denoted as oscillating segments;
[0171] Confirm the number of 0s and 1s in each oscillation segment. If the number of 1s is greater than the number of 0s, reset all 0s in the oscillation segment to 1; otherwise, reset all 1s in the oscillation segment to 0.
[0172] The reset P-wave position label is denoted as: stationary data label.
[0173] This method prevents oscillations in the results by using an oscillation threshold N. Oscillation refers to the phenomenon of alternating 0 and 1 phases, because oscillations do not occur in real electrocardiogram data. In this embodiment, the oscillation threshold N = 10.
[0174] It can be observed that the p-wave position labels in this embodiment contain continuously oscillating 01 segments, i.e., oscillating segments.
[0175] If there are no oscillation segments in the data in actual work, then proceed directly to step a3;
[0176] Confirm the number of 0s and 1s in each oscillation segment. If the number of 1s is greater than the number of 0s, reset all 0s in the oscillation segment to 1; otherwise, reset all 1s in the oscillation segment to 0. The resulting stationary data labels are as follows: [0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0. 0.0.0.0.0.0.0.0.0.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.0. 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.]
[0180] The graph corresponding to the stable data labels is as follows Figure 12 As shown.
[0181] a3: Preset fixed threshold F; Fixed threshold F = 14
[0182] The stationary data labels are iterated again to find all segments with consecutive 1s and to count the number of 1s in each segment.
[0183] If the number of 1s is less than F, then reset all 1s in the corresponding segment to 0; otherwise, proceed to step a4.
[0184] The sorted labels are denoted as: Fixed Data Labels.
[0185] Since the P-wave is a waveform with a length of approximately 110ms, the fixed threshold value is 0.11 * sampling rate * 0.5. If the sampling rate is 256, then in this embodiment, the fixed threshold F is equal to 14.
[0186] In this embodiment, the number of 1s in a consecutive 1 segment is 15, which is greater than the fixed threshold F. Therefore, there is no need to set it to zero, and step a4 is executed.
[0187] a4: Preset interval threshold G and enhancement threshold S;
[0188] All consecutive segments of 1 are denoted as: P-wave segments;
[0189] The fixed data labels are iterated again to find all consecutive 0 segments located between two P-wave segments, which are denoted as: intermediate segments.
[0190] In this embodiment, there is only one P-wave segment, so skip a5 to a8 and proceed to step a9.
[0191] a5: Confirm the number of consecutive 0s s0 in each intermediate segment;
[0192] If there is an intermediate segment that satisfies: s0>G, then all the corresponding intermediate segments are marked as: reconfirmed segments, and step a6 is executed;
[0193] Otherwise, if all the intermediate segments satisfy s0≤G, then proceed to step a8.
[0194] a6: After enhancing the heartbeat data corresponding to the reconfirmed segment, replace the original data in the ECG signal to be identified, and send it into the trained recognizer for secondary confirmation. The P wave position label output by the recognizer is recorded as: enhanced P wave position label.
[0195] The enhancement operation is as follows: multiply the heartbeat data corresponding to the reconfirmed segment by the preset enhancement threshold S.
[0196] The normal interval duration between two heartbeats is 0.6 - 1 second. If the distance between two P waves exceeds the interval between two heartbeats, it is possible that there is an undetected one in the middle. In this embodiment, G takes data between 0.6 - 1 second; the enhancement threshold S is set to 2, then: 1 * sampling rate * 2 times = 1 * 256 * 2 = 512; the 1 in 1 * sampling rate * 2 times refers to 1 second, that is, if there is no P wave within two seconds, the data in the middle of this period is enhanced. Two seconds basically includes two heartbeats, that is, it can be determined that one heartbeat will be missed in the middle.
[0197] a7: Confirm the number of secondary confirmations in the recognizer. If the number of secondary confirmations has met the preset secondary confirmation threshold, execute step a8;
[0198] Because in actual work, it is possible that there is no P wave between two particularly long PP intervals in the electrocardiogram data. For example, this P wave is not detected due to various reasons. Therefore, to prevent entering an infinite loop, this application controls the number of loops by setting a secondary confirmation threshold. In this embodiment, the secondary confirmation threshold is set to 3. If the loop of executing a1 - a6 is continuously performed three times, the loop will no longer be executed and the subsequent steps will be executed;
[0199] Otherwise, based on the enhanced P wave position label, loop and implement steps a1 - a6;
[0200] a8: Denote the finally obtained P wave position label as: the to - be - filtered label;
[0201] a9: Preset a noise filtering threshold Nos; the noise filtering threshold Nos = 0.2;
[0202] Traverse the to - be - filtered label to find all continuous segments of 1s, denoted as: P wave segments;
[0203] Calculate the average height h of the corresponding electrocardiogram data signal for each P wave segment, and compare h with Nos;
[0204] If there exists h < Nos, reset all 1s in the corresponding P wave segment to 0;
[0205] In this embodiment, if the average height h of the electrocardiogram data signal > Nos, execute step a10;
[0206] a10: Output the finally obtained P wave position label as the final result of the optimization processing operation;
[0207] In this embodiment, that is Figure 12The final output result is shown below. Because the data in this embodiment is relatively short, there are fewer items that need optimization. In actual work, the collected ECG data to be identified is much longer, and there may be all items that need optimization. In specific execution, among the optimization items in steps a2 to a9, if there is data that needs optimization, then optimization is performed; if not, it is skipped, and the next item is executed.
[0208] like Figure 7 In Example 2 shown, Figure 7 The data corresponding to the electrocardiogram curve in the figure are used as the electrocardiogram data to be identified, and the actual P wave position is shown in the figure as the actual result.
[0209] Based on this method Figure 7 The graphs corresponding to the P-wave position labels obtained after identifying the electrocardiogram curves are the images marked as predicted results in the figure. Comparing the actual results and predicted results corresponding to the "electrocardiogram curves" shows that the accuracy of this method's identification results is extremely high.
[0210] After using the technical solution of this invention, the morphology of the P wave is randomly adjusted by the function X_random to prevent data overfitting and ensure that this method is applicable to P wave recognition in ECGs of various leads and various populations. This method generates a training dataset to simulate different types of diseases. Because the location of the P wave and the waveform before and after it differ under different diseases, the desired ECG waveform can be generated according to rules, solving the problem of different P wave morphologies in different populations at different times. When generating the training dataset, noise is added to simulate the noise present in real ECGs, effectively solving problems such as P wave recognition failure caused by noise interference. This method uses an encoder-decoder pattern to construct a data validator to verify the data in the ECG signal set to be verified, ensuring that the data in the generated training dataset conforms to the standards of actual ECGs and can achieve the purpose of simulating the ECG of a specific person. The waveforms of ECGs of different people are different. Encoder-decoder verification can simulate the ECG of a specific person, ensuring the effectiveness of the training dataset, thereby ensuring effective training of the recognizer and ensuring the accuracy of the recognizer's recognition results.
Claims
1. A machine learning-based electrocardiogram P-wave recognition method, characterized by, It comprises the following steps: S1: based on historical data, collecting original electrocardio signal data, filtering out interference noise in the original electrocardio signal data, obtaining effective electrocardio signal data; S2: segmenting each of the effective electrocardio signal to obtain P wave, QRS wave and T wave, and constituting PQRST signal set; S3: randomly adjusting each waveform signal in the PQRST signal set through a random adjustment function to obtain an adjusted signal set; The random adjustment function X_random is: X_random=f(X,length_X,length_random)*a Wherein, X is the original waveform, f(X) function is a linear interpolation function, length_X is the width of the original waveform X, length_random is a random number representing the target width; a is a random number; S4: randomly taking various types of waveform signals from the adjusted signal set, splicing electrocardiogram signals according to preset electrocardio signal waveform rules to obtain a spliced signal set; The electrocardio signal waveform rules include normal electrocardiogram rule, atrioventricular conduction block electrocardiogram rule and premature ventricular contraction electrocardiogram rule; S5: randomly adding simulated interference noise to each electrocardio signal data in the spliced signal set to obtain a to-be-verified electrocardio signal set; S6: constructing a deep learning network based on encoder-decoder, denoted as data verifier; S7: training the data verifier using real original electrocardio signal data to obtain the trained data verifier; The loss function used in training is: Wherein, x is the input waveform data, y is the output waveform data, and n is the waveform length; S8: preset a simulation threshold; S9: taking each signal data in the to-be-verified electrocardio signal set one by one, denoted as to-be-verified signal data; The to-be-verified signal data is sent into the trained data verifier for verification; In the verification process, if the loss function corresponding to the to-be-verified signal data is less than the simulation threshold, the to-be-verified signal data is judged as valid data and stored in the training data set; Otherwise, the to-be-verified signal data is judged as invalid and deleted; S10: constructing an identifier based on convolutional neural network; The output of the identifier is a p wave position label with the same waveform length as the input signal data, and the p wave position label is an identifier indicating whether the waveform at the corresponding position of the input signal data is a p wave; S11: training the identifier based on the training data set to obtain the trained identifier; S12: obtaining a to-be-identified electrocardio signal and sending the to-be-identified electrocardio signal into the trained identifier for identification; The p wave position label output by the identifier indicates that the waveform at the corresponding position of the to-be-identified electrocardio signal is a p wave; it further comprises an optimization processing operation, which arranges each p wave position label based on the optimization processing operation, specifically comprising the following steps: a1: 1 represents a p-wave label on the p-wave position label, and 0 represents a non-p-wave; Traverse the p-wave position label to confirm the position and number of 0 and 1 on the P-wave position label; a2: preset oscillation threshold N; Find all continuous 0 segments and 1 segments, count the number of continuous 0 and the number of continuous 1, and if it is greater than or equal to N, mark these segments as: smooth segments; Mark all segments outside the smooth segments as: oscillation segments; Confirm the number of 0 and 1 included in each of the oscillation segments respectively, if the number of 1 is greater than the number of 0, reset all 0 in the oscillation segment to 1, otherwise, reset all 1 in the oscillation segment to 0; Mark the reset p-wave position label as: smooth data label; a3: preset fixed threshold F; Traverse the smooth data label again, find all continuous 1 segments, and count the number of 1 in each segment, if the number of 1 is less than F, reset all 1 in the corresponding segment to 0; The sorted label is marked as: fixed data label; a4: preset interval threshold G; Mark all continuous 1 segments as: p-wave segments; Traverse the fixed data label again, find all continuous 0 segments between two p-wave segments, and mark them as: intermediate segments; a5: confirm the number of continuous 0 s0 included in each of the intermediate segments; If the intermediate segment exists, it meets: s0>G, then mark all the corresponding intermediate segments as: reconfirmation segments, then execute step a6; Otherwise, if all the intermediate segments meet s0≤G, execute step a8; a6: After performing enhancement operation on the heart beat data corresponding to the reconfirmation segment, replace the original data in the to-be-identified electrocardio signal, and input it into the trained identifier to perform secondary confirmation, mark the po-wave position label output by the identifier as: enhanced p-wave position label; a7: confirm the number of times of secondary confirmation in the identifier, if the number of times of secondary confirmation has met the preset secondary confirmation threshold, execute step a8; Otherwise, based on the enhanced p-wave position label, cyclically implement steps a1-a6; a8: mark the finally obtained p-wave position label as: to-be-filtered label; a9: preset noise filtering threshold Nos; Traverse the to-be-filtered label to find all continuous 1 segments, mark them as: p-wave segments; Calculate the average height h of the corresponding electrocardio data signal of each p-wave segment, and compare h and Nos; If there is h a10: the finally obtained p-wave position label is output as the final result of the optimization processing operation.
2. The method of claim 1, wherein the method is based on machine learning. The oscillation threshold N=10, the fixed threshold F=14, the enhancement threshold S=2, and the noise filtering threshold Nos=0.
2. 3.The machine learning based P-wave recognition method of electrocardiogram according to claim 1, characterized in that: In step S3, the value range of length_random is [length_X*0.9, length_X*1.1]; the value range of a is [0.9, 1.1].
4. The machine learning based P-wave identification method of electrocardiogram according to claim 1, characterized in that: The ECG waveform rule defines the waveform category and waveform order included in each category of ECG; The normal ECG rule and waveform order are as follows: n1: P wave: waveform generated by atrial contraction; n2: PR segment: time period between the end of P wave and the beginning of Q wave; interval is 0.12-0.2 seconds; n3: Q wave: start of ventricular depolarization; n4: R wave: main waveform of ventricular depolarization; n5: S wave: a small downward wave peak immediately following R wave; n6: ST segment: time period between the end of R wave and the beginning of T wave; duration is 0.08-0.12 seconds; n7: T wave: waveform of ventricular repolarization; represented as a small upward wave peak on ECG; duration is about 0.16 seconds; n8: TP segment: time period between the end of T wave and the beginning of P wave; duration is 0.2-0.4 seconds; The atrioventricular block includes first-degree atrioventricular block, second-degree atrioventricular block and third-degree atrioventricular block; specific rules are as follows: The first-degree atrioventricular block; in the first-degree atrioventricular block, there is a prolonged PR interval between P wave and QRS wave, but the form and interval of QRS waveform are normal; The second-degree atrioventricular block includes Mobitz type I and Mobitz type II; Mobitz type I: in this case, the PR interval between P wave and QRS wave gradually prolongs until the QRS waveform suddenly disappears; next, the interval between P wave and QRS waveform will restart, and the cycle continues; Mobitz type II: in this case, the PR interval between P wave and QRS wave remains relatively constant, but the QRS waveform suddenly disappears; in this case, the interval between P wave and QRS waveform is irregular; The third-degree atrioventricular block: in this case, the relationship between P wave and QRS wave is completely disconnected, so that a regular PQRST waveform interval cannot be formed; The ECG of premature beat includes premature beat and ventricular tachycardia: The ECG rule of premature beat: P wave appears randomly; and if P wave appears, the PR interval between P wave and QRS waveform is usually shorter than the normal value; The ECG rule of ventricular tachycardia: there is no P wave.
5. The machine learning based P-wave identification method of electrocardiogram according to claim 1, characterized in that: The simulated interference noise includes Gaussian noise.
6. The method of claim 1, wherein: In step S1, the method for filtering out interference noise in the original ECG signal data includes: A band-pass filter of 0.5 HZ to 50 HZ is used to filter out interference noise in the original ECG signal data.
7. The method of claim 1, wherein the method is based on machine learning. Cross-entropy is used as Lossfunction in the identification process of the identifier. 8.The method of claim 1, wherein: The enhancement operation in step a6 is that the heart beat data corresponding to the re-confirmation segment are multiplied by a preset enhancement threshold S, respectively.
Citation Information
Patent Citations
An electrocardiogram classifying method based on a deep learning algorithm
CN106108889A
Electrocardiogram classification method based on deep learning algorithm
CN106214145A