# Energy-Efficient and Real-Time Wearable for Wellbeing-Monitoring IoT System Based on SoC-FPGA
## 3 Proposed Biometric System
### Heart Rate Calculator Using PPG  
The heart rate calculator algorithm operates over two channels of the PPG signal, the red (RED) and the infra-red (IR), probed by distinct LEDs and photosensors. The computation of the hear rate comprises two main stages: preprocessing and periodicity search of both RED and IR signals. The computational operations included in the first one are the following:  
1. DC mean calculation: a loop over a buffer containing \(N\) signal samples computes the sum of their values, and then the average by dividing the accumulated sum by \(N\).
2. DC mean subtraction: the computed average is subtracted from each channel sample by an iterative loop.
3. Linear regression calculation: a dot product between the sample set and corresponding shifted sample indexes is computed, then divided by a constant.
4. Linear regression subtraction: the computed value is multiplied by each shifted sample indexes and subtracted from each channel sample.
5. Mean square calculation: the sum square of all sample values is calculated and divided by \(N\).
6. Pearson correlation calculation: a dot product (Equation (1)) between both channels' samples is determined and then divided by \(N\).  
where  
* \(N\) is the number of samples;
* \(x_{n}\) denotes a preprocessed IR sample;
* \(\bar{x}\) is the mean value of preprocessed IR samples, which is 0, because of DC removal;
* \(y_{n}\) denotes a preprocessed RED sample;
* \(\bar{y}\) is the mean value of preprocessed RED samples, which is also 0.  
A good quality signal must have a Pearson correlation equal or greater than 0.8. Otherwise, the sample set is discarded, and a new collection is recorded.  
From this stage, the algorithm initiates an iterative process of finding the signal periodicity, via peak detection. In this step underlies the concept of autocorrelation, a function that allows to identify patterns in a signal. More specifically, it consists of the correlation--or similarity--between a signal and its delayed copy. As such, taking into account that PPG is a periodic signal, this property is advantageous to determine heart rate, especially in noisy environments, such as probing data using bio-sensors. Mathematically, the autocorrelation \(R\) at a given delay \(m\) is the sum of the products between each sample (\(X(n)\)) and its delayed one (\(X(n+m)\)), over all \(N\) samples of set \(X\), shown in Equation (2):  
\[R(m)=\sum_{n=1}^{N}X(n)X(n+m) \tag{2}\]  
Figure 3 shows the result of computing the values of autocorrelation for all possible sample delays, from 0 to \(N-1\), where \(N=100\), and after normalizing the values relatively to the autocorrelation at delay \(N=0\).  
The shift \(k\) corresponding to the index of the closest local maximum matches the number of samples containing a complete heart beat. This peak, marked in Figure 3 by green, is sufficient to determine PPG signal periodicity. Therefore, pulse period \(T_{\text{HR}}\) is calculated multiplying the number of samples \(k\) by the time gap between two samples, that is, sample period \(T_{s}\). This way, the heart rate is the inverse of the pulse period, represented in Equation (3):  
Figure 3: Autocorrelation of PPG signal for different delays.  
\[\text{HR}_{\text{bps}}=\frac{1}{T_{\text{HR}}}=\frac{1}{k\times T_{s}}=\frac{1}{k \times\frac{1}{f_{s}}}=\frac{f_{s}}{k} \tag{3}\]  
where \(f_{s}\) denotes the sampling rate, inverse of \(T_{s}\). This result corresponds to beats per second (bps), so the beats per minute (bpm) are given by Equation (4):  
\[\text{HR}_{\text{bpm}}=\frac{f_{s}\times 60}{k} \tag{4}\]