## 2 Methods  
### Development of the Automatic Heart-Sound-Analysis Algorithm  
The proposed hybrid smart stethoscope was not only designed for heart-sound aus-cultation, but also for automatic heart-sound analysis. Because one cycle of the PPG signal occurs between the first systole and the next systole, the key idea of this device is to measure heart sounds and the PPG signal simultaneously, and then, using the PPG signals in the same cycle as a reference, to identify the S1 and S2 heart sounds. Before the identifying process, there are two preprocessing phases that use the raw data of the heart sounds and the PPG signals measured by the sensors in the device: one that determines the boundaries of S1 and S2 heart sounds, and another that detects the peak of PPG signals. Figure 2 shows the procedure of heart-sound preprocessing from the raw data to the boundary determinations based on variational mode decomposition (VMD) [9; 18; 19]. The heart sounds pass through a digital filter that rejects baseline components and high-frequency noises first, from which the PCG signal, including S1 and S2 sounds, and systolic murmurs are detected. Due to the likely existence of varying peak envelopes in the heart sounds, a third-order Shannon entropy was implemented in this study to reduce the peak variations, following the formula:  
\[SE=-\frac{1}{N}\sum_{i=1}^{N}\Bigl{|}x_{(i)}^{\ 3}\Bigl{|}log\Bigl{|}x_{(i)}^{\ 3} \Bigr{|} \tag{1}\]  
where \(x\) is the PCG signal processed by the adaptive amplitude thresholding rule to reduce the number of false positives, and \(N\) is the length of the moving integration window, which was set to 20 samples (20 ms) with a sampling frequency of 1 kHz to be compliant with the duration of S1 and S2 heart sounds [16]. With a smoothing process based on linear zero-phase filtering with a rectangular impulse response, the multiple peaks and spikes of the PCG signals were reduced, as shown in Figure 2b. The boundaries of the local heart sounds were found by the envelope threshold rule as defined below:  
\[GL_{(i)}=\left\{\begin{array}{ll}1&\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (0.01+SE_{avg}<SE)\\ 0&\ \ \ \ \ \ \ \ \  
shown in Figure 2d, demonstrating that preprocessing was capable of accurately locating the start-points of the heart sounds.  
Figure 3 shows the procedure of the PPG signals as processed from pulse waveform delineation to the systolic peak detection. To reduce background noise, the frequency threshold range was set between 0.5 and 5 Hz, which accorded with the maximum heart rate, 220 bpm [20]. A smoothing algorithm was implemented to smooth the PPG signals as follows:  
\[SD_{n}=\frac{\sum_{i=1}^{n}A_{i}}{n} \tag{3}\]  
where \(n\) is the number of moving averages, \(A\) is the noise-reduced PPG signal, and the number of zero crossings is set to 10. Shannon entropy also was implemented in the PPG signal preprocessing to determine the systolic peak. The location of the systolic peak was determined by finding the maximum of the windowed sequence, which is centered at the detected peak location with a spread of 10 samples. The S1 heart sound corresponds with the systole, and the time it takes for blood to flow from the heart to the finger is less than 500 ms. In addition, the S2 heart sound always occurs around the peak of the PPG signal \(\pm\) 20 ms [21; 22; 23; 24; 25]. Therefore, an identification rule was developed to distinguish the S1 and S2 heart sounds by calculating the time interval between the peak of the PPG signal and the start-point of heart sound as follows:  
\[HS_{sp}=\left\{ \begin{array}{ll}S1_{sp}&\left(T_{peak}-500\ \text{ms}\leq T_{sp}<T_{peak}-20\ \text{ms}\right)\\ S2_{sp}&\left(T_{peak}-20\ \text{ms}\leq T_{sp}\leq T_{peak}\ +20\ \text{ms}\right) \end{array} \right. \tag{4}\]  
where \(T_{peak}\) is the time of the PPG signal's peak, and \(T_{sp}\) is the time of the PCG signal's start-point in the same cardiac cycle.