"They told me the heartbeat was one signal. Then they handed me twelve views of it, and warned that eleven were redundant except when they were not."
A Slightly Overwhelmed AI Agent
Prerequisites
This section builds on the measurement view of Part I: a sensor reports a projected, biased quantity rather than the thing itself, developed in Chapter 2, and the sampling and bandwidth vocabulary of Chapter 3. It assumes the biosignal amplitude and band anchors introduced in Chapter 28, where the ECG was placed at roughly 1 mV over a 0.5 to 150 Hz band. No cardiology background is required; the physiology you need is introduced here. Amplitude and interval figures are engineering anchors, not clinical diagnostic thresholds.
The Big Picture
Every cardiac AI model in this chapter, from a wrist-worn arrhythmia detector to an ejection-fraction estimator, consumes one raw substrate: a voltage over time that traces the heart's electrical wavefront. But that voltage is never absolute. It is always a projection of a moving three-dimensional dipole onto a specific pair of electrodes, and choosing that pair, the lead, changes the waveform's amplitude, its sign, even which features are visible at all. Understanding ECG means holding two ideas at once: the morphology (the P-QRS-T shape a single beat carries) and the geometry (how many leads you have and what direction each one looks from). Get the morphology wrong and you mislabel beats; get the lead geometry wrong and you compare incomparable signals, or train a model on twelve channels it will never see at inference on a watch.
The beat as a wave sequence: P, QRS, T
A single normal heartbeat writes a stereotyped sequence of deflections, and each one is the electrical signature of a physical event in the muscle. The P wave is the small, rounded bump (roughly 0.1 to 0.25 mV, lasting under 120 ms) produced as the atria depolarize and contract. The QRS complex is the tall, sharp spike (up to 1 to 2 mV, typically 80 to 100 ms wide) that marks depolarization of the far more massive ventricles; its steepness is why the QRS is the anchor for beat detection. The T wave is the broader, lower hump that follows as the ventricles repolarize and reset for the next beat. Between them sit intervals that are themselves diagnostic quantities: the PR interval (atria-to-ventricle conduction delay), the QT interval (total ventricular electrical activity), and the flat ST segment whose elevation or depression is a classic ischemia signal.
Why does this decomposition matter for a model rather than a cardiologist? Because it defines what a "feature" of an ECG even is. A hand-built classifier measures PR and QT durations and ST-segment offsets; a deep network in this chapter's later sections learns filters that fire on the same landmarks. Either way, the sampling rate must resolve the fastest event. The QRS carries meaningful energy to about 40 Hz for rhythm work and beyond 100 Hz for fine notching, which is why clinical ECG samples at 250 to 500 Hz and why undersampling smears the one feature every downstream stage depends on.
Key Insight
An ECG lead is not a wire; it is a direction. At each instant the heart's activity sums to a single net dipole vector, and a lead reports the projection of that vector onto its own axis: \(v_{\text{lead}}(t) = \vec{d}(t)\cdot\hat{u}_{\text{lead}}\). A wave points upward on the trace when the depolarization wavefront travels toward the positive electrode and downward when it travels away. This one fact explains almost every apparent contradiction in ECG: the same beat is a tall R wave in one lead and a deep S wave in another, not because the heart changed, but because two leads sampled the same rotating vector from different angles.
From one dipole to twelve views: the lead systems
If a beat is a rotating vector, then a full picture needs multiple viewing angles, and the standard clinical answer is the 12-lead ECG. Its twelve traces are not twelve independent measurements. Six limb leads (I, II, III, and the augmented aVR, aVL, aVF) view the vector in the body's frontal plane, and by Einthoven's law they are algebraically linked: lead II equals lead I plus lead III, so only two of the six carry new frontal-plane information. Six precordial leads (V1 through V6) march across the chest to view the vector in the horizontal plane, adding the front-to-back and left-to-right directions the limb leads miss. The redundancy is deliberate: overlapping views make the human read robust, and they let a localized abnormality (an ischemic wall facing only V2 and V3) announce itself in the leads that look at it.
The engineering consequence is sharp. Because the frontal-plane leads are linearly dependent, a full 12-lead record has only about eight degrees of freedom, and this is why compact representations and reconstruction of "missing" leads are feasible, a theme that returns with the vectorcardiographic idea below. It also means that when a wearable gives you a single lead, you have not lost one twelfth of the information; you have lost most of the spatial coverage, keeping a good rhythm view but a poor localization view. Table 29.1.1 anchors the morphology and lead facts you will size pipelines against.
| Component | Physical event | Typical amplitude | Typical duration |
|---|---|---|---|
| P wave | Atrial depolarization | 0.1 to 0.25 mV | < 120 ms |
| QRS complex | Ventricular depolarization | 1 to 2 mV | 80 to 100 ms |
| T wave | Ventricular repolarization | 0.1 to 0.5 mV | 150 to 250 ms |
| PR interval | Atrioventricular conduction | n/a | 120 to 200 ms |
| QT interval | Total ventricular activity | n/a | 350 to 450 ms |
| 12-lead set | 6 frontal + 6 horizontal views | ≈ 8 independent channels | n/a |
The short program below makes the projection idea concrete. It models the heart as a single rotating vector and computes what three limb leads would record, then checks that Einthoven's relation holds numerically, exactly the redundancy a lead-reconstruction model exploits.
import numpy as np
t = np.linspace(0, 1, 500) # one beat, seconds
# toy net cardiac dipole: a vector that grows and rotates during the QRS
angle = np.deg2rad(60) + 0.5 * np.sin(2 * np.pi * t)
mag = np.exp(-((t - 0.4) / 0.03) ** 2) # sharp QRS-like burst
d = np.stack([mag * np.cos(angle), mag * np.sin(angle)]) # 2D frontal dipole
# lead axes (unit directions) for Einthoven's triangle, degrees
axes = {"I": 0, "II": 60, "III": 120}
lead = {name: d[0]*np.cos(np.deg2rad(a)) + d[1]*np.sin(np.deg2rad(a))
for name, a in axes.items()}
resid = np.max(np.abs(lead["II"] - (lead["I"] + lead["III"])))
print(f"max |II - (I + III)| = {resid:.3e}") # ~0: leads are linearly dependent
As Listing 29.1 shows, the three limb leads are three shadows of one moving vector, and any one is recoverable from the other two. This linear structure is what lets research systems reconstruct a fuller lead set from fewer electrodes, and it is the geometric reason a wearable's single lead is a genuine but partial view. Feature choices built on these landmarks connect directly to the feature-engineering discipline of Chapter 8.
In Practice: the watch that sees only Lead I
A consumer smartwatch offers an "ECG" app: the wearer touches the crown with the opposite hand, closing a circuit from wrist to finger. Electrically, that is a single lead approximating clinical Lead I, sampled near 500 Hz for about 30 seconds. It resolves the QRS beautifully and gives a clean rhythm trace, so it is excellent for spotting an irregular beat interval. But a clinician reading it cannot localize an ischemic region, because Lead I is one frontal-plane direction and the telltale ST changes may face a chest lead the watch does not have. The design lesson is not that the watch is broken; it is that a model trained on 12-lead hospital data will see a distribution it was never shown if deployed on this one-lead stream. Training and evaluation must match the lead geometry of deployment, or the leakage-safe protocols of Chapter 5 will flatter a model that cannot generalize.
Baseline, polarity, and the artifacts morphology hides
Morphology is only readable after the signal is conditioned, and ECG carries three corruptions that directly attack the waves you just learned. Baseline wander is a slow (below 0.5 Hz) drift from breathing and electrode motion that lifts and drops the whole trace, threatening the ST segment whose absolute level is diagnostic. Powerline interference injects a 50 or 60 Hz sinusoid that can bury the fine QRS structure. Electrode and motion artifact produces sharp transients a naive detector will mistake for a QRS. Each is handled by band-limited filtering, a high-pass to flatten wander, a notch for mains, developed with full mathematics in Chapter 6. The catch, and the reason clinical ECG keeps a wide passband, is that too aggressive a high-pass distorts the ST segment and can manufacture the very ischemia sign a downstream model is hunting for.
Polarity deserves its own warning because it is a frequent silent bug. Swapped limb electrodes flip a lead's sign, turning tall R waves into deep negative deflections; a beat detector keyed to positive peaks then misses every beat. This is not a rare mishap in fleet data, and it is why robust pipelines detect on a rectified or energy transform of the signal rather than trusting polarity, a defensive habit aligned with the anomaly and quality gating ideas of Chapter 12.
Research Frontier
A live research thread reconstructs the full 12-lead ECG, or a synthetic vectorcardiogram, from the one or two leads a wearable can capture, exploiting exactly the linear dependence Listing 29.1 demonstrates. Public benchmarks such as PTB-XL (about 21,800 clinical 12-lead records) and the PhysioNet/Computing in Cardiology 2020 and 2021 challenges have driven models that estimate missing precordial leads from limb leads, and diffusion-based ECG generators now synthesize morphologically plausible beats for augmentation. The open problem is trust: a reconstructed lead can look right yet omit the localized abnormality that only the true chest electrode would have shown, so reconstruction aids screening but does not yet replace acquisition. Foundation-model approaches to this appear in Section 29.5.
The Right Tool
Written from scratch, delineating a beat, that is, locating P onset, QRS onset and offset, and T offset so you can measure PR and QT, is roughly 120 to 150 lines of careful peak-finding, adaptive thresholds, and edge handling around ectopic beats. The neurokit2 library returns every landmark in two calls:
import neurokit2 as nk
signals, info = nk.ecg_process(ecg, sampling_rate=500) # clean + find R peaks
waves = nk.ecg_delineate(signals["ECG_Clean"], info["ECG_R_Peaks"],
sampling_rate=500) # P, Q, S, T boundaries
neurokit2.ecg_delineate returns P, QRS, and T boundary samples in one call, replacing roughly 130 lines of hand-tuned delineation. It gives you the interval measurements (PR, QT) as byproducts. The library removes the drudgery; judging whether its default delineator suits your device's noise and your population remains your responsibility.The convenience is real and so is the caveat: a delineator tuned for clean clinical ECG can mislocate T offsets on a noisy single-lead wrist trace, so validate its landmarks against a labeled subset of your own data before trusting the derived intervals.
Exercise
You receive a batch of single-lead ECG recordings from a wearable fleet. In perhaps 3 percent of them, every QRS complex points downward instead of up, and your positive-peak beat detector reports almost no beats. In two or three sentences, explain the most likely physical cause, describe a signal transform that would make your detector polarity-invariant, and state one check you would add so the pipeline flags rather than silently drops these records.
Self-Check
1. Why is the QRS complex, rather than the P or T wave, the standard anchor for beat detection and heart-rate estimation?
2. The 12-lead ECG has twelve traces but only about eight independent channels. What causes the redundancy, and why is it useful rather than wasteful?
3. A single-lead smartwatch gives a clean rhythm trace but cannot localize ischemia. Explain this using the idea that a lead is a projection direction of one cardiac vector.
What's Next
In Section 29.2, we put this morphology to work at scale: how arrhythmia and atrial-fibrillation detectors read the rhythm of the beats you can now name, why the absence of an organized P wave and the irregularity of R-to-R intervals betray AFib, and what changes when you must run that detection continuously across millions of noisy wearable streams instead of one clean clinical strip.