Tinycardia
Tinycardia detects atrial fibrillation (AFib) from ECG signals using machine learning models small enough to run on STM32 microcontrollers. It combines deep learning on raw ECG waveforms with extracted RR interval features for robust arrhythmia detection. The project aims to bring real-time, low-power cardiac monitoring to wearable and portable devices.
LINKS
Motivation and hardware
Tinycardia is a lightweight, real-time cardiac event monitoring system built to address two major limitations in existing cardiac detection tools: affordability and responsiveness. Consumer options like the Apple Watch require the user to remain still and initiate a reading manually, which limits their usefulness in emergencies. On the other end, clinical tools like Holter monitors are continuous but expensive and cumbersome. Tinycardia was designed to bridge this gap by enabling real-time arrhythmia detection on a low-power embedded system with no user interaction. The prototype uses an STM32 Nucleo board paired with a MAX30003 single-lead ECG sensor, chosen for its clinical-grade signal fidelity and low power profile. ECG signals are sampled at 256Hz and streamed to a laptop via USB using the ST-LINK virtual COM port, where a custom GUI displays both the real-time waveform and inference results. The sensor is configured in a Modified Lead II setup, offering clear P-wave and R-wave visibility and low motion artifacting, ideal for atrial fibrillation detection.
Model design and deployment
To classify arrhythmias, I first processed ECG data from the PTB-XL dataset, resampled to match the MAX30003’s 256Hz sampling rate. I initially experimented with beat-level classification using the MIT-BIH dataset but found it unsuitable, since atrial fibrillation requires rhythm-based analysis over longer windows to capture timing irregularities. I extracted 10-second windows from PTB-XL and applied the Pan-Tompkins algorithm for QRS detection, a lightweight and clinically validated method for noisy ambulatory ECGs. These features were passed to a 1D convolutional neural network, which was later augmented with statistical RR interval features (mean, standard deviation, and variance) to account for the temporal nature of AFib. This hybrid model achieved 93.7% validation accuracy, significantly outperforming the CNN alone. The trained model was then deployed to the STM32 using X-CUBE-AI within STM32CubeIDE, enabling fully embedded inference on the microcontroller with no external compute required.
Real-world results
To validate the system, I tested Tinycardia on myself and both of my parents using adhesive electrodes. In multiple test sessions, the system successfully streamed ECG data in real time, displayed live waveforms, and consistently produced correct classifications with no false positives. This real-world testing demonstrated that even in early prototype form, Tinycardia delivers reliable cardiac event detection under realistic operating conditions. The project as a whole reflects end-to-end engineering across embedded hardware, biomedical signal acquisition, applied machine learning, and real-time system design.