# A Complete Pipeline for Heart Rate Extraction from Infant ECGs
## 2 Materials and Results
### The HR Pipeline
#### 2.3.2 Correction for Missing and Additional Beats  
A missing R-peak causes two true measurements to be replaced by a single false measurement of approximately half value (Figure 11a), while an additional peak causes one true measurement to be replaced by two roughly double-false measurements (Figure 11b), although the proximity of the additional peak to existing peaks alters the amplification ratio of the subsequent heart rate. Two metrics were used to ascertain the ideal filter width and proportional threshold for HR processing. The first metric was used to evaluate the median approach applied to a clean set of R-peak labels that only contained a few errors. The second metric was used to evaluate the median approach applied to a realistically processed ECG. Dataset A (\(n=97\)) was captured using a BiosignalPlux device (PLUX Biosignals, Lisbon, Portugal) that recorded the ECG with Bluetooth. Across the 97 recordings, occasional disconnections occurred, leading to gaps in the signal (23 in total). Additionally, the noise arising from infant motion also led to short periods where no QRS complex could be identified (323). These gaps in the ground truth R-peak list resulted in drops in the derived HR signal. The optimal median filter approach identifies these gaps without removing any real signal. The expected number of gaps to interpolate over was recorded for each participant. The absolute difference between interpolations made by the filter and the expected number of interpolations was used to evaluate the optimal parameters for a clean environment. Figure 12a shows the variation in these results with different parameter choices. Next, the output from the proposed ECG pipeline (15 Hz HPF preprocessing, Neurokit2 peak detection) was used to represent a realistically preprocessed signal. The residual heart rate between the median-filtered ECG and a ground truth (with gaps interpolated over) was used to demonstrate the optimal parameters from a noisier baseline (Figure 12b). For the clean ECG test (Figure 12a), a high activation threshold (e.g., 1.7 or 1.8) combined with a narrow filter width (e.g., 7-21) produced a very low number of incorrect adjustments (<3% compared to the total number of adjustments or <0.0015% compared to every potential adjustment, e.g., every single heart rate beat). Almost all these incorrect adjustments were due to arrhythmias in the heart rate, causing a longer than expected gap between the detected beats. A very conservative threshold combined with very few beats needed to accurately determine the incorrect label made sense, given the cleanness of the ground truth. For the test with the processed ECG (Figure 12b), a much more liberal activation threshold (e.g., 1.2 or 1.3) with a much wider filter width (15-31) provided the optimal parameters for reducing the heart rate residual with this dataset. This accounted for the higher level of uncertainty in the underlying truth in the processed heart rate. Figure 11: A demonstration of potential inaccuracies arising in R-peak labelling algorithms. Each QRS complex should contain one R-peak label. The left column shows an ECG signal (purple) and peak labels. The black “x” shows the underlying true peak labels. The blue “+” and red “o” show incorrect labelling. The right column shows the corresponding instantaneous heart rate, calculated using Equation (1). The black, blue, and red lines/markers in the right column correspond to heart rates derived from the peaks in the ECGs. (**a**) A single lower heart rate measurement due to missing a beat; (**b**) two raised heart rate measurements due to an additional beat; (**c**) two incorrect heart rate measurements, one higher and one lower, with the order depending on the direction the beat is shifted. (**c**) Adapted from [PERSON] et al. [13].To detect beats that varied above/below a local median by more than a given proportional threshold, we used a median filter.