This application provides a modular, clinical-grade pipeline for ECG signal processing, feature extraction, and heartbeat classification. It includes a Tkinter-based GUI for interactive visualization and classification of ECG segments, powered by a pre-trained machine learning model.
The app performs the following tasks:
- Loads ECG signals from CSV or WFDB formats
- Detects R-peaks and segments heartbeats
- Extracts clinically relevant features (RR interval, QRS duration, P-wave width, etc.)
- Classifies each heartbeat using a trained ExtraTreesClassifier model
- Displays results and confidence scores in a responsive GUI
- Upload File: Load ECG data from CSV or WFDB
.heafiles - Classify Heartbeat: Start classification of ECG segments
- Pause/Continue: Control the classification flow
- Segment Navigation: Browse previous/next heartbeat segments
- Live Plot: Visualize ECG waveform with Matplotlib
- Results Panel: View predicted class, confidence, and extracted features
The GUI is built using ttkbootstrap for a modern dark-themed interface and matplotlib for waveform visualization. Classification runs asynchronously to keep the UI responsive.
Each heartbeat segment is analyzed to extract:
rr_interval: Time between successive R-peaksr_peak_amp: Amplitude of the R-peakqrs_duration: Duration of the QRS complexp_wave_width: Width of the P-wavemin_voltage,max_voltage,mean_voltage,std_voltage: Signal statistics
These features are computed using slope analysis, moving averages, and statistical summaries. The ECGFeatureExtractor class handles this logic.
The classifier uses a pre-trained ExtraTreesClassifier (trained by me on mit-bih database) model with:
- Scaler:
StandardScalerfor feature normalization - Encoder:
LabelEncoderfor label transformation - Model:
KNeighborsClassifiertrained on balanced ECG feature data
N: Normal beatV: VentricularS: SupraventricularF: FusionQ: UnknownU: Unknown
The classifier returns both the predicted label and a confidence score (0–100%).
Supported formats:
- CSV: Plain signal values, one column, no header
- WFDB: MIT-BIH
.heafiles (converted internally)
The ECGDataLoader handles both formats and automatically detects R-peaks using scipy.signal.find_peaks.
The classifier module includes:
get_score(x, y): Returns accuracy score on test datadisplay_confusion_matrix(x, y): Plots confusion matrix usingmatplotlib
These utilities help validate model performance and interpret classification results.
- Modular architecture with separation of concerns
- Threaded data loading to prevent UI blocking
- Compatible with Windows and Linux
- Uses
joblibfor model persistence andpandasfor feature handling - UI state management includes pause/resume logic and segment navigation
- Includes
requirements.txtfor reproducible setup