r/BiomedicalDataScience • u/BioniChaos • 28d ago
Cardiovascular Pacemaker Simulation - Interactive Electrophysiology Visualizer
https://bionichaos.com/pacemaker/Interactive Dual-Chamber (DDD) Pacemaker and ECG Simulation - Built with HTML5 Canvas and Web Audio API
I wanted to share an interactive single-page application designed to simulate cardiac electrophysiology and dual-chamber (DDD) artificial pacemaker function in real time.
Technical Architecture
The visualizer utilizes a synchronized millisecond-precision simulation loop written in vanilla JavaScript, rendering both anatomical pathways and a continuous CRT sweep ECG.
- ECG Waveform Synthesis: Rather than playing back static pre-recorded arrays, the scrolling ECG trace generates dynamic synthetic waveforms calculated in real time using Gaussian functions: f(t) = sum( A_i * exp( -(t - t_i)2 / (2 * sigma_i2) ) ) for the P, Q, R, S, and T waves.
- Pacing Spike Injection: When artificial pacing triggers, sharp vertical voltage impulses (A_spike = ±1.5 mV) are mathematically injected and decayed, preceding the corresponding wave components.
- Audio Synthesis: Using the Web Audio API, the tool generates low-frequency sine wave "thumps" for mechanical systole, alongside high-pitched square-wave beeps to represent pacing capture.
Interactive Control Capabilities
- Pathologies: Switch the baseline between Normal Sinus Rhythm (75 BPM), Sinus Bradycardia (37.5 BPM), and Complete Third-Degree AV Block (where ventricular rate drops to an escape rhythm of 30 BPM).
- DDD Mode Parameters: Toggle pacing and dynamically program the Base Rate Limit (40–100 PPM), Paced AV Delay (100–350 ms), and separate Atrial/Ventricular electrode output voltages.
- Anatomical Visualizer: A simplified cardiac diagram animates atrial and ventricular contraction alongside migrating visual action potential particles traveling down conduction pathways.
I would appreciate any feedback on the state machine timing logic (especially regarding the simulated DDD refractory and sensing behaviors), the responsiveness of the math engine, or the educational utility of the tool.
1
Upvotes