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.

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
- peak interval
- refractory period
- HRV
- BPM
Review sequence
- peak interval
- refractory period → HRV
- BPM
Official references
- STM32CubeF4 Getting Started (UM1730)
- STM32 DSP with CMSIS (AN4841)
- Arm CMSIS-DSP
- STM32CubeF4 repository
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.