MSCA-TNet based deep learning method for ECG arrhythmia classification Authors: Songjian Huang, Senpeng Chen, Zihao Guo, Kaiming Ji, Miao Zhang Published: 2026 ABSTRACT AbstractElectrocardiography (ECG) is a widely adopted modality for monitoring cardiac rate and rhythm and identifying various abnormalities of the cardiac electrical system. Research on ECG preprocessing and intelligent classification is vital for the early diagnosis and clinical management of cardiovascular diseases and helps improve the accuracy and efficiency of cardiac diagnosis. Nevertheless, ECG signals captured by wearable acquisition devices frequently suffer from poor signal quality due to subject motion and uncontrolled acquisition environments. Furthermore, native ECG waveforms are faint and susceptible to diverse noise interference. To diagnose noise-corrupted arrhythmia, clinicians need to inspect lengthy ECG recordings relying on professional expertise, which is tedious, labor-intensive and prone to subjective bias. Another critical challenge lies in severe class imbalance within public ECG datasets, resulting in degraded classification performance for minority arrhythmia categories. Accordingly, developing robust automated arrhythmia detection algorithms is essential to ease the diagnostic workload of clinical practitioners. In this work, discrete wavelet transform (DWT) is adopted for noise elimination, and the SMOTE-Tomek hybrid resampling strategy is applied to mitigate class imbalance on the MIT-BIH and INCART datasets. We further propose MSCA-TNet, a hybrid architecture embedding the adaptive channel attention (ACA) module and Transformer to extract both local fine-grained features and global long-range contextual information from ECG sequences. The ACA module dynamically modulates channel-wise feature weights to emphasize clinically discriminative features while suppressing irrelevant components. On the two benchmark datasets, the proposed model yields macro-average accuracies of 93.97% and 98.79%, alongside overall accuracies of 98.88% and 99.47%.Keywords: ECG classification, Arrhythmia detection, Transformer, Attention, Deep learningSubject terms: Cardiology, Computational biology and bioinformatics, Engineering, Health care, Mathematics and computing Introduction The diagnosis of arrhythmia typically depends on the identification of normal and abnormal individual heartbeats on the electrocardiogram (ECG)1, as well as accurate annotation based on the morphology of the ECG. According to the Association for the Advancement of Medical Instrumentation (AAMI)2, non-life-threatening arrhythmias can be categorized into five major classes: normal non-ectopic (N), supraventricular ectopic (S), ventricular ectopic (V), fusion (F), and unknown (Q). The ECG is a commonly used method for monitoring heart rate and rhythm3, and it can detect various abnormalities in the cardiac electrical system. Research on the preprocessing and classification techniques of ECG signals is vital for early diagnosis and treatment of heart diseases and improves the accuracy and efficiency of clinical diagnosis. ECG signals are non-linear and non-stationary, with an amplitude range of 10 μV to 4 μmV and a frequency range of 0.67 Hz to 120 Hz4. A typical cardiac cycle in an ECG includes the P wave, QRS complex, and T wave5, among which the T wave and P wave have relatively small amplitudes. Common morphological features include the RR interval, PR interval, P wave duration, QRS duration, T wave duration, and QT interval6, as shown in Fig. 1. ECG waveform showing key features (P wave, QRS complex, T wave) and intervals (RR, PR, QT). In the field of ECG signal classification, an increasing number of ECG denoising7 and classification methods have been proposed in recent years8–10. Convolutional Neural Networks (CNNs) and Long Short-Term Memory networks (LSTMs) have been proven highly effective for arrhythmia detection and classification. Ahmed A A et al.11 proposed a classification model comprising three 1D CNN blocks for arrhythmia classification using ECG lead II signals. Reddy S D12 used a low-pass filter (LPF) and a two-stage median filter to eliminate signal artifacts and extract features effectively. They also proposed a Sampled Vector Random Forest Classifier (SVRF), which alleviates noise sensitivity in multi-class classification and improves classification accuracy. For instance, some studies have incorporated self-supervised learning frameworks, adopting unsupervised pre-training to reduce dependence on labeled data and fine-tuning the model for downstream classification, which significantly boosts detection performance for rare arrhythmias13. Other studies improve model generalization and robustness by combining wavelet threshold denoising with dynamic feature fusion to unify feature extraction and classification14. Khorrami H15 used DCT coefficients for ECG feature extraction. In addition, they employed Continuous Wavelet Transform (CWT) and Discrete Wavelet Transform (DWT) for feature acquisition and compared the classification performance of DCT, CWT, and DWT. Shikha Singhal and Manjeet Kumar16 proposed a multi-level arrhythmia classification method combining Group Sparse Mode Decomposition (GSMD) and Super-Resolution Spectral Transform (SRST). This method first decomposes non-stationary ECG signals into Intrinsic Mode Functions (IMFs) via GSMD, then applies super-resolution algorithms to generate IMF-related frequency-domain spectrograms, and finally adopts the Superlet Transform (SLT) to convert 1D ECG waveforms into 2D feature representations. Kim Y K17 proposed an arrhythmia classification framework combining ResNet with Squeeze-and-Excitation (SE) blocks and Bidirectional Long Short-Term Memory (BiLSTM). He Yuhang18 proposed a multi-label ECG classification model based on attention mechanisms and Graph Convolutional Networks (GCN), named MLECG-AGCN. An attention-augmented CNN improves the utilization of high-frequency components, while the embedded GCN makes full use of global information and neighborhood feature distribution to facilitate sample classification and raise prediction accuracy. Cheng Y et al.19 proposed a deep-learning-based intelligent analysis framework for 12-lead ECG named LFG-Net, which selects high-contribution lead features via the Shapley Additive exPlanations (SHAP) method. Model training is optimized by minimizing the loss discrepancy between screened features and classification outputs. Chen C Y et al.20 proposed a multi-channel multi-scale deep neural network that realizes end-to-end ECG classification without manual feature engineering. In terms of deep-learning-based feature extraction, several studies resort to multi-modal fusion strategies. Yuan Chengcheng et al.21 put forward an ECG classification model integrating Residual Networks (ResNet) and self-attention mechanisms. ResNet builds deep convolutional layers to capture local features and mitigate gradient degradation, whereas the Self-Attention Bi-directional Gated Recurrent Unit (ABiGRU), constructed by embedding self-attention into BiGRU, strengthens the modeling and classification of temporally correlated features. Although existing machine learning and deep learning methods have achieved promising classification results for arrhythmia, the booming development of wearable ECG monitoring accelerates the advancement of convenient, efficient and intelligent long-term ECG recording, creating new prospects for early cardiovascular screening and computer-aided diagnosis. To satisfy such practical requirements, this work focuses on three core tasks: ECG signal denoising, alleviation of arrhythmia class imbalance, and development of a high-performance classification model. The proposed MSCA-TNet achieves outstanding performance in multi-scale feature extraction and long-range dependency modeling and enables precise automated ECG arrhythmia classification. Compared with existing hybrid models combining CNN, attention mechanism and Transformer for ECG classification, MSCA-TNet possesses three distinct innovations. First, an adaptive channel attention module is designed. By fusing identity mapping, attention weight matrix and learnable parameter matrix, the module achieves targeted enhancement of low-amplitude minority-class features such as weak P waves of S-type arrhythmia, overcoming the drawback of conventional attention modules in capturing subtle waveform characteristics. Second, a hybrid feature extraction framework consisting of multi-scale convolution and dual-input contextual Transformer is established. Multi-scale convolution extracts local morphological features of P/QRS/T waves across different temporal scales, while the dual-input Transformer realizes bidirectional contextual perception via stacked original and flipped feature sequences, remedying the poor long-range dependency modeling capability of traditional BiLSTM for cardiac rhythm signals. Third, a joint preprocessing framework integrating DWT denoising and SMOTE-Tomek resampling is constructed to suppress background noise and mitigate class imbalance simultaneously. Unlike previous studies that address noise removal or class imbalance separately, the proposed strategy jointly optimizes signal quality and sample distribution. Benefiting from the collaborative design of the above modules, MSCA-TNet delivers precise ECG classification, elevates the identification accuracy of minority arrhythmia subgroups, and improves the clinical interpretability of intelligent ECG diagnosis. Methods The proposed MSCA-TNet is specially designed for automatic ECG signal classification.Overall, the detailed architecture of the proposed MSCA-TNet is shown in Fig. 2. the model follows a clear multi-stage processing pipeline.First, raw ECG signals undergo standardized preprocessing, including wavelet denoising, heartbeat segmentation, and amplitude normalization, to suppress background interference and unify input data distribution.Second, multi-scale convolutional layers are adopted to extract local morphological features of ECG waveforms at different temporal resolutions, effectively capturing characteristic variations of the P wave, QRS complex, and T wave.Third, the designed Adaptive Channel Attention module adaptively recalibrates channel-wise feature weights, strengthening the representation of weak and minority-class waveform features that are easily obscured by noise.Thereafter, the dual-input contextual Transformer module models long-range temporal dependencies and bidirectional contextual relationships within ECG sequences, compensating for the limited long-distance modeling capability of traditional recurrent networks.Finally, the fused high-dimensional features are fed into a Softmax classifier to output category probabilities for arrhythmia identification.By integrating multi-scale convolution, adaptive channel attention, and contextual Transformer modules, MSCA-TNet achieves effective fusion of local morphological features and global long-range temporal dependencies, offering a reliable and high-precision solution for intelligent ECG arrhythmia diagnosis. Overall architecture of MSCA-TNet for ECG classification. Dataset The dataset used in this study is the MIT-BIH Arrhythmia Database22. The dataset contains excerpts of 48 half-hour, two-channel ECG recordings from 47 subjects who were part of the BIH Arrhythmia Laboratory research from 1975 to 1979. Among them, 23 recordings (the “100 series”) were randomly selected from over 4,000 Holter monitor tapes to reflect the arrhythmia conditions of the general population. The other 25 recordings (the “200 series”) were carefully chosen to include uncommon but clinically significant types of arrhythmias. The recordings were digitized at a sampling rate of 360 samples per second per channel. Multiple cardiologists independently annotated each record, and disagreements were resolved to obtain computer-readable reference annotations for each beat, with a total of approximately 110,000 annotations23. This study aims mainly to classify ECG signals into five major categories: Normal non-ectopic (N), Supraventricular ectopic (S), Ventricular ectopic (V), Fusion (F), and Unknown (Q). The specific classification is shown in Table 1. Table 1Types of heartbeats present in the MIT-BIH database based on AAMI.CategoryTypeNNormal beat (N)Left bundle branch block beat(L, R)Atrial escape beat(e)Junctional escape (j)SAtrial premature beat (A)Atrial premature beat with conduction (a)Junctional premature beat (J)Supraventricular premature beat (S)VVentricular premature contraction (V)Ventricular escape (E)FFusion of ventricular and normal beat (F)QPacemaker beat (/)Fusion of pacemaker and normal beat (f)Unclassifiable beat (U) Types of heartbeats present in the MIT-BIH database based on AAMI. Pre-processing The ECG signals were segmented and R-peak information was extracted24. One complete heartbeat consisting of 180 sampling points is intercepted to cover the P-QRS-T complex as well as the preceding and succeeding baseline segments. Since ECG recordings are frequently corrupted by different types of noise, denoising is implemented to facilitate subsequent arrhythmia classification. In this study, the Daubechies 5 (db5) wavelet with five-level decomposition and soft thresholding is adopted for ECG denoising. The processed ECG beats are grouped into five categories: Normal (N), Supraventricular Anomaly (S), Ventricular Anomaly (V), Fusion (F), and Unknown (Q). Notably, the MIT-BIH Arrhythmia Database23 suffers from severe class imbalance: normal beats account for the vast majority, whereas clinically important arrhythmia samples such as ventricular anomalies are scarce. Such imbalance tends to degrade model performance on minority categories and raise misdiagnosis rates. To fundamentally avoid data leakage and ensure experimental rigor, this study strictly restricts oversampling operations to the training set only. A subset of training samples is split out to form the validation set. After each training epoch, model performance is assessed on the validation set to track training trends and tune hyperparameters. The raw dataset is randomly split into training, validation and test subsets at proportions of 65%, 15%, and 20%, respectively. Among them, 65% of all samples are used for model training, 15% for validation, and the remaining 20% for final testing. To alleviate dataset imbalance, SMOTE-Tomek25 is adopted in this work. After dataset partitioning, minority samples belonging to classes S and F within the training set are oversampled to 50000 samples per category. The whole SMOTE-Tomek resampling pipeline is exclusively executed on the training set, which helps boost model performance on imbalanced data. By simultaneously augmenting minority samples and pruning noisy borderline samples, the model’s generalization is effectively improved. The test set is kept untouched during the entire training procedure and utilized solely in the final evaluation to verify generalization on unseen real-world samples. Model Multi-scale convolution Multiscale convolution differs from traditional CNNs, which generally adopt fixed-size convolutional kernels and thus extract only single-scale features. This limitation hinders the processing of complex time-series data. Owing to their fixed receptive fields and single-scale feature extraction mechanism, traditional CNNs cannot simultaneously capture local details and global information. Expanding their receptive fields usually requires additional convolutional layers or pooling operations. In contrast, multiscale convolution utilizes multiple kernels with different sizes to perform parallel convolution on feature maps. For complex time-series signals, small kernels capture short-term fine-grained details, while large kernels model long-term temporal trends. This multi-scale modeling strategy reduces information loss and enables comprehensive integration of sequential signal features. The structure of the adopted multi-scale convolution module is illustrated in Fig. 3. four convolution kernels with sizes of 3 × 1, 5 × 1, 7 × 1, and 9 × 1 are employed for parallel feature extraction. The features generated by different kernels are concatenated to form the final multi-scale feature output. Structure of multi-scale convolution layer for ECG feature extraction. ACA channel attention Channel attention has proven effective for automated ECG classification. Multi-lead ECG is extensively used in clinical examinations and wearable monitoring systems. each lead captures unique cardiac activity via limb and chest electrodes. Channel attention automatically highlights diagnostically informative lead features related to arrhythmia and other cardiac abnormalities. Since raw ECG is frequently corrupted by respiratory noise, motion artifacts and hardware interference, the mechanism suppresses useless irrelevant components and concentrates on clinically relevant waveforms to raise classification accuracy. Facing inherent dataset imbalance in ECG tasks, our ACA module specially strengthens minority-class feature representation. Combined with the SMOTE-Tomek resampling strategy mentioned above, it substantially promotes the model’s performance on imbalanced ECG data. Inspired by the work of Xiang et al.26, our ACA module first compresses features along the sequence dimension to calculate attention matrix via convolution and Softmax. The final attention weight matrix is constructed by fusing identity mapping , learned attention matrix and trainable parameter matrix . Input feature is element-wisely multiplied with for adaptive feature recalibration, which amplifies vital diagnostic features and attenuates useless noise-related information. Subsequent convolution layers recover the original channel dimension and output weighted feature maps. The ACA module improves the network’s ability to locate discriminative ECG features and lifts overall classification accuracy. The architecture of the proposed ACA module is shown in Fig. 4. Adaptive channel attention module. Different from traditional SE or ECA attention modules , ACA achieves precise enhancement of weak ECG features (such as P-waves in class S) by fusing the identity matrix, attention weight matrix, and learnable parameter matrix, solving the problem that traditional attention mechanisms insufficiently capture minority-class features. Dual-input contextual transformer The Dual-Input Contextual Transformer structure combines the powerful feature extraction capabilities of the Transformer27 with the advantages of bidirectional information flow. The attention mechanism in the Transformer is extended to multiple self-attention heads, each of which can learn different attention weights, thereby enabling the capture of long-range dependencies and complex patterns in the data. ECG signals are complex time-series data, and the Dual-Input Contextual Transformer is capable of capturing long-range dependencies and local features within ECG signals. For example, it can identify important features in ECG signals such as theP wave, QRScomplex, andT wave. Unlike traditional bidirectional processing on sequences and the Bi-Transformer proposed by27, which inputs the original feature map and its reversed version into the model separately and then adds the results, the Dual-Input Contextual Transformer works differently. It superimposes the original feature map and its reversed version and then processes them through the same Transformer. This essentially simulates a bidirectional contextual understanding, allowing it to better handle ECG signals of varying lengths and complexities. It also enhances the model’s generalization ability across different datasets. Bidirectional information fusion enables a more comprehensive understanding of the contextual information in ECG signals, thereby improving the accuracy of ECG signal classification. Although an ECG heartbeat is a short sequence, its rhythm characteristics (such as RR intervals and the temporal relationship between P waves and QRS complexes) involve discontinuous long-range dependencies. Traditional BiLSTM captures temporal dependencies through gating mechanisms, whose receptive field grows linearly with sequence length, resulting in limited ability to model discontinuous long-range correlations.In contrast, the self-attention mechanism in Transformer can capture dependencies across all positions of the feature sequence in parallel. Combined with the dual-input context design proposed in this study, it enables a more comprehensive understanding of the bidirectional temporal context of ECG signals and accurately captures the global rhythm characteristics of heartbeats.Subsequent module replacement experiments will further provide a quantitative comparison with BiLSTM to verify the performance superiority of Transformer, demonstrating that the increase in model complexity yields clear performance gains (Fig. 5). Multi-head attention. The multi-head attention mechanism is a core component of the Transformer model. It allows the model to learn information in parallel across different representation subspaces. By executing multiple “heads” (i.e., multiple independent attention mechanisms) in parallel, each head learns different aspects of the input data. This approach can capture a variety of relationships between different positions in a sequence.In the figure, Q(Query) represents the query vector, which indicates the information that currently needs to be focused on. K (Key) represents the key vector, which indicates the features of each element in the sequence. V(Value) represents the value vector, which indicates the actual information of each element in the sequence. For each head, the result of the concatenation of input X and is used as Q, K, and V, that is, . First, linear transformations are applied to Q, K, and V to generate the specific representations for each head. Here is the dimension of the key vector. After concatenating the outputs of all heads, a linear transformation is applied to integrate the information from different heads. The output vector after the linear transformation contains the information of each element in the sequence, with weights determined by the multi-head attention mechanism. Here is a learnable weight matrix. The implementation code of the MSCA-TNet framework has now been open-sourced. (Project URL: https://doi.org/10.5281/zenodo.20542420). This code repository not only contains the complete implementation of the modules proposed in the paper, but also provides pre-trained model weights that have been trained on the MIT-BIH and INCART datasets. Developed using the PyTorch framework, the code supports GPU acceleration, and its modular design facilitates functional expansion. Researchers can develop new ECG analysis algorithms based on the existing architecture. Training hyperparameter settings The model is trained using the Adam optimizer with a learning rate of 0.001, weight decay of 0.0001, and momentum parameters and . Cross-entropy loss is employed as the loss function. Training is performed for up to 60 epochs with an early stopping strategy. Training is terminated if the validation accuracy does not improve for 15 consecutive epochs. The batch size is set to 128. All experiments are implemented in the PyTorch framework with an NVIDIA RTX 4090 GPU. Dropout regularization with a dropout rate of 0.2 is applied to mitigate overfitting. Result To evaluate the model’s performance, facilitate the comparison of classification results, and explore optimization strategies, this paper delved into the model’s ability to accurately classify electrocardiogram (ECG) arrhythmias by examining the accuracy, recall, and macro-average F1 score for each category. The specific formulas are shown below: After training and testing, the proposed model in this study achieved relatively excellent classification performance on the MIT-BIH Arrhythmia Database. The results are shown in Table 2 and Fig. 6. . Table 2ECG test results for various categories.ClassPrecision (%)Recall (%)F1-score (%)ACC (%)Macro-F1(%)N99.5999.2199.40S86.2593.3889.67V97.8897.0697.4798.8893.97F76.1993.5783.99Q99.3899.2099.29 ECG test results for various categories. Confusion matrix of model prediction. The table shows that the five categories achieved an accuracy rate of 98.88%, with good performance in precision and F1 scores, especially for categories N and Q, which both have accuracy rates above 99% and F1 scores above 99%. The macro-average F1 score was 93.97%, which is the average of the F1 scores of all categories without considering the number of samples in each category. This value indicates that the model has good performance across all categories. However, categories S and F had fewer samples in the original dataset. Even though we performed oversampling to increase the number of these two categories, their classification performance still needs improvement. This is also the low accuracy problem of category F that many studies are working hard to solve, and future efforts are needed to improve the prediction accuracy of category F. Discussion To evaluate the performance of MSCA-TNet, this study compares it with recently published arrhythmia classification models, and the results are presented in Table 3 . The proposed MSCA-TNet achieves competitive performance with an ACC of 98.88% and a Macro-F1 of 93.97%,which compares favorably with existing studies . It should be specifically noted that strict fair controlled variable comparison cannot be achieved by directly citing results from different literatures, due to discrepancies in experimental settings such as data partitioning, preprocessing, and class balancing strategies. Therefore, this study adopts internal ablation experiments and module replacement comparison experiments to verify the necessity and superiority of each core module under a completely consistent experimental environment. This avoids conclusion bias caused by differences in external conditions and more rigorously demonstrates the effectiveness of the proposed model design. Table 3Comparison of model performances.AuthorsYearMethodsACC (%)Macro-F1 (%)Gopik et al.282020RCNN94.2594.00M.Hammad et al.292021ResNet+LSTM+GA98.0089.70T.Pokaprakam et al.302022Seq2Seq+CRNN97.6089.00Bhatia S et al.312022CNN+BiLSTM89.4091.67Khan F et al.3220231-D ResNet98.6392.63Nemissi M et al.3320241D-CNN + Temporal Feature98.7893.58Oubadi et al.342024GAN+LSTM94.7493.00Wu et al.352024SC-RGA Transformer95.7082.60This work2025MSCA-TNet98.8893.97 Comparison of model performances. Module validity verification experiments To verify the effectiveness and contribution of each core module in the proposed ECG classification model,this study designs two validation experiments: ablation experiments and module replacement comparison experiments.Ablation experiments use the full model as the baseline and construct variants by removing core modules one by one to verify the necessity of each module.Module replacement experiments focus on replacing key modules with functionally similar ones to verify the superiority of the adopted modules.All experiments are conducted on the MIT-BIH database with exactly the same training settings as the baseline model, including epochs, learning rate, batch size, and oversampling strategy.With ACC and Macro-F1 as the main evaluation metrics, the performance differences between various variants and the baseline model are comparedto verify the necessity and effectiveness of each module. Ablation experiment design Ablation experiments strictly follow the single-variable principle, where only one core module is removed at a time to ensure the comparability of experimental results. Combined with the model structure, the specific ablation scheme is as follows: the preprocessing pipeline (denoising, segmentation, normalization) and the Softmax classification layer are retained unchanged, while only the target core module is removed. All experimental results are reported as the average of 5 repeated runs to reduce random errors, with detailed data presented in Table 4 and Figure 7. Table 4Comparison of ablation experiment results.MSCACATransformerSMOTE-TomekACC (%)Macro-F1 (%)S-F1 (%)F-F1 (%)✓✓✓✓98.8893.9789.6783.991D CNN✓✓✓97.3289.6683.7776.81✓×✓✓97.0690.6583.9378.24✓✓×✓96.6489.2381.7176.06✓✓✓×97.3387.8978.9875.01✓✓BiLSTM✓96.4890.2381.6480.17 Comparison of ablation experiment results. Radar chart of ablation experiment results on the MIT-BIH dataset. Combined with the ablation experiment results and the structural characteristics of the model, the analysis is as follows: The multi-scale convolution layer lays the foundation for extracting temporal ECG features. Upon removing this layer, the overall ACC drops by 1.56%, Macro-F1 by 4.31%, and the F1-scores of classes S and F decline by 5.90% and 7.18%, respectively. ECG waveforms consist of multi-scale morphological components including P waves, QRS complexes and T waves. Multi-scale convolution selectively extracts features spanning different time durations and supplies high-quality base features for subsequent enhancement and fusion. Removing this component results in incomplete feature extraction and degraded identification of challenging minority arrhythmia types. The ACA channel attention module strengthens diagnostically critical pathological features. Without the ACA module, ACC reduces by 1.82%, Macro-F1 by 3.32%, with F1-scores of classes S and F falling by 5.74% and 5.75%, respectively. ACA automatically pinpoints informative feature channels, amplifies valid waveform characteristics and suppresses useless noise. Specifically, it boosts faint P-wave features of class S and ambiguous features of class F to elevate the model’s minority-class recognition. The Dual-Input Contextual Transformer is essential for modeling long-range temporal dependencies. Its removal causes an ACC reduction of 2.24%, a 4.74% drop in Macro-F1, alongside F1 declines of 7.96% (S) and 7.93% (F). ECG rhythm inherently contains long-range correlations such as RR-interval continuity; this transformer complements the locally limited modeling capability of convolution. Lack of this module prevents full capture of sequential contextual information and impairs classification accuracy. The SMOTE-Tomek resampling strategy mitigates severe dataset imbalance. Excluding SMOTE-Tomek preprocessing leads to a 1.55% ACC drop, a sharp 6.08% Macro-F1 reduction, and F1 decrements of 10.69% (S) and 8.98% (F), the most substantial degradation across all ablation groups. Raw ECG datasets follow a long-tailed distribution, causing inadequate training on S- and F-type samples. By augmenting minority samples, SMOTE-Tomek mitigates classification bias and stabilizes the model’s performance on rare arrhythmia categories. Analysis of module replacement experiment results The gating mechanism of BiLSTM can only capture local temporal correlations in sequence order, with a receptive field that grows linearly with sequence length, failing to parallelly capture non-continuous long-range rhythm associations in ECG signals such as P-wave-QRS wave and RR interval relationships. In contrast, the self-attention mechanism of Transformer can simultaneously attend to all positions in the feature sequence. Combined with the dual-input contextual design, it can more comprehensively understand the bidirectional temporal context of ECG signals and fully mine the global rhythm features of ECG signals. These results verify the rationality and superiority of selecting Transformer in this study, and its increased complexity yields clear performance gains .In summary, the ablation experiments validate the necessity of each core module in the proposed ECG classification model, and the modules work synergistically with complementary advantages: the multi-scale convolution layer is responsible for extracting multi-time-scale features, the ACA module enhances key feature representation, the dual-input Transformer integrates long-range dependency features, and the oversampling strategy alleviates class imbalance. Together, they constitute the model’s excellent classification performance, confirm the rationality of the model design, and provide a clear direction for subsequent model optimization. Cross-database generalization validation To further validate the performance and generalization capability of our model, we also conducted verification using the St Petersburg INCART 12-lead Arrhythmia Database. This database is provided by the St. Petersburg Institute of Cardiological Technics and contains original recordings from 32 patients aged 18 to 80 years old (17 males and 15 females). The dataset comprises 75 annotated recordings extracted from 32 Holter records, each lasting 30 minutes and containing 12 standard leads. Each lead has a sampling rate of 257 Hz, with the gain parameters explicitly specified in corresponding .hea files. Additionally, the reference annotation files include over 175,000 annotated heartbeats. Table 5INCART dataset classification results.ClassPrecision (%)Recall (%)Macro-F1 (%)ACC (%)N99.6299.7898.7999.47A98.4397.34 INCART dataset classification results. As illustrated in Figs. 8, 9 and 10, the proposed model achieves stable performance across two independent datasets, which verifies that MSCA-TNet extracts inherent ECG feature patterns rather than dataset-specific noise and confirms its strong generalization and reliability. Confusion matrix of on the INCART test dataset for N and A heartbeat categories. Smoothed training and validation loss curves on the INCART dataset. Smoothed training and validation accuracy curves on the INCART dataset. Conclusion This study proposes a hybrid MSCA-TNet architecture for arrhythmia signal classification. The model first denoises and reconstructs ECG signals using discrete wavelet transform, and then addresses the data class imbalance problem via SMOTE-Tomek resampling. It integrates effective feature extraction of multi-scale convolution, adaptive channel attention mechanism, and sequence modeling capability of the dual-input contextual Transformer. These components collaboratively capture comprehensive temporal and spatial characteristics of ECG signals, thereby improving arrhythmia classification performance. The multi-scale convolution module fuses multi-scale features to enhance the model’s expressive power and classification accuracy. The adaptive channel attention mechanism enables the network to selectively highlight diagnostically important feature channels and suppress irrelevant information by leveraging global context. The proposed hybrid architecture achieves competitive automatic arrhythmia classification on the MIT-BIH database, and effectively alleviates the dataset imbalance issue. It shows potential for deployment in wearable monitoring devices in the future, providing an efficient and reliable auxiliary tool for real-time intelligent cardiac health services. Nevertheless, this work has several limitations. First, the proposed model is only validated on the standard MIT-BIH and INCART databases, and its performance on real-world wearable ECG signals with severe motion artifacts and individual differences still needs further verification. Second, even with SMOTE-Tomek resampling, the classification performance for minority classes S and F remains insufficient due to limited and difficult samples. In future work, targeted improvements will be conducted in three aspects: at the data level, GANs will be used to generate high-fidelity synthetic samples of class F, and manual verification will be performed on original annotations. At the model level, a fine-grained feature extraction branch for class F will be added after the ACA module, and contrastive learning will be introduced. At the feature level, complementary information from multi-lead ECG signals will be fused to improve the distinguishability of P waves in class S, so as to further strengthen the model’s recognition ability for minority arrhythmia categories. Author contributions S.H. developed the methodology, implemented the software, and wrote the original manuscript draft. S.C. performed data curation and conducted the experimental validation. Z.G. carried out the formal analysis of the results. K.J. conducted the investigation and prepared all visualizations and figures. M.Z. was responsible for the conceptualization of the study and the review and editing of the manuscript. All authors reviewed and approved the final version of the manuscript. Funding This research is partially supported by Natural Science Foundation of Fujian Province: 2023J011807, 2023J05309 Data availability The datasets analysed and the code generated during the current study are available as follows: 1.the MIT-BIH Arrhythmia Database, which contains 48 half-hour excerpts of two-channel ambulatory ECG recordings, is accessible at https://physionet.org/content/mitdb/1.0.0/. 2.the INCART 12-Lead Arrhythmia Database, consisting of 75 long-term 12-lead ECG recordings with annotated arrhythmias, is available at https://physionet.org/content/incartdb/1.0.0/. Code availability Code is available at https://doi.org/10.5281/zenodo.20542420 Declarations Competing interest The authors declare no competing interest. Footnotes Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. Miao Zhang these author contributed equally to this work. References Associated Data Data Availability Statement The datasets analysed and the code generated during the current study are available as follows: 1.the MIT-BIH Arrhythmia Database, which contains 48 half-hour excerpts of two-channel ambulatory ECG recordings, is accessible at https://physionet.org/content/mitdb/1.0.0/. 2.the INCART 12-Lead Arrhythmia Database, consisting of 75 long-term 12-lead ECG recordings with annotated arrhythmias, is available at https://physionet.org/content/incartdb/1.0.0/. Code is available at https://doi.org/10.5281/zenodo.20542420