An ECG data classification method based on RNN and Mamba sequence model

By combining RNN, Mamba sequence model and frequency domain transformation method, the time-frequency domain features of ECG data are extracted and fused, which solves the problem of traditional models' insufficient ability to capture ECG data features and achieves higher classification accuracy and arrhythmia detection effect.

CN119807853BActive Publication Date: 2025-10-24HANGZHOU DIANZI UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510095407.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2025-10-24
Estimated Expiration
2045-01-21

AI Technical Summary

Technical Problem

Traditional deep learning models find it difficult to effectively capture the time domain and frequency domain features of ECG data at the same time, and the RNN and LSTM models are unable to capture long-term dependencies, resulting in inaccurate arrhythmia detection.

Method used

A method based on RNN and Mamba sequence model is adopted. The features of ECG data are extracted through Encoder and position encoding is added. The time domain features are extracted by combining RNN and Mamba sequence model. The frequency domain features are obtained through CWT and DFT transformation, and then fused into the time domain features. Finally, ResNetECG is used for classification.

Benefits of technology

The accuracy of ECG data classification is improved, and the long- and short-time dependence characteristics of ECG signals can be better captured, thereby improving the accuracy of arrhythmia detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807853B_ABST
    Figure CN119807853B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computer vision deep learning and medical data processing, in particular to an ECG data classification method based on RNN and Mamba sequence model, first, the original ECG data is encoded using an encoder to extract its preliminary features, and position coding is added.Next, on the one hand, based on the time sequence of ECG data, the time domain features of ECG data are extracted through RNN and Mamba module; on the other hand, based on the characteristics of ECG data wave, the frequency-time information and amplitude-frequency two kinds of frequency domain features are obtained from the ECG features through continuous wavelet transform CWT and discrete Fourier transform DFT; then the two kinds of frequency domain features are added to the time domain features to realize the enhancement effect of the time domain features.After that, a residual network ResNetECG is used to classify the enhanced time domain features.The present application improves the accuracy of the classification result.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer vision deep learning and medical data processing, and particularly relates to an ECG data classification method based on RNN and Mamba sequence model. BACKGROUND

[0002] ECG (electrocardiogram) data is the data of heart electrical activity recorded by electrodes on the skin, commonly used for monitoring the health of the heart and identifying abnormal rhythms, also applicable to arrhythmia detection. ECG signals usually include different waveforms (P wave, QRS complex, T wave, etc.), which reflect different electrical activity stages of the heart. Arrhythmia is a heart rhythm disorder caused by abnormal electrical activity of the heart, which can manifest as rapid, slow or irregular heartbeat. The severity of arrhythmia varies from harmless symptoms to potentially fatal heart problems, and research on abnormal detection of arrhythmia is of great significance.

[0003] Traditionally, arrhythmia detection relies on electrocardiogram examination, and doctors judge whether there is an abnormality by observing electrocardiogram waveforms to determine whether it is arrhythmia. Although manual analysis can accurately determine certain types of arrhythmia in electrocardiogram, this method is time-consuming and dependent on the experience of doctors, and is not suitable for processing large amounts of complex ECG data. With the increase of data and the improvement of computer performance, it is of great clinical value and necessity to use deep learning methods to study ECG data, because it can effectively process large amounts of complex data and extract key information, thereby improving the accuracy and efficiency of heart disease diagnosis and treatment.

[0004] ECG data contains important time domain and frequency domain features, but traditional deep learning models (such as convolutional neural network CNN, recurrent neural network RNN, etc.) usually cannot effectively capture both features at the same time. Most models only focus on time domain information, ignoring frequency domain features, which may lead to inaccurate detection of certain electrocardiographic events (such as abnormal rhythms). At the same time, ECG electrocardiogram signals have long-term dependencies (such as the timing relationship between different wave bands), but traditional RNN and LSTM models have insufficient long-term dependency capture ability, which may result in the model being unable to correctly identify abnormal signal patterns across multiple heartbeats. SUMMARY

[0005] In order to overcome the problem of insufficient long-term dependency capture ability of RNN and LSTM models, the present application proposes an ECG data classification method based on RNN and Mamba sequence model, which extracts and fuses the time-frequency domain features of ECG data, and then performs classification processing, thereby improving the accuracy of the classification result.

[0006] In order to achieve the above object, the technical scheme adopted by the present application is as follows:

[0007] An ECG data classification method based on RNN and Mamba sequence model, comprising the following steps:

[0008] S1, obtaining an ECG data set and labeling the data therein;

