Skip to content

physiosync

Timing corrections for multi-signal physiological recordings: the stamp sawtooth, hidden frame clocks, the ECG-to-PPG delay and its sawtooth, and the resolution of fiducial points. Dataset-neutral.

Repository github.com/metrology-atlas/physiosync
Branch main
Visibility public
Licence MIT
Language Python 3.10+ (numpy, scipy)
Related vitaldb-bench, lineaccess

What it is

physiosync works on times and samples it is given. It reads no file format and assumes no particular dataset, monitor, sampling rate or frame rate; a dataset's import code calls it and stores the results (corrected timing and quality labels). Corrections are applied only where they are corroborated, and each comes with a confidence tier.

Its part in the atlas

It holds the general methods that several VitalDB studies rely on: the stamp-clock fit (The stamp sawtooth model for SNUADC and BIS), the frame-clock search (The PPG's 30 Hz frame clock), the ECG-PPG sawtooth removal (The PPG sawtooth and its correction, The rebuilt PPG slip finder and its correction) and fiducial resolution (Every time is quantised, and fiducials inherit it). vitaldb-bench scripts call it on VitalDB cases.

Install

pip install "physiosync @ git+https://github.com/metrology-atlas/physiosync@v0.3.4"

Version 0.3 adds the rebuilt slip finder and fit_ecg_ppg_delay(method="rebuilt") (The rebuilt PPG slip finder and its correction); the earlier method stays the default and gives the same results as 0.2.0 (checked on 324 recordings, tools/port_delay_regress.py). 0.3.2 rebuilds the correction after an end-to-end check against the arterial line (tools/correction_vs_art.py): each tooth closes exactly, uncertain slips are ramps, and unresolved teeth and recordings whose creep is not corrected are left alone. 0.3.3 applies a stored whole-release slip fit to other beats of the same recording (slip_result=) and gives rebuilt fits measurement records and labels per tooth; the atlas's PPG timing labels and its pulse arrival time example use it (PPG timing quality, Pulse arrival time in two correction steps).

What is in it

stamps.py Record stamps that follow a sample clock between corrections; fits the rate and offsets and removes the stamp sawtooth.
frames.py Finds a hidden frame clock at any rate, from the spectrum of sample-to-sample change and fiducial locking.
quantisation.py Effective temporal resolution of fiducial points, on whole-sample grids or partly locked to a period.
ecg_ppg.py The ECG-to-PPG delay; fits and removes the frame-slip sawtooth, with confidence tiers (two methods, detect and rebuilt).
slips.py The rebuilt slip finder; beat quality and pulse shapes, slips with their evidence, tooth tiers and the delay to remove.
labels.py One label per sawtooth tooth, with its correction, resolution and confidence.
chains.py Rate-consistent chains of slips, as lower-confidence labels.
measurement.py The PAT measurement model of a recording, for downstream estimators.
pairing.py Beat pairing between ECG and PPG.
reference.py Published pulse arrival times by study and hardware.

Studies that use it

Study Code Summary
The PPG sawtooth and its correction physiosync/ecg_ppg.py, physiosync/slips.py, physiosync/labels.py The ECG→PPG delay creeps at 18–52 ppm and jumps up by one 33.3 ms frame at each slip, every 11–31 minutes. First of the sawtooth series. Its first correction, a tooth-by-tooth fit (physiosync's detect method), was essentially exact where confident on injected test data; it has been replaced as the atlas default by the rebuilt correction of The rebuilt PPG slip finder and its correction, which brings finger PAT closer to arterial PAT, and is kept here as history.
The PPG's 30 Hz frame clock physiosync/frames.py, physiosync/quantisation.py ECG and PPG fiducials resolve to one 2 ms sample, but PPG fiducials taken on raw samples lock to a hidden 33.3 ms frame grid. Scanning for it finds the oximeter's frame clock to about 1 ppm, a fixed fingerprint of each recording setup.
The rebuilt PPG slip finder and its correction physiosync/slips.py Fourth of the sawtooth series (Finding and placing each PPG frame slip finds the slips, The PPG sawtooth's period, its phase jumps, and the reversed sawtooth their grid, Where the PPG sawtooth stops where it stops). The slip finder is rebuilt around one rule: correct a step only when the evidence that it is a frame slip is strong, because a wrong correction puts a false step into real physiology. It judges each candidate on the shape of the pulse and, where there is one, on the arterial line, and corrects only one-frame steps. Checked against 172 blinded manual labels, a review of 174 corrections and sawtooths injected into real recordings, it called no held-out slip-free event a slip and 98% of the corrections reviewed were judged right. Its correction was then tested end to end against the arterial line in 2,976 recordings, which showed the first version made a third of them worse; rebuilt so each tooth closes exactly, it brings finger PAT closer to arterial PAT than the earlier method (median spread 9.46 against 11.17 ms in sawtooth recordings, 13.95 uncorrected), though it leaves more recordings worse than uncorrected (7.3% against 2.9%). physiosync 0.3.2, fit_ecg_ppg_delay(method="rebuilt").
The stamp sawtooth model for SNUADC and BIS physiosync/stamps.py Fitting each track's record stamps against its sample count as a drift with corrections (a sawtooth) puts SNUADC and BIS on one timeline without any artefact. Checked against shared bursts, the EEG–ECG timing error falls from about 790 ms on the recorded stamps to 33 ms with one constant per SNUADC mode in the pilot, and 40 ms over the whole release.
Where the PPG sawtooth stops physiosync/ecg_ppg.py Third of the sawtooth series (Finding and placing each PPG frame slip, The PPG sawtooth's period, its phase jumps, and the reversed sawtooth), rebuilt on 2 November and run on the full release on 3 November. With the new slip detector and the slip grid, stretches of 1.5 teeth or more without a slip are fewer than first reported: 1,072 stretches, 469 hours, in 796 of 5,714 recordings. Most of those inside a recording are two teeth long, and where the slips on either side lie on one grid, the step the grid predicts is usually there, missed because a ramp or a disturbance coincided with it. Where the phase moves across a stretch, it moves by quarter teeth. Some stretches look flat; the frame clock keeps its rate and phase through them; and the 586 recordings without any one-frame step show no hidden sawtooth, though many drift slowly.

Observations it handles

Observation Status Summary
Every time is quantised, and fiducials inherit it established A time on a grid of step Δ carries an error of Δ/√12 (1 SD). In VitalDB that is 0.58 ms for a 500 Hz sample, 2.3 ms for BIS EEG, 0.8 ms for the arrhythmia annotations' 1/360 s grid, and up to ±17 ms for PPG fiducials taken on raw samples, which lock to the 33.3 ms frame.
The ECG→PPG delay is a sawtooth established Inside the oximeter the PPG content creeps 18–52 ppm against its 30 Hz frames; every 11–31 minutes the delay steps up by one 33 ms frame (no repeated frame shows in the waveform). The rate is fixed per recording setup.
The plethysmogram is built in 30 Hz frames established The SNUADC PLETH waveform comes from the oximeter in 33.3 ms frames, smoothed to 500 Hz. Its content changes once per frame, on the oximeter's own clock, about 0.4 s after the finger.

Worked examples

Example Side Status Summary
Pulse arrival time in two correction steps time current As stored, the ECG-to-finger PAT in VitalDB is about 0.72 s, far beyond any physiological value, because a device delay of about 0.39 s and a frame-slip sawtooth sit inside it. Removing the sawtooth narrows finger minus arterial PAT from 13.6 to 11.1 ms in the median case, and removing one global delay brings PAT to about 0.33 s to the upstroke, keeping the differences between patients.

Mentioned in

References

  • Harris CR, Millman KJ, van der Walt SJ, et al. Array programming with NumPy. Nature. 2020;585(7825):357-362. ↗
  • Virtanen P, Gommers R, Oliphant TE, et al. SciPy 1.0: fundamental algorithms for scientific computing in Python. Nat Methods. 2020;17(3):261-272. ↗
  • LaussenLabs. hrvmatch [source code]. GitHub. ↗
  • Krekel H, Oliveira B, Pfannschmidt R, Bruynooghe F, Laugher B, Bruhin F. pytest. 2004. ↗