## 3 EBI Signal Processing and Algorithm Development for HR Estimation
### Cross-Correlation for BPM Estimation  
Cross-correlation was selected because it is a robust method for detecting periodic patterns in noisy, nonstationary signals [42], making it particularly well-suited for EBI-based HR estimation. EBI signals can be prone to interference from motion artifacts, physiological noise, and other environmental factors, which can obscure the HR signal. Cross-correlation helps mitigate these issues by comparing the acquired signal to a reference template or waveform, such as a clean heartbeat signal, to identify matching periodic features. This method enhances the accuracy of HR estimation for several reasons:  
1. Noise Resilience: Cross-correlation emphasizes similarities between the signal and the template, reducing the impact of random noise or artifacts that do not follow the expected periodic pattern of heartbeats. 2. Pattern Matching: Even when the signal is distorted, cross-correlation can still detect the presence of periodicity by identifying recurring patterns, ensuring that heartbeats are correctly identified even under suboptimal conditions. 3. Range Selection: Particularly suited for cardiac signals, cross-correlation can be targeted to a specific frequency range (e.g., 0.5 to 5 Hz), which encompasses the HR range. This targeted approach reduces unwanted processing and optimizes computational efficiency by focusing only on the relevant frequency band. After preprocessing, we pass the signal to a function that determines HR. HR estimation consists of two main parts: the cross-correlation part and the peak detection part. The Cross-Correlation method [41] for BPM estimation from the EBI signal is performed as follows: the input signal is divided into multiple equal parts \(M\) (10 parts for this signal). The signal is divided into parts based on its time constant and the duration according to Equation (5):  
\[\text{duration}=\frac{\text{length}(\text{in\_signal})}{\text{fs}},\quad \text{num\_parts}=\left\lfloor\frac{\text{duration}}{\text{time\_constant}}\right\rfloor \tag{5}\]  
where the _time_constant_ is selected between 2 and 4 s, optimizing the segmentation of the input signal for effective analysis. For each segment, frequencies between 0.5 Hz and 5 Hz are tested to identify the one that best correlates with the EBI signal, using sinusoidal generation and cross-correlation, as shown by Equations (6) and (7) :  
\[\sin_{a}(t_{i})=\sin(2\pi ft_{i}), \tag{6}\]  
\[\rho(X,Y,k)=\sum_{n=0}^{N-k-1}X[n]\cdot Y[n-k]. \tag{7}\]where \(X\) and \(Y\) represent the input signals, \(k\) is the lag parameter, which determines the time shift between the two signals, and \(N\) is the greater of the lengths of \(X\) and \(Y\). The equation calculates the similarity between \(X\) and \(Y\) as \(Y\) is shifted relative to \(X\). Positive values indicate a positive correlation, while negative values indicate a negative correlation. In this example, the correlation between input EBI signal \(X_{i}\) and generated sine signals \(\sin_{a}(f)\) are calculated. The frequency with the highest correlation is considered to support the effective monitoring of temporal variations in HR, closely approximating the best frequency for each part Equations (8)-(10). If the current frequency has a higher correlation, i.e., if the following is true:  
\[\theta_{i}(f)>max:_{\theta_{i}}, \tag{8}\]  
where  
\[max:_{\theta_{i}}=\theta_{i}(f) \tag{9}\]  
and  
\[\hat{f_{i}}=f, \tag{10}\]  
then, convert the best frequency to BPM and store it as Equation (11):  
\[BPM_{i}=\hat{f_{i}}\cdot\epsilon 0. \tag{11}\]  
Thereafter, calculate the mean BPM of all the best BPM values and update BPM values that deviate from the mean significantly. Then, calculate the difference from the mean BPM Equation (12):  
\[\delta_{i}=|BPM_{i}-B\hat{P}M|. \tag{12}\]  
If the difference is greater than the threshold, e.g., if Equation (13):  
\[\delta_{i}>\theta, \tag{13}\]  
then set Equation (14):  
\[BPM_{i}=B\hat{P}M. \tag{14}\]  
The signal is divided into frames of length:  
\[\sin_{a}(t_{i})=\sin(2\pi ft_{i}), \tag{6}\]0