STM32 · Embedded · 08

PPG Peak, HRV, and BPM Detection Flow

The baseline PPG source runs at 100 Hz and calculates first/second differences and peak intervals. A separate HRV module keeps four peaks, forms three gaps, rejects gaps outside a 20% margin, and then calculates BPM.

Full electrode, NUCLEO-F411RE, ECG, and PPG breadboard prototype

What I checked first

The baseline PPG source runs at 100 Hz and calculates first/second differences and peak intervals. A separate HRV module keeps four peaks, forms three gaps, rejects gaps outside a 20% margin, and then calculates BPM.

Source view

  • The newer PPG variant combines a slope sign change with a refractory interval to suppress duplicate peaks.
  • The HRV module computes a gap average and margin and returns BPM=0 when intervals are inconsistent.
  • No saved accuracy evaluation is present, so this page documents the algorithm structure only.

Code path

GapAvr = (Gap1 + Gap2 + Gap3) / 3;
margin = GapAvr / 5;
if (all_gaps_within_margin) {
    bpm = 60 * 1000 / GapAvr;
}

Key terms

  1. peak interval
  2. refractory period
  3. HRV
  4. BPM

Review sequence

  1. peak interval
  2. refractory period → HRV
  3. BPM

Official references

The reviewed sources contain 22 prototype photos, a 40-slide STM setup deck, a three-page KiCad schematic, an ADC/UART note, an HRV module, two PPG code records, twelve top-level ECG C variants, and a complete CubeIDE project archive. I do not count byte-identical variants or ST/Arm vendor files as separate results, and I make no new performance claim without saved measurements.

Publication first-page preview