ECG Anomaly Detection Using Unsupervised Deep Autoencoders
A technical evaluation of a deep learning framework for scalable, data-driven cardiac monitoring in clinical research and wearable health systems.
Clinical Motivation & Research Context
Early detection of cardiac abnormalities is a critical challenge in continuous health monitoring. Traditional ECG analysis, which relies on handcrafted features and expert annotation, severely limits scalability and real-time deployment efficiency.
This case study explores an **unsupervised deep learning framework** designed to learn the intrinsic structure of normal ECG signals. It detects anomalies as significant deviations in reconstruction behaviour, enabling highly scalable and data-driven cardiac monitoring solutions.
Problem Formulation: Reconstruction-Based Anomaly Detection
The research objective is to design an unsupervised anomaly detection model capable of identifying pathological ECG patterns without explicit data labeling during the training phase. The problem is framed as a reconstruction-based task.
Limited Data
Addressing the scarcity of annotated abnormal ECG data, which hinders supervised learning approaches.
Signal Variability
Managing the high variability and inherent noise present within continuous physiological signals.
Real-Time Requirement
Ensuring the model is suitable for deployment, offering real-time, low-latency anomaly detection capability.
Dataset & Signal Preprocessing for Unsupervised Learning
The study utilised a public ECG dataset, where each instance consisted of a single-lead signal comprising 140 temporal samples. A rigorous preprocessing pipeline was implemented to guarantee a truly unsupervised training environment.
01
Signal Normalisation
Applied StandardScaler or Min–Max scaling to standardise signal amplitude distributions.
02
Tensor Conversion
Conversion of processed signals into TensorFlow tensors for deep learning compatibility and efficient processing.
03
Data Isolation
Strict separation of normal and anomalous samples, ensuring abnormal signals were never exposed during the training phase.
Visualisation of averaged waveforms highlights the subtle yet critical morphological differences that the autoencoder is tasked with capturing.
Autoencoder Architecture: Learning Latent Representations
An **undercomplete deep autoencoder** was strategically employed to force the model to learn compact, low-dimensional latent representations, capturing only the most essential physiological patterns of healthy ECG data.
Encoder Layering
Input dimension reduction sequence: 140 → 32 → 16 → 8. The final layer forms the latent space.
Decoder Layering
Reconstruction sequence from latent space: 8 → 16 → 32 → 140, matching the original input dimension.
Activation & Loss
ReLU for hidden layers, Sigmoid for the output layer. Mean Absolute Error (MAE) used as the primary loss function.
Training Strategy & Optimization
The model was rigorously trained exclusively on normal ECG signals, aiming to minimise the reconstruction loss. This approach ensures the autoencoder becomes highly proficient at recreating healthy signals but poorly reconstructs any anomalous input.
Training and validation loss curves demonstrate stable learning and successful convergence, confirming the model's methodological rigor and generalisation ability.
Optimization
Utilised the Adam optimizer for efficient gradient descent across mini-batches.
Overfitting Control
Continuous validation monitoring was performed to prevent overfitting to the training distribution.
Implementation
Comparative analysis between TensorFlow's Sequential and subclassed API implementations to ensure optimal performance.
Reconstruction-Based Anomaly Detection Thresholding
Anomaly classification is driven by reconstruction error statistics, offering an adaptive approach that naturally accommodates physiological signal variability.
1
Compute MAE
Calculate the Mean Absolute Error between the original ECG input signal and the reconstructed output signal.
2
Establish Threshold
Define an adaptive anomaly threshold using statistical measures (mean + standard deviation) derived from the reconstruction errors of normal signals.
3
Classify Anomaly
Any signal where the MAE exceeds the established adaptive threshold is flagged and classified as anomalous.
Normal ECG Anomalous ECG
Experimental Results & Performance Validation
The experimental results show a clear statistical separation between the reconstruction errors of normal and anomalous ECG samples, decisively validating the effectiveness of this unsupervised approach for clinical anomaly detection.
Training Losses
Training Loss Distribution
Tightly clustered MAE for signals used in training, demonstrating the model's proficiency in modelling normality.
Testing Losses
Test Loss Distribution
Clear bimodality in test set MAE, where anomalous signals yield significantly higher reconstruction errors than normal signals.

Evaluation metrics: High performance was recorded across Accuracy, Precision, and Recall, confirming the model's reliability in distinguishing pathological events.
Insights, Limitations & Research Trajectory
The study confirms that deep autoencoders can effectively learn and model normal cardiac dynamics, establishing reconstruction error as a reliable, quantitative indicator of ECG anomalies. Unsupervised learning proves highly suitable for signals characterised by sparse anomaly rates.
Temporal Integration
Investigating CNN/LSTM-based temporal autoencoders to capture sequential dependencies in ECG time series.
Wearable Deployment
Optimisation for real-time edge deployment on low-power, wearable ECG devices.
BCI Integration
Integration with broader systems, including Brain-Computer Interface (BCI) platforms for holistic stress and health monitoring.
Conceptualising the integration of the anomaly detection model into comprehensive digital health and BCI-driven stress management systems.
Made with