Skip to content

kzqureshi/ppg-diffusion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

ppg-diffusion

A compact, end-to-end pipeline that simulates physiological signals, trains a generative diffusion model on the synthetic data, and systematically evaluates the generated output. The worked example generates synthetic photoplethysmography (PPG) signals.

The project mirrors the simulation → synthetic training data → generative model → systematic evaluation workflow at small scale, and runs end-to-end on a CPU in ~2 minutes.

samples

Top: physically-simulated PPG signals. Bottom: signals generated by the trained DDPM. The model reproduces the systolic–diastolic double-peak pulse morphology, respiratory amplitude modulation, and realistic beat-to-beat spacing.

What it does

  1. Physical simulation (ppgdiff/simulate.py) — generates realistic PPG windows from a two-Gaussian pulse model with configurable heart rate, respiratory amplitude modulation, baseline wander, and measurement noise. This is the synthetic training basis.
  2. Generative model (ppgdiff/model.py, ppgdiff/diffusion.py) — a small 1D U-Net (~230k parameters) trained as a denoising diffusion probabilistic model (DDPM) to generate new PPG signals from noise.
  3. Systematic evaluation (ppgdiff/evaluate.py) — compares real vs. generated signals using physiologically meaningful metrics:
    • average power spectral density (Welch),
    • heart-rate distribution estimated from the spectral fundamental,
    • a single-number spectral log-PSD error.

Results (CPU, 60 epochs, 1024 training signals)

Metric Real (simulated) Generated (DDPM)
Mean heart rate 77.6 ± 14.3 bpm 78.5 ± 14.5 bpm
Spectral log-PSD MAE 0.126

The generated signals match the real distribution in both spectral content and heart-rate statistics — the model learned the underlying physiology, not just the average waveform.

Quickstart

pip install torch numpy scipy matplotlib
python train.py --epochs 60 --n-train 1024
# figures + metrics written to examples/

All hyperparameters are exposed as CLI flags (python train.py --help).

Why this design

PPG is a quasi-periodic signal with clear spectral structure, which makes the evaluation physically interpretable: a good generator must reproduce the heart-rate band and its harmonics, not merely look plausible. Working in 1D keeps the whole pipeline trainable on a laptop while exercising the same components — diffusion training, ancestral sampling, distributional evaluation — used in larger generative-modelling systems.

Structure

ppgdiff/
  simulate.py    # physical PPG simulator
  model.py       # 1D U-Net (noise predictor)
  diffusion.py   # DDPM schedule, training loss, sampling loop
  evaluate.py    # PSD + heart-rate evaluation metrics
train.py         # end-to-end: simulate -> train -> sample -> evaluate
examples/        # generated figures and metrics

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages