User Guide: Synthetic ECG Generation & 12-Lead Dynamics¶
Mathematical Foundation: The McSharry Model¶
The dynamic generator implemented in ecg_sdk.core.generator extends the canonical 3D dynamical attractor introduced by McSharry et al. (2003) and the multichannel vectorcardiographic extensions by Sameni et al. (2007) and Clifford et al. (2005).
Phase Trajectory \(\theta(t)\)¶
The cardiac phase trajectory \(\theta(t)\) rotates continuously around the limit cycle in the interval \([-\pi, \pi]\):
where the instantaneous heart rate \(f_{\text{HR}}(t)\) incorporates Respiratory Sinus Arrhythmia (RSA / HRV modulation at \(\sim 0.25\) Hz):
12-Lead Anatomical Parameters¶
Each lead \(l \in \{\text{I}, \text{II}, \text{III}, a\text{VR}, a\text{VL}, a\text{VF}, V_1, \dots, V_6\}\) is modeled as a sum of 5 Gaussian functions corresponding to the \(P, Q, R, S,\) and \(T\) waves:
where \(\Delta \theta_{l,i} = \text{mod}(\theta(t) - \theta_{l,i} + \pi, 2\pi) - \pi\).
12-LEAD SPATIAL POLARITIES
┌──────────────────┬────────────────────────────────────────────────────────┐
│ Lead │ Electrophysiological Wave Morphology │
├──────────────────┼────────────────────────────────────────────────────────┤
│ I (0°) │ Positive P, modest R (+1.10 mV), positive T (+0.30 mV) │
│ II (+60°) │ Dominant electrical axis: Tallest R (+1.65 mV) │
│ III (+120°) │ Einthoven's Law: Lead III = Lead II - Lead I │
│ aVR (-150°) │ Fully INVERTED: Negative P, deep QS, negative T │
│ aVL (-30°) │ Goldberger: aVL = (I - III) / 2 │
│ aVF (+90°) │ Goldberger: aVF = (II + III) / 2 │
│ V1 (Right Ventr) │ rS complex: Small r (+0.25 mV), deep S (-1.20 mV) │
│ V2 (Septal) │ rS complex: Deepest S wave (-1.65 mV) │
│ V3 (Transition) │ RS biphasic complex: R / S ≈ 1 │
│ V4 (Apex) │ Rs complex: Dominant tall R (+1.75 mV) │
│ V5 (Lateral LV) │ qR complex: Septal q, tallest R (+1.85 mV) │
│ V6 (Lateral LV) │ qR complex: Tall positive R (+1.45 mV) │
└──────────────────┴────────────────────────────────────────────────────────┘
Cardiac Arrhythmias & Anomaly Gallery¶
The generator supports injecting controlled physiological arrhythmias and clinical emergency conditions:

- Normal Sinus Rhythm (NSR) (
anomaly=Noneor'normal'): Standard physiological rhythm (60–100 bpm). - Sinus Bradycardia (
anomaly='bradycardia'): Heart rate dropped to \(\sim 38\) bpm (prolonged RR intervals). - Sinus Tachycardia (
anomaly='tachycardia'): Heart rate elevated to \(\sim 150\) bpm. - Premature Ventricular Contractions (PVC) (
anomaly='pvc'): Wide, anomalous ventricular beats injected periodically with lead-dependent polarity (inverted in lateral leads \(V_5, V_6\), positive in right ventricular lead \(V_1\)). - Sinus Pause / Asystole (
anomaly='pause'): Flatline emergency event exceeding \(>3.0\) seconds.