Creative Computing: An ECG animation for arrythmic events.

python

First Beat: Why This Matters

The human heart is a remarkable electrical engine, beating around 100,000 times a day. But when its rhythm falters in conditions like bradycardia (too slow) or tachycardia (too fast) the consequences can be life-threatening.

Electrocardiograms (ECGs) are the gold standard for detecting these irregularities, but interpreting them in real time is challenging, even for trained clinicians. Studies show that diagnostic accuracy can be as low as 55% among medical graduates.

This project set out to change that by combining signal processing, data visualisation, and human visual perception principles to create an animated ECG tool that not only displays heart activity in real time but also highlights abnormalities in a way that is intuitive, fast, and clinically useful.

Setting the Rhythm: The Goal

The aim was to build a Python-based animated ECG visualisation that:

  • Streams ECG data in a scrolling, real-time animation.
  • Detects bradycardia and tachycardia events automatically.
  • Uses visual salience techniques (colour, zoom, pause) to draw attention to abnormalities.
  • Reduces cognitive load for clinicians, making diagnosis faster and more accurate.

The data came from the MIT-BIH Arrhythmia Database, a gold-standard dataset with expert-annotated ECG recordings.

Signal Intake: Data and Preprocessing

Raw ECG signals are messy, containing baseline wander, powerline interference, and muscle noise.

To clean them, the project used Discrete Wavelet Transform (DWT) with a Coiflet wavelet and rigrsure thresholding. This method:

  • Preserves important waveform features (P wave, QRS complex, T wave).
  • Removes noise across multiple frequency bands.
  • Improves signal-to-noise ratio without distorting the ECG shape.

Heart in Motion: The Animation

The visualisation was built in Matplotlib using FuncAnimation for smooth scrolling.

Key features include:

  • Real-time heart rate calculation from R–R intervals.
  • Automatic abnormality detection for bradycardia (<60 bpm) and tachycardia (>100 bpm).
  • Pause and Zoom when an abnormality is detected, preventing “change blindness”.
  • Colour coding:
    • Red for dangerous rhythms.
    • Distinct colours for P, QRS, and T waves (tetradic colour scheme).
  • ECG grid overlay for precise measurement of wave durations and amplitudes.

Focused Pulse: Visual Salience

The design was guided by human visual perception research:

  • Red was chosen for abnormalities due to its high salience and association with danger.
  • Smooth scrolling matches natural eye tracking, reducing fatigue.
  • Pause and Zoom ensures clinicians do not miss transient events.
  • Limited colour palette (fewer than 5 colours) to avoid overload.
  • Grid lines provide a stable reference frame for accurate measurement These choices were not just aesthetic, they were cognitive performance optimisations.

Under the Hood: How It Works

  1. Load ECG data from MIT-BIH.
  2. Denoise using DWT.
  3. Detect R-peaks from annotations.
  4. Calculate heart rate from R–R intervals.
  5. Check thresholds for bradycardia or tachycardia.
  6. Trigger visual cues (pause, zoom, colour change).
  7. Continue scrolling until next event.

Core Tech Stack:

  • Python for processing and animation.
  • Matplotlib for plotting.
  • NeuroKit2 for ECG delineation.
  • PyWavelets for signal denoising.
  • WFDB for reading ECG datasets.

Vital Signs: Results

  • âś… Clearer ECGs – Noise removed without losing diagnostic features
  • âś… Real-time detection – Immediate visual alerts for abnormal rhythms
  • âś… Reduced cognitive load – Clinicians can focus on what matters
  • âś… Educational value – Useful for training medical students and patients

Flatlines and Limitations

  • Performance bottleneck – FuncAnimation slows down over long runs.
  • Colour overlap – P and T waves can sometimes appear similar in certain arrhythmias.
  • Fixed QRS width assumption – Could be improved with dynamic detection.
  • Not yet tested in live clinical settings – Needs real-world validation.

Future improvements:

  • Switch to a faster rendering engine (e.g., PyQtGraph).
  • Add more arrhythmia types (AFib, VT, VF).
  • Make colour scheme colourblind-friendly.
  • Integrate with live ECG monitoring devices.

Final Beat: A Step Ahead in Cardiac Care

This project shows how creative computing can bridge the gap between raw medical data and actionable clinical insight.

By combining signal processing, animation, and visual salience theory, we can make ECG interpretation faster, more accurate, and more intuitive, potentially saving lives in the process.

The heartbeat is one of the most fundamental signals of life. With the right tools, we can read it better than ever.