## 3 EBI Signal Processing and Algorithm Development for HR Estimation
### Accurate HR Estimation by Peak Detection  
After the correlation is performed to the whole spectrum in all defined segments of the waveform to determine the best frequency, the maximum value is located along with the best frequency.  
To improve BPM estimation accuracy, BPM values that deviate from the median BPM by more than a defined threshold are set to the median BPM.  
Next, the window-based peak detection is performed: the EBI signal is divided into smaller windows as shown in Figure 7 (upper plot) (of a certain length obtained from the cross-correlation method, according to Equation (15) to determine the peaks in each window corresponding to heartbeats EBI value drops).  
Within each window, the peak (maximum value) is detected, and the time of the event is stored as seen in Figure 7 (bottom plot). From the detected values (peaks and peak locations or indices), location values are subsequently calculated into BPM, see in Equation (16):  
\[BPM_{i}=\frac{60}{\Delta t}, \tag{16}\]  
where \(\Delta t\) represents the time difference between peak locations.  
The window for processing the EBI signal is defined by subtracting one from the window size, calculated as shown in Equation (15). This adjustment ensures the window spans from the starting index 'i' to 'end'. Within each window, we identify the maximum peak value (maxPeak) and its index (maxIndex). The determination of the peak time (\(t_{peak}\) in seconds) is carried out according to Equation (17):  
\[t_{peak}=\frac{i+maxIndex-3}{f_{s}}. \tag{17}\]  
Then, we perform the BPM value determination using the peak location time intervals. To estimate the instantaneous HR (in BPM), we analyze the time intervals between consecutive peak locations. The BPM is calculated by dividing 60 by the time difference between peak locations, as illustrated by Equation (16).  
Then, we proceed with the computation of the median BPM (\(BPM_{median}\)) and the Median Absolute Deviation (\(BPM_{MAD}\)) of BPM values using the predefined functions available in the standard Matlab library. An outlier threshold is established as a constant \(\theta_{outlier}\) = 3, and the final BPM is determined using Equations (18) and (19). If:  
\[|\delta_{i}-BPM_{median}|>\theta_{outlier}\cdot BPM_{MAD}, \tag{18}\]  
then:  
\[BPM_{i}=BPM. \tag{19}\]  
The collected data underwent diverse analytical assessments. The PPG signal was subjected to the 'findpeaks' algorithm (MATLAB), establishing thresholds to identify signal peaks, albeit potentially misinterpreting them as heartbeats. Precision was augmented by meticulously adjusting the 'findpeaks' function parameters, specifically \"minPeakDistance\" and \"minPeakProminence\" for each PPG signal. This manual fine-tuning aimed to visually achieve the highest accuracy in results. The EBI signal underwent processing using the 'findpeaks' method and a newly developed algorithm called 'BPM DL'. Figure 8 shows the processed BPM data using the described methods.  
Figure 7: Example of EBI signal partition for the window-based peak detection (**upper plot**) and the peaks of the detected pulse waves (**bottom plot**).  
In summary, this algorithm estimates the BPM by first identifying the best frequency that correlates with the EBI signal using cross-correlation and then detecting peaks in the signal to estimate the HR more accurately. Finally, it calculates BPM based on the time differences between peak locations. The result is expected to provide an accurate estimation of the HR from the EBI signal.