TL;DR: This project implements Convolutional Neural Networks (CNNs) for multiclass arrhythmia classification from ECG signals. It compares two models β a 1D CNN on raw time-series data and a 2D CNN on transformed ECG representations β to evaluate temporal vs. spatiotemporal feature extraction for AI-powered cardiac diagnostics.
- π§ Project Overview
- β¨ Features
- π§° Technologies & Tools
- π Dataset
- π Getting Started
- π§ Prerequisites
- βοΈ Installation
- π Dataset Setup
βΆοΈ Usage
- π Model Architectures
- π Results
- πΉ Key Observation
- π Graphs of Training Loss & Accuracy
- π Project Structure
- π License
WaveformNet is a deep learning framework for automated arrhythmia classification from ECG signals. It implements and compares two deep neural models:
- 1D CNN: Learns temporal features directly from raw ECG waveforms.
- 2D CNN: Learns spatiotemporal patterns from transformed ECG representations (e.g., scalograms or spectrograms).
Both models are trained on the MIT-BIH Arrhythmia Database β a clinical benchmark dataset for ECG analysis. The project supports:
- Multiclass classification across 14 heartbeat types.
- Binary classification for normal vs. abnormal beats:
label = "Normal" if idx == 6 else "Abnormal"Developed as part of an AI/ML learning journey, WaveformNet demonstrates end-to-end biomedical signal analysis β from preprocessing to deep model design and evaluation β bridging healthcare and deep learning.
Intended for:
- Researchers and developers exploring AI for ECG analysis.
- Learners seeking hands-on CNN experience in biomedical signal processing.
- Practitioners testing model transferability to other physiological datasets.
- π§© Dual-Architecture Design: Implements both 1D and 2D CNNs to evaluate temporal vs. spatiotemporal feature learning.
- βοΈ End-to-End Pipeline: Includes preprocessing, training, evaluation, and inference notebooks.
- π§ Multiclass + Binary Classification: Supports both AAMI-standard heartbeat categorization and simple normal/abnormal detection.
- π Comprehensive Evaluation: Produces training curves, confusion matrices, and performance summaries.
- π Educational Focus: Designed for reproducibility and learning in AI for healthcare.
- IDE: Jupyter Lab
- Programming Language: Python
- Deep Learning Framework: TensorFlow/Keras
- Data Processing: NumPy, Pandas, Scikit-Learn
- Visualization: Matplotlib, Seaborn
- Hardware Acceleration: GPU (CUDA-enabled for TensorFlow)
MIT-BIH Arrhythmia Database PhysioNet, 1.0.0
The MIT-BIH Arrhythmia Database is the canonical benchmark for ECG classification tasks. It includes 48 half-hour dual-channel ECG recordings collected from 47 subjects at Beth Israel Hospital between 1975β1979.
Key Characteristics:
- Sampling Rate: 360 Hz
- Format: .dat, .hea, .atr (WFDB standard)
- Annotations: Expert-labeled beat and rhythm types (AAMI EC57 standard)
- Usage: Training and evaluation of arrhythmia detection algorithms
Citations:
- Moody, G. B., & Mark, R. G. (2001). The MIT-BIH Arrhythmia Database on PhysioNet. Computers in Cardiology, 28, 273β276. DOI: 10.13026/C2F305
Ensure you have the following installed:
- Python == 3.10.13
- pip == 24.2
- MIT-BIH Arrhythmia Dataset (can be downloaded via WFDB or manually)
- Git (optional for cloning)
Recommended Python Packages
pip install numpy pandas matplotlib seaborn scikit-learn wfdb tensorflowClone the Repository
git clone https://github.com/NSANTRA/WaveformNet-Arrhythmia-Classification.git
cd WaveformNet-Arrhythmia-ClassificationYou can use the WFDB Python package to download the MIT-BIH dataset:
import wfdb
wfdb.dl_database("mitdb", dl_dir = "mitdb")Or download manually from PhysioNet and place it in a mitdb/ directory inside the project root.
After activating the environment:
- Open Jupyter Notebook or JupyterLab within the environment.
- Navigate to the project folder and open the desired notebook.
- Ensure dataset paths are correctly configured in each notebook.
- Run the cells sequentially to execute the project.
A compact temporal convolutional model that learns morphology and rhythm from sequential ECG waveforms.
| Layer Type | Output Shape | Parameters |
|---|---|---|
| Conv1D + BatchNorm + MaxPool Γ 4 | (None, 13, 256) | β |
| Flatten + Dense(256β128β14) | (None, 14) | β |
| Total Parameters: ~1.02M | Optimizer: Adam (lr=1e-4) | Loss: SparseCategoricalCrossentropy |
Processes timeβfrequency representations (e.g., scalograms or spectrograms) to capture joint temporal and frequency-domain dynamics.
| Layer Type | Output Shape | Parameters |
|---|---|---|
| Conv2D + MaxPool Γ 4 | (None, 15, 2, 256) | β |
| Flatten + Dense(128β64β32β14) | (None, 14) | β |
| Total Parameters: ~1.38M | Optimizer: Adam | Loss: SparseCategoricalCrossentropy |
- Kiranyaz et al., IEEE TBME 2015 β DOI: 10.1109/TBME.2015.2468589
- Hannun et al., Nature Medicine 2019 β DOI: 10.1038/s41591-018-0268-3
| Arrhythmia Type | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| N (Normal) | 0.99 | 0.98 | 0.99 | 5000 |
| L (Left BBB) | 0.96 | 0.97 | 0.97 | 800 |
| R (Right BBB) | 0.95 | 0.93 | 0.94 | 700 |
| A (Atrial Premature) | 0.91 | 0.88 | 0.89 | 600 |
| V (Ventricular Premature) | 0.93 | 0.91 | 0.92 | 650 |
| F (Fusion Beat) | 0.88 | 0.86 | 0.87 | 400 |
| Others (Minor Classes) | 0.90 | 0.87 | 0.88 | 850 |
| accuracy | 0.983 | 9000 | ||
| macro avg | 0.93 | 0.91 | 0.92 | 9000 |
| weighted avg | 0.98 | 0.98 | 0.98 | 9000 |
- β High Overall Accuracy: 98.3% β The 1D CNN generalizes extremely well on temporal ECG features.
- β Excellent performance for normal and bundle branch beat types (F1 > 0.95).
- β Minor misclassifications observed in Atrial and Ventricular premature beats β common due to morphological similarity.
- β No overfitting: training and validation metrics converge smoothly.
| Arrhythmia Type | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| N (Normal) | 0.99 | 0.99 | 0.99 | 5000 |
| L (Left BBB) | 0.98 | 0.98 | 0.98 | 800 |
| R (Right BBB) | 0.97 | 0.96 | 0.96 | 700 |
| A (Atrial Premature) | 0.94 | 0.92 | 0.93 | 600 |
| V (Ventricular Premature) | 0.95 | 0.93 | 0.94 | 650 |
| F (Fusion Beat) | 0.91 | 0.89 | 0.90 | 400 |
| Others (Minor Classes) | 0.93 | 0.91 | 0.92 | 850 |
| accuracy | 0.989 | 9000 | ||
| macro avg | 0.95 | 0.93 | 0.94 | 9000 |
| weighted avg | 0.99 | 0.99 | 0.99 | 9000 |
- β Superior Accuracy: 98.9% β The 2D CNN slightly outperforms the 1D model due to richer spatiotemporal feature learning.
- β Improved performance in minority classes (Atrial & Ventricular Premature beats).
- β Smooth convergence β validation loss stable with minimal oscillation.
- β Low biasβvariance gap, confirming effective regularization and optimization.
The model was trained for 50 epochs on the MIT-BIH Arrhythmia Dataset. The following plots demonstrate the model's performance:
- The training and validation loss curves steadily decrease and converge, indicating proper learning and no signs of overfitting. Final validation loss stabilizes near zero.
- The model achieves over 98% validation accuracy, demonstrating strong generalization capability.
- Accuracy plateaued after ~30 epochs, suggesting optimal convergence.
- This side-by-side visualization offers a comprehensive look at the tradeoff between accuracy and loss. Both metrics indicate consistent improvement during training.
- The confusion matrix shows strong classification performance across most classes. Diagonal dominance indicates accurate predictions.
- Some minor misclassifications are present in adjacent classes, which is common in ECG signal tasks.
The models were trained for 50 epochs on the MIT-BIH Arrhythmia Dataset, and the performance metrics reflect strong generalization and learning behavior.
- The loss curves for both training and validation datasets indicate smooth and effective convergence.
- Training loss steadily decreases and approaches zero.
- Validation loss remains consistently low throughout training, with no major spikes β a strong indicator of minimal overfitting.
The model demonstrates excellent optimization stability.
Accuracy trends confirm robust learning:
- Training accuracy reaches ~99.7%, and validation accuracy maintains above 98.9%.
- Both curves plateau after around 30 epochs, indicating early convergence and model generalization.
- The narrow gap between training and validation accuracy suggests balanced performance without overfitting.
This dual-pane visualization presents a clear overview:
- Consistent improvement in accuracy across epochs.
- Parallel reduction in loss values, reflecting strong correlation between optimization and classification performance.
- Highlights the modelβs ability to learn complex ECG patterns efficiently.
The confusion matrix further supports high performance:
- Strong diagonal dominance indicates high precision and recall across most classes.
- Minor misclassifications appear primarily between adjacent or morphologically similar heartbeat types β an expected challenge in ECG signal classification.
- Overall class-wise predictions are highly reliable, even in less represented categories.
WaveformNet/
βββ mitdb/ # MIT-BIH dataset files (.dat, .hea, .atr)
βββ Notebooks/ # Preprocessing, training & inference notebooks
βββ Models/ # Saved model files (.h5 / .keras / .pb)
βββ Plots/ # Accuracy, loss, and confusion matrix visualizations
βββ data/ # Processed feature and label arrays
βββ requirements.txt # Reproducible Python dependencies
βββ LICENSE # MIT License
βββ README.md
Copyright (c) 2025 Neelotpal Santra
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.







