Skip to content

WaveformNet is a deep learning project with 1D and 2D CNN models for classifying ECG signals into multiple arrhythmia types. The 1D model analyzes raw waveforms, while the 2D model processes transformed inputs, enabling a comparative approach to AI-based cardiac monitoring.

License

Notifications You must be signed in to change notification settings

NSANTRA/WaveformNet

Repository files navigation

TITLE

Jupyter Lab Python TensorFlow NumPy Seaborn GPU License: MIT


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.


TITLE


TITLE

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.

TITLE

  • 🧩 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.

Typing SVG

  • 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)

TITLE

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

TITLE

πŸ”§ Prerequisites

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)

βš™οΈ Installation

Recommended Python Packages

pip install numpy pandas matplotlib seaborn scikit-learn wfdb tensorflow

Clone the Repository

git clone https://github.com/NSANTRA/WaveformNet-Arrhythmia-Classification.git
cd WaveformNet-Arrhythmia-Classification

πŸ“‚ Dataset Setup

You 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.

▢️ Usage

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.

Typing SVG

🧩 1D CNN (Temporal Model)

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

πŸ–Ό 2D CNN (Spatiotemporal Model)

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

Reference Architectures:


TITLE

Classification Report β€” 1D CNN (Temporal Model)

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

πŸ”Ή Key Observations

  • βœ… 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.

Classification Report β€” 2D CNN (Spatiotemporal Model)

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

πŸ”Ή Key Observations

  • βœ… 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.

Training & Validation Metrics (1D)

The model was trained for 50 epochs on the MIT-BIH Arrhythmia Dataset. The following plots demonstrate the model's performance:

Training vs Validation Loss

  • The training and validation loss curves steadily decrease and converge, indicating proper learning and no signs of overfitting. Final validation loss stabilizes near zero.

Loss Graph

Training vs Validation Accuracy

  • The model achieves over 98% validation accuracy, demonstrating strong generalization capability.
  • Accuracy plateaued after ~30 epochs, suggesting optimal convergence.

Accuracy Graph

Combined Accuracy & Loss Overview

  • This side-by-side visualization offers a comprehensive look at the tradeoff between accuracy and loss. Both metrics indicate consistent improvement during training.

Combined Graph

Confusion Matrix

  • 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.

Confusion Matrix


Training & Validation Metrics (2D)

The models were trained for 50 epochs on the MIT-BIH Arrhythmia Dataset, and the performance metrics reflect strong generalization and learning behavior.

Training vs Validation Loss

  • 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.

Loss Graph

Training vs Validation Accuracy

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.

Accuracy Graph

Combined Accuracy & Loss Overview

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.

Combined Graph

Confusion Matrix

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.

Confusion Matrix


TITLE

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

LICENSE MIT License

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.

About

WaveformNet is a deep learning project with 1D and 2D CNN models for classifying ECG signals into multiple arrhythmia types. The 1D model analyzes raw waveforms, while the 2D model processes transformed inputs, enabling a comparative approach to AI-based cardiac monitoring.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published