# A Complete Pipeline for Heart Rate Extraction from Infant ECGs
## 2 Materials and Results
### The HR Pipeline
#### 2.3.4 Signal Quality Index Calculation  
In addition to developing methods to correct R-peak labels for longform infant ECGs, it is important to identify time periods that have many (consecutive) incorrect labels due to noisy measurements. Local linear interpolation is unable to accurately reflect the underlying HRs for these periods, and so they may need to be excluded from further data analyses. Thus, we developed an algorithm optimised for longform infant ECGs to help identify regions in which a data recovery approach was inadvisable. Pre-existing methods for HR quality assessment were not found to be suitable for long heart rates, and all of them were tuned on adult datasets. [PERSON] et al. [56] used a non-stationary signal, viable heart rate range, and high signal-to-noise ratio (SNR), but required the signal to be rejected/accepted in full. [PERSON] et al. [20] extracted shapes and behaviours of the signal to group ECG samples by an agglomerative clustering approach, an approach that becomes computationally inefficient for longer recordings. It is also  
Figure 12: The result of parameter variations for selecting different filter widths (FWs) and activation thresholds (ATs) with a local moving-median filter. (**a**) The total number of errors in the interpolation for the moving-median filters applied to a clean dataset, with 346 being the expected number of interpolations across the dataset. One 12-month infant with a mildly arrhythmic heart rate accounts for 4 of the incorrect interpolations in the optimal parameter choices. (**b**) The heart rate residual shows the difference between the interpolated heart rate and the true heart rate for the moving-median filter applied to a realistically processed dataset. A trade-off is then made between how strict the threshold is in removing incorrect peak labels compared to preserving the original signal. (**b**) Adapted from [PERSON] et al. [13], with additional data and labels added. worth noting that many SQI methods implicitly try to reject areas of high noise directly in the ECG [57]. The HeartPy method [36] explicitly rejects peaks that create a beat interval \(>\)30% above or below the mean interval time of the whole signal. [PERSON] et al. [58] used local kurtosis based on expected kurtosis values for ECG and common ECG noise sources. [PERSON] et al. [59] rejected peaks if the R-peak maxima was not followed by an S-trough minima at least 70% of the local (1 s wide) range of the signal. Additionally, [PERSON] and [PERSON] [60] proposed a noise-detection algorithm based on an agreement from different ECG algorithms. However, given the results in this paper showing the poor performance of most algorithms on infant ECGs (Figures 4 and 5), this approach was not explored here. The beat correction algorithm for missed/additional beats was used as a baseline measure of signal quality, with additional steps added to fine-tune the quality algorithm further. Figure 2 highlights that correctly labelled R-peaks typically fall inside the expected bounds, whereas incorrectly labelled R-peaks are likely going to either cause a steep decrease or increase in heart rate (for missing or additional labels, respectively). By calculating the proportion of \"wrong\" labels within a given filter width, a rolling measure of heart rate signal quality was calculated. If a small number of incorrect labels was present, a close approximation to the original heart rate could be recovered. If many measurements were incorrect, then the heart rate could not be reliably approximated. A filter width of 31 and an adaptive threshold of 1.3 were used (Figure 12b). A moving-median approach was used to create the base of a binary signal quality index (SQI) vector [13].