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.
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.
- 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. - 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. - 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.
| 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.
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).
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.
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
MIT