[0009] S2, using an Encoder encoder to construct a feature expression of the ECG signal and adding position encoding;

[0010] S3, extracting time domain features based on RNN and Mamba sequence model through a main branch;

[0011] S4, obtaining frequency domain features and enhancing time domain features through an auxiliary branch;

[0012] S5, classifying the enhanced time domain features based on ResNetECG.

[0013] Further, in the step S1, the ECG data set is a public data set downloaded from the PhysioNet website, and when labeling the data in the data set, a python script is used to realize the labeling, and the labeled data is saved in a json format file.

[0014] Further, in the step S2, the ECG signal is preliminarily processed based on the Encoder encoder to extract the preliminary features of the input signal and generate a latent feature representation, and then position encoding is added in the latent feature table to inject absolute or relative position information.

[0015] Further, in the step S3, the time domain features of the signal are obtained based on the time sequence of the ECG signal through the RNN and Mamba sequence model, the RNN module obtains the short-time dependent features of the signal and combines the short-time features between different time steps through the Self-Attention self-attention mechanism to obtain weighted short-time features; the Mamba module obtains the long-time dependent features of the signal by processing the weighted short-time features, which is equivalent to obtaining long-time dependent features based on short-time features, thereby obtaining a new time domain feature representation containing both short-time feature information and long-time feature information.

[0016] Further, in the step S4, the frequency-time information of the signal is obtained through the CWT continuous wavelet transform, the amplitude and frequency information of the signal is obtained through the DFT discrete Fourier transform, and the two different forms of frequency domain features obtained are fused into the time domain features obtained by the main branch at different time points by adding the corresponding element positions of the same size feature representations, thereby enhancing the time domain features.

[0017] Further, in step S5, the ResNetECG is used for the classification task, and the FC full connection layer is at the end of the network, and the number of nodes represents the number of categories of the ECG dataset.

[0018] The present application has the following characteristics and beneficial effects:

[0019] 1) The present application provides a time domain feature extraction method based on RNN and Mamba sequence model: the RNN sequence model obtains the short-time dependent features of the ECG signal and performs weighted combination between the time steps through the Self-Attention self-attention mechanism; and the Mamba module obtains the long-time dependent features of the signal on the basis of the short-time features, thereby obtaining a new time domain feature representation containing both short-time feature information and long-time feature information, and achieving a longer dependency effect than the LSTM model.

[0020] 2) The frequency domain features of the ECG signal are obtained through continuous wavelet transform and discrete Fourier transform, and they are used to enhance the previous time domain features: the frequency-time information of the signal is obtained through CWT continuous wavelet transform, and the amplitude and frequency information of the signal is obtained through DFT discrete Fourier transform; the two types of information extract the frequency domain features of the ECG signal through two branches, and they are integrated into the time domain features, thereby realizing the enhancement effect of the time domain features, so as to be better used for classification. BRIEF DESCRIPTION OF DRAWINGS

[0021] Figure 1 It is a flowchart of an ECG data classification method based on RNN and Mamba sequence model of an embodiment of the present application.

[0022] Figure 2 It is a whole network structure diagram of an embodiment of the present application.

[0023] Figure 3 It is a structure diagram of the RNN module and the Mamba module for extracting time domain features provided by the embodiment of the present application.

[0024] Figure 4 It is an effect display diagram before and after the continuous wavelet transform and the discrete Fourier transform for the embodiment of the present application.

[0025] Figure 5 It is an Encoder encoder and ResNetECG network structure diagram provided by the embodiment of the present application. DETAILED DESCRIPTION

[0026] The present invention is described in detail below in conjunction with specific embodiments. The following examples will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments can be combined with each other.

[0027] like Figure 1 As shown in FIG, an ECG data classification method based on RNN and Mamba sequence model includes the following steps:

[0028] S1. Obtain the data set and label the samples in it;

[0029] For the purposes of this paper, we used a public dataset downloaded from the PhysioNet website, namely the MIT-BIH Arrhythmia Database, which primarily consists of 48 30-minute, two-lead electrocardiogram (ECG) records sampled at 360 Hz. There are a total of 20 labels, and in the experiment we selected the five most common labels and all the remaining labels: N (normal beat), L (left bundle branch block beat), R (right bundle branch block beat), V (ventricular premature beat), A (atrial premature beat), and Other+ (all other 15 labels).

[0030] Since the original data set ECG signals and labels do not correspond one to one, data annotation is required. In the present invention, data annotation is implemented by writing a Python script file and saving the annotated data in a json format file.

[0031] S2. Construct the feature expression of the data through the Encoder encoder and add position encoding

[0032] The Encoder is used to preliminarily process the original ECG signal, extract the initial features of the input signal, and generate potential feature representations. Figure 5 As shown in the figure, the input ECG data size is (B, 3600, 1), where B represents the batch size, 3600 represents the time step, and 1 is the feature dimension under the time step. The first one-dimensional convolution layer has a kernel size of 7, a stride of 5, and a padding of 1. The second one-dimensional convolution layer has a kernel size of 5, a stride of 3, and a padding of 1. After convolution, batch normalization, and Relu activation, the input data changes from a size of (B, 3600, 1) to a size of (B, 240, 1). The purpose of the batch normalization layer BatchNorm1d is to standardize the data to speed up training. The Relu activation function transforms the linear mapping into a nonlinear mapping to enhance the diversity of features. At the same time, due to the characteristics of the Relu activation function itself, the gradient explosion is suppressed to a certain extent. The formula is:

[0033] y = Relu(BN(Conv(x)))

[0034] where Conv represents convolution operation, BN represents batch normalization operation, and Relu represents activation function.

[0035] According to the time sequence of the ECG data, there is a sequence between the time steps, and after the time steps are compressed by the above-mentioned Encoder (the time steps are changed from 3600 to 240), the sequence between the time steps disappears. In order to use the sequence information of the ECG signal, the absolute or relative position information is injected by adding the positional encoding in the feature representation. In the present application, the fixed positional encoding based on the sine function and the cosine function is used.

[0036] Suppose that the input ECG signal X has a size of (L, D), L represents the time step, and D represents the embedding dimension. The positional encoding uses the same shape of the position embedding matrix P to output X+P, and the elements in the i-th row and the 2j-th and 2j+1-th columns of the matrix are:

[0037]

[0038] where p i,2j ,p i,2j+1 respectively represent the encoding values at the i-th row and the 2j-th and 2j+1-th columns.

[0039] S3, obtaining the time domain feature of the signal based on the time sequence of the ECG signal through the main branch

[0040] The main branch is realized based on the RNN and the Mamba sequence model, and mainly consists of an RNN model, a Mamba model and a feature fusion module. The RNN model is used to obtain the short-time dependent feature of the signal and to combine the short-time features between the time steps through the Self-Attention self-attention mechanism to obtain the weighted short-time feature. The Mamba module obtains the long-time dependent feature of the signal by processing the weighted short-time feature, which is equivalent to obtaining the long-time dependent feature on the basis of the short-time feature, thereby obtaining a new time domain feature representation containing both the short-time feature information and the long-time feature information.

[0041] Specifically, as shown in Figure 3 and in combination with Figure 2The main branch (middle branch) structure of the RNN model is a multi-layer loop structure, and the number of layers is set as a hyperparameter, while the number of hidden units is set according to the complexity of the input data. According to the output result of the Encoder encoder, for the ECG signal of 240 time steps, the RNN model with 3 layers and 64 hidden units is used. In the unfolded structure diagram of the RNN model, x1, x2,...x n is the time step, is the hidden layer state, y1, y2,...y n is the output of the RNN model at each time step. After the RNN model, the input data changes from (B, L, D) to (B, H, L). Where B represents the batch size, L is the time step size of the signal, D is the input feature dimension, and H is the hidden layer size set in the RNN. RNN can remember the information of the previous time step through the hidden state h, and use this historical information to affect the output of the current time step. In this way, it can capture the time sequence dependence in sequence data, so as to extract the time sequence features of the ECG signal. The formula is as follows:

[0042] h t =tanh(W ih ·x t +W hh ·h t-1 +b n )

[0043] Where h t is the hidden state of the current time step, W ih is the input weight matrix acting on the input x t of the current time step, W hh is the loop weight matrix acting on the hidden state h t-1 of the previous time step. b h is the bias term. tanh is the activation function.

[0044] Self-Attention self-attention mechanism is the core module in Transformer, which establishes a relationship between different positions in the same sequence to help the model better understand long-distance dependencies. In the present invention, the self-attention mechanism is used to establish the relationship between different time steps of the input ECG signal and to perform weighted combination. The formula is as follows:

[0045]

[0046] Wherein, Q refers to Query query sequence, K refers to Key key sequence, V refers to Value value sequence.In the application, Q, K and V are all the same ECG signal sequence, Q and K obtain attention weight through calculation, and are multiplied with V to obtain a new sequence after considering context.Self-Attention learns how each time step is associated with other time steps through attention weight, dynamically adjusts weight, and generates new feature representation considering the relationship between different time steps.

[0047] The Mamba model is a sequence model, and its essence can also be regarded as an RNN cycle model.Different from the traditional RNN structure is that it realizes parallel computing through one-dimensional convolution operation during training, and uses SSM state space model during inference.SSM state space model is a model that maps input sequence x(t) to latent state representation h(t) and outputs predicted sequence y(t).The formula is as follows:

[0048] h'(t)=Ah(t)+Bx(t)

[0049] y(t)=Ch(t)+Dx(t)

[0050] Wherein, x(t) is the input sequence, h(t) is the latent state representation at any time t, and y(t) is the output sequence.A is the state transition matrix, B is the matrix of input sequence to state representation, C is the matrix of state representation to output sequence, and D is the matrix directly from input sequence to output sequence.The reason why the Mamba model can obtain long-time dependent information of the signal is that the A matrix is set.Through the use of HiPPO matrix, a latent state representation that can remember long history information is generated, and combined with the C matrix for transmission, thereby obtaining long-distance dependent information of the sequence (signal).

[0051] In combination Figure 3 It is illustrated that for the input sequence x, first, RMSNorm is used for normalization operation, and the dimension size of the sequence is changed through two linear mapping linear layers respectively, then one branch is processed through one-dimensional convolution conv1d, activation Silu and state space model SSM to obtain a latent state representation a;Another branch only passes through the Relu activation function to obtain another latent state representation b;Then, the multiplication of a and b is performed again through the linear layer mapping, thereby obtaining the output sequence y.The input sequence x and the output sequence y are the same size.

[0052] S4, obtain frequency domain features through auxiliary branch and enhance time domain features

[0053] Based on the characteristics of ECG data waves, the frequency-time information of the ECG signal is obtained through CWT continuous wavelet transform, and the amplitude and frequency information of the ECG signal is obtained through DFT discrete Fourier transform; then, the frequency-time information and the amplitude and frequency information are integrated into the time domain features obtained by the main branch, thereby achieving an enhancement effect on the time domain features. Specifically:

[0054] like Figure 4 As shown, continuous wavelet transform CWT is a process of decomposing a signal into wavelet basis functions of different frequency bands (scales), which can provide localized information in frequency and time and is suitable for processing ECG signals. The principle is to obtain a coefficient matrix at each scale by performing scale changes (diffusion or contraction) and displacement (temporal translation) on the wavelet function. This matrix contains the characteristics of the signal in different frequency ranges. Each layer of the feature matrix represents a different frequency size, and different frequencies are assigned different weight coefficients through the channel attention SENet module, thereby obtaining a frequency-time feature with more reference significance. In the present invention, the input ECG data size is (B, 240, 1), and after CWT transformation, a data matrix of size (B, 64, 240) is obtained, and then different weight coefficients are assigned to different channels (64 represents the number of channels) through SENet, thereby obtaining a new frequency domain feature.

[0055] like Figure 4 As shown, the discrete Fourier transform DFT decomposes the input ECG signal into a weighted sum of sinusoidal waves of different frequencies. That is, assuming you have a discrete sequence signal x[n] of length N, DFT converts this signal to the frequency domain to obtain its amplitude and phase information at different frequencies. Combining the amplitude and phase information can obtain the amplitude at different frequencies, thereby obtaining the corresponding relationship between amplitude and frequency. In the present invention, the input ECG data size is (B, 240, 1) and after DFT transformation, two vector features of equal size are obtained, namely the amplitude vector and frequency vector of size (240,). After that, after fusion (weighted summation) operation, the amplitude and frequency information are contained in each time step, which also obtains a new frequency domain feature.

[0056] The two different forms of frequency domain features obtained above are integrated into the time domain features obtained by the main branch at different times by adding the corresponding element positions of the features represented by the same size, thereby achieving the effect of enhancing the time domain features.

[0057] 2. Classification based on ResNetECG network

[0058] ResNetECG is a residual network for classification task, the end of the network is a FC full connection layer, the number of nodes represents the number of classes of ECG dataset, that is, the enhanced time domain features are classified through the network.

[0059] As shown in Figure 5 The known input data size is (B, 1, 240, 64), where B represents batch, 1 represents channel number, and the size is 240x64. The first convolutional layer is the input layer, which aims to extract low-level features. A two-dimensional convolution with a larger convolution kernel (7x7) and a step of 2 is performed, followed by BatchNorm2d batch normalization and Relu activation function, and finally the feature representation suitable for input into the ResNet residual block is obtained. Then the residual block structure is followed. The residual structure has a total of 4 residual blocks, and multiple residual blocks are used to extract deeper features step by step. The difference between the residual blocks is the number of channels, which are 64, 128, 256, and 512 in turn. Each residual block is composed of two convolutional layers, a batch normalization layer (Batch Normalization), an activation function (ReLU), and a residual connection. Each residual block first performs convolution operation, then batch normalization and activation, and finally adds the input to the convolution output. In the residual connection, in order to ensure that the feature representations under different branches can be added, a convolution operation with a convolution kernel of 1x1 and a batch normalization operation are added in the shortcut branch. After the residual structure, GlobalAveragePooling2D is used for global average pooling to compress the spatial dimension of each feature map into a single value. The last structure is a simple full connection layer linear, which also represents the output layer. The role is to combine the features obtained after convolution and pooling through the full connection layer, and finally map to the target class. In the present application, the output class is 6.

[0060] Before using the RNN and Mamba-based sequence model of the present application for model training, some hyperparameters need to be set, which are as follows: batch size is 20, initial learning rate is 0.001, learning rate decay period is 30, GPU is used for training, data set input path, model training result saving path, etc. The deep learning method of the present application is realized based on the pytorch framework, and the tool is the integrated development environment pycharm. The experiment is carried out on a single GPU, and the operating system is Ubuntu.

[0061] Through experiments, the classification results are shown in Table 1.

[0062] Table 1

[0063] Epochs Training set accuracy Test set accuracy 50 96.9457 96.4699 100 97.3178 96.9907

[0064] From the accuracy values of the training set recorded in Table 1, it can be seen that the method extracted by the application can realize the classification of ECG data, and the accuracy values of the test set recorded in Table 1 show that this method has excellent classification performance and can correctly classify most of the ECG data.

[0065] The above shows and describes the basic principles, main features and advantages of the present application. Those skilled in the art should understand that the present application is not limited to the above-mentioned embodiments, and the above-mentioned embodiments and descriptions in the specification are only preferred examples of the present application and are not intended to limit the present application. Without departing from the spirit and scope of the present application, various changes and improvements can be made to the present application, and these changes and improvements all fall within the scope of the claimed application. The scope of protection of the present application is defined by the appended claims and their equivalents.

Claims

1. An ECG data classification method based on RNN and Mamba sequence model, characterized in that, Comprising the following steps: S1, obtaining an ECG data set and labeling the data therein; S2, using an Encoder encoder to construct a feature representation of the ECG signal and adding position encoding; S3, extracting time domain features through a main branch based on an RNN and a Mamba sequence model; Through the RNN and the Mamba sequence model, the time domain features of the signal are obtained based on the time sequence of the ECG signal, the RNN module obtains the short-time dependent features of the signal and performs weighted combination between the time steps through the Self-Attention self-attention mechanism to obtain weighted short-time features; the Mamba module obtains long-time dependent features of the signal by processing the weighted short-time features, thereby obtaining time domain feature representations containing both short-time feature information and long-time feature information; S4, obtaining frequency domain features and enhancing time domain features through an auxiliary branch; The frequency-time information of the signal is obtained through CWT continuous wavelet transform, the amplitude and frequency information of the signal is obtained through DFT discrete Fourier transform, and the obtained frequency-time information, amplitude and frequency information are fused into the time domain features obtained by the main branch at different time points by adding the corresponding element positions of the features with the same size, thereby enhancing the time domain features; S5, classifying the enhanced time domain features based on ResNetECG, The ResNetECG is used for classification tasks, and the end of the network is an FC full connection layer, and the number of nodes represents the number of classes of the ECG data set.

2. The ECG data classification based on the RNN and the Mamba sequence model according to claim 1 A method, characterized in that In step S1, the ECG data set is a public data set downloaded from the PhysioNet website, and the data in the data set is labeled through a python script.

3. The ECG data classification based on the RNN and the Mamba sequence model according to claim 1 A method, characterized in that In step S2, the Encoder encoder is used to preliminarily process the ECG signal, extract the preliminary features of the input signal, generate latent feature representations, and then add position encoding to the latent feature table to inject absolute or relative position information.

Citation Information

Patent Citations

  • Industrial internet prediction method and system based on frequency domain and long and short term feature fusion

    CN115907154A

  • Bearing diagnosis method and system based on variable working condition multi-modal data fusion

    CN118332488A