ECG Synthesizer
Embedded SystemsAn ESP32-based ECG synthesizer that generates physiologically accurate cardiac waveforms — P wave, QRS complex, and T wave — through a custom analog output stage. Built with C++ and PlatformIO, based on the EKG simulator used in Duke's BME teaching labs.
View on GitHubOverview
The ECG Synthesizer generates a realistic electrocardiogram (ECG) signal on hardware, replicating the cardiac waveform morphology — P wave, QRS complex, and T wave — at a configurable heart rate. The project pairs an ESP32 microcontroller (used as a DAC source) with a custom analog output stage that conditions the differential signal for standard ECG lead outputs (RA, LL, RL).
The design is based on the EKG simulator circuit used in Duke University’s BME teaching labs, extended with embedded firmware for waveform synthesis.
Hardware
Output Stage Circuit
The analog front-end takes a positive and negative waveform from the ESP32 and conditions them for ECG lead outputs.
| Stage | Components | Function |
|---|---|---|
| Input summing | R1, R2 (1 MΩ each) | Sums POSITIVE WFORM and NEGATIVE WFORM at U1A inputs |
| Differential amplifier | U1A, R3 (1 kΩ), R4 | Amplifies differential signal; R4 sets gain to GND reference |
| Buffer/comparator | U1B (±5 V supply) | Buffers U1A output to drive the ECG lead resistor ladder |
| Lead outputs | R7 (RL), R8 (LL), R9 (RA) — with test points TP1–TP3 | Provides the three standard limb lead reference voltages |
The ±5 V rail powers the output op-amp (U1B), ensuring the conditioned waveform can swing symmetrically around ground — matching the common-mode range expected by ECG acquisition hardware.
Key Design Choices
- 1 MΩ input resistors — high input impedance preserves the DAC signal and limits loading on the ESP32 output
- 1 kΩ feedback (R3) — sets a moderate closed-loop gain while keeping the differential stage stable
- Separate ±5 V supply for U1B — allows rail-to-rail output swing independent of the 3.3 V MCU supply
Firmware
Written in C++ with PlatformIO targeting the ESP32. The firmware synthesizes each segment of the cardiac cycle:
| Waveform Segment | Description |
|---|---|
| P wave | Atrial depolarization — low-amplitude, rounded positive deflection |
| QRS complex | Ventricular depolarization — rapid, high-amplitude spike |
| T wave | Ventricular repolarization — slower, positive deflection |
| Isoelectric baseline | Flat segments between waves at the correct physiological timing |
The synthesized waveform is output through the ESP32’s built-in DAC, then split into differential positive/negative outputs before entering the analog conditioning stage.
Use Case
The synthesizer produces a realistic ECG signal that can drive:
- ECG acquisition boards and analog front-ends for testing
- Teaching demonstrations of cardiac waveform morphology
- Bench validation of signal processing algorithms before live patient data is used
This makes it useful as a signal source for BME lab coursework — verifying that ECG amplifier circuits, filters, and ADC pipelines respond correctly to a known, repeatable input.