Skip to main content

m31 · Capstone: AF electrogram analysis on real recordings (PhysioNet iafdb)

Warning

Education only. Not for diagnosis, treatment or any clinical decision.

Note

Draft, stage 2 of 6. The derivations are written, and each equation is checked by tests in tests/test_m31_af_analysis.py. Demos, the guided code lab, questions and the remaining sections follow in later stages (plan: docs/outlines/m31-outline.md). Nothing here has had expert review yet.

In 60 seconds

Real recordings are messier than simulations. The ventricles shout over the atria, baselines wander, amplitudes may not be calibrated, and annotations are automatic. This capstone takes one public database of intracardiac atrial fibrillation (AF) recordings from raw files to a short, reproducible report on activation rate and organization at four catheter sites. Along the way it shows how each processing choice changes the answer, and how to state the uncertainty honestly.

From the field

Planned in the outline (docs/outlines/m31-outline.md); written in a later stage.

Derivations

Symbols used throughout. \(x(n)\) a sampled signal, \(f_s\) its sampling rate (Hz). \(n_k\) the sample index of the \(k\)-th detected QRS complex. \(\bar t(m)\) the average beat (template), defined for \(m = -L_1, \dots, L_2\) samples around the QRS. \(N_b\) the number of beats averaged. DF dominant frequency (Hz), CL cycle length (ms).

The recordings

The Intracardiac Atrial Fibrillation Database (iafdb) is published on PhysioNet (Intracardiac Atrial Fibrillation Database (Version 1.0.0) 2003; Goldberger et al. 2000). Its page, checked on 2026-11-04, describes 32 records from 8 patients, four catheter placements per patient (record names end in svc, ivc, tva and afw), sampled at 1 kHz with 14-bit resolution. Each record has intracardiac bipolar channels and surface ECG leads; the page is not consistent about the number of ECG leads, so the lab reads the channel list from each header. Two facts shape the analysis:

  • Amplitudes are uncalibrated. Nothing in this capstone reports a voltage in mV, and amplitudes are not compared across records.
  • QRS annotations are automatic and uncorrected. The lab checks them before using them.

The license is the Open Data Commons Attribution License v1.0: the data may be reused with credit.

Taking the ventricles out

Ventricular activity appears in surface leads and, as far field, in intracardiac channels. It repeats with each QRS complex, while atrial activity during AF does not. Averaging segments aligned on the QRS therefore keeps the ventricular part and averages the atrial part away:

\[ \bar t(m) = \frac{1}{N_b}\sum_{k=1}^{N_b} x(n_k + m) \tag{1}\]

Subtracting the template at every detected QRS leaves the atrial activity plus a residual:

\[ x_A(n) = x(n) - \sum_k \bar t(n - n_k) \tag{2}\]

This is average-beat subtraction. Its weakness is that it assumes every ventricular complex looks the same. When QRS morphology changes from beat to beat, residual energy remains; a spatiotemporal method that allows for such changes reduced the residual QRST error to 58 % of that of plain average-beat subtraction on simulated signals (Stridh and Sörnmo 2001). For intracardiac dominant-frequency analysis, ventricular far-field signals significantly affected DF, and subtracting a ventricular template helped (Ng et al. 2007).

How many beats? Whatever is not locked to the QRS (atrial activity, noise) enters the template with variance \(\sigma^2\) per beat. If those contributions are independent from beat to beat, the template carries

\[ \operatorname{Var}\!\left[\bar t(m)\right] = \frac{\sigma^2}{N_b} \tag{3}\]

of it, so the residual falls as more beats are averaged, until changes in QRS shape dominate.

Key takeaways

  • The template keeps what is time-locked to the QRS; atrial activity averages out as \(1/N_b\).
  • Average-beat subtraction assumes identical ventricular complexes; check the residual.

Rate and its stability

The dominant frequency defined in m29 implies a cycle length; its spread across windows says how stable the rate is:

\[ \mathrm{CL}_{\mathrm{DF}} = \frac{1000}{\mathrm{DF}}, \qquad \mathrm{CV}_{\mathrm{DF}} = \frac{s_{\mathrm{DF}}}{\overline{\mathrm{DF}}} \tag{4}\]

with CL in ms for DF in Hz, and \(s_{\mathrm{DF}}\) and \(\overline{\mathrm{DF}}\) the standard deviation and mean of DF over sliding windows. Window length is a trade-off: short windows follow changes but give unreliable DF; in one technical study, records longer than 2 s were needed for reliable DF (Ng et al. 2007).

Key takeaways

  • DF implies a cycle length of \(1000/\mathrm{DF}\) ms only when one rate dominates the window.
  • Report window length and the window-to-window variability with every DF.

Honest uncertainty

Values from neighbouring windows are correlated: overlapping windows share samples, and AF rate drifts slowly. Correlated observations carry less information than their number suggests (Killip et al. 2004), so an interval computed as if every window were independent is too narrow. The fix is to resample whole blocks of consecutive windows, or whole records, so the correlation stays inside each block. With values split into \(B\) non-overlapping blocks, draw \(B\) blocks with replacement, compute the statistic \(\hat\theta^\ast_b\) of their concatenation, repeat for \(b = 1, \dots, R\), and take the interval

\[ \left[\, q_{\alpha/2}\!\left(\hat\theta^\ast\right),\; q_{1-\alpha/2}\!\left(\hat\theta^\ast\right) \right] \tag{5}\]

from the quantiles \(q\) of the \(R\) resampled values. Blocks must be longer than the correlation time. On strongly correlated synthetic data, single-value resampling missed the true mean far more often than the nominal 5 %, and block resampling came much closer (a test checks this).

Key takeaways

  • Resample the unit that is independent: blocks of windows, records or patients, never samples.
  • The same rule appears in m35 for patients and records.

Clinical correlate

NotePending clinical review

Planned in the outline. Requires sign-off by an EP physician.

Visual summary

Planned in the outline.

How experts think

Planned in the outline.

Cheat sheet

Planned in the outline.

Interview questions

Planned in the outline.

Code lab

Planned in the outline.

Self-check

Planned in the outline.

Literature figures

Planned in the outline.

Further reading

Planned in the outline.

References

Goldberger, A. L., L. A. Amaral, L. Glass, et al. 2000. “PhysioBank, PhysioToolkit, and PhysioNet: Components of a New Research Resource for Complex Physiologic Signals.” Circulation 101 (23): e215–20. https://doi.org/10.1161/01.cir.101.23.e215.
Intracardiac Atrial Fibrillation Database (Version 1.0.0). 2003. PhysioNet. https://doi.org/10.13026/C23S33.
Killip, Shersten, Ziyad Mahfoud, and Kevin Pearce. 2004. “What Is an Intracluster Correlation Coefficient? Crucial Concepts for Primary Care Researchers.” Annals of Family Medicine 2 (3): 204–8. https://doi.org/10.1370/afm.141.
Ng, Jason, Alan H Kadish, and Jeffrey J Goldberger. 2007. “Technical Considerations for Dominant Frequency Analysis.” Journal of Cardiovascular Electrophysiology 18 (7): 757–64. https://doi.org/10.1111/j.1540-8167.2007.00810.x.
Stridh, M, and L Sörnmo. 2001. “Spatiotemporal QRST Cancellation Techniques for Analysis of Atrial Fibrillation.” IEEE Transactions on Biomedical Engineering 48 (1): 105–11. https://doi.org/10.1109/10.900266.