# MATLAB/PPG High-Difficulty Reproduction: Respiratory Rate from PPG

## Target paper / method family

This reproduction targets the high-difficulty MATLAB PPG respiratory-rate literature around:

- Pimentel, M.A.F. et al. **Towards a Robust Estimation of Respiratory Rate from Pulse Oximeters**. IEEE TBME, 2016. DOI: 10.1109/TBME.2016.2613124.
- Charlton et al. **An assessment of algorithms to estimate respiratory rate from the electrocardiogram and photoplethysmogram**. Physiological Measurement, 2016/2017 open access.
- Public toolbox: RRest, MATLAB respiratory-rate estimation toolbox: https://github.com/peterhcharlton/RRest

The full paper/toolbox evaluates hundreds of combinations of:

1. Respiratory signal extraction from PPG/ECG: baseline wander, amplitude modulation, frequency modulation, etc.
2. Respiratory-rate estimation: FFT, AR spectra, pole selection, autocorrelation, breath detection.
3. Fusion: modulation fusion and temporal smoothing.

## Dataset

BIDMC PPG and Respiration Dataset, PhysioNet:
https://physionet.org/content/bidmc/1.0.0/

This scaffold downloaded the first 10 recordings in CSV form:

- `bidmc_##_Signals.csv`: PPG (`PLETH`), respiration (`RESP`), ECG channels.
- `bidmc_##_Breaths.csv`: manual breath annotations from two annotators.

The dataset documentation states that BIDMC contains 53 eight-minute recordings sampled at 125 Hz and was used to evaluate RR algorithms from PPG.

## What was reproduced

This is a first high-difficulty scaffold rather than a full 314-algorithm reimplementation.

Implemented:

- MATLAB-compatible script: `reproduce_ppg_rr_matlab.m`
- Python numerical runner for this environment: `run_ppg_rr_reproduction.py`
- 64-second windows with 32-second step.
- Reference RR from manual breath annotations.
- PPG respiratory signal extraction:
  - raw baseline-wander spectral method,
  - feature baseline from pulse troughs,
  - amplitude modulation from peak-trough amplitude,
  - frequency modulation from inter-pulse interval.
- Spectral RR estimation in respiratory frequency band.
- Simple smart-fusion style rule.
- Bias, MAE, and 95% limits of agreement against manual breath-derived RR.

## Current verified results

Data used: first 10 BIDMC subjects, 136 windows.

| Method | n | Bias bpm | MAE bpm | 95% LoA low | 95% LoA high |
|---|---:|---:|---:|---:|---:|
| PPG raw baseline wander | 136 | -1.006 | 1.563 | -8.134 | 6.122 |
| PPG smart fusion scaffold | 136 | -11.136 | 11.416 | -22.513 | 0.240 |
| Impedance respiration channel | 136 | -0.082 | 0.471 | -1.630 | 1.465 |
| PPG feature BW | 136 | -10.149 | 10.976 | -23.883 | 3.585 |
| PPG AM | 136 | -11.194 | 11.711 | -23.176 | 0.788 |
| PPG FM | 136 | -10.575 | 11.128 | -23.658 | 2.507 |

## Interpretation

The raw PPG baseline-wander method gives a usable first-pass RR estimate on this subset, with MAE around 1.56 bpm. The impedance respiration channel is much closer to manual breath annotations, as expected because breath annotations were made using the impedance respiration signal.

The feature-based PPG modulation streams and naive fusion are currently poor. This is a useful negative result: the difficult part of the original RRest-style work is robust pulse detection, ectopic/outlier removal, respiratory-band interpolation, quality assessment, and fusion. The scaffold exposes exactly where the gap is.

## Re-run

Python verified runner:

```bash
python3 reproductions/ppg_rr_matlab_pimentel2016/run_ppg_rr_reproduction.py
```

MATLAB-compatible script, in MATLAB:

```matlab
cd reproductions/ppg_rr_matlab_pimentel2016
reproduce_ppg_rr_matlab
```

Note: the current runtime does not have MATLAB or Octave installed, so MATLAB execution itself could not be verified here. The companion Python implementation was executed and produced the reported metrics.

## Next steps for full high-difficulty reproduction

1. Install MATLAB or Octave with signal-processing functions.
2. Clone and run the official RRest toolbox.
3. Expand from 10 to all 53 BIDMC subjects.
4. Reproduce the paper's algorithm families systematically:
   - XA1-XA4 filter methods,
   - XB1-XB10 feature methods,
   - EF1-EF7 frequency methods,
   - ET1-ET5 time-domain breath detection,
   - FM1-FM4 and FT1 fusion.
5. Match published Bland-Altman / LoA tables.
