## 2 Proposed Method for Automatic Segmentation of Heart Sounds
In [46], the authors make a comparison of different methods used to calculate the envelope of the PCG signal, with the Shannon energy being the most effective for identifying the S1 and S2 peaks. In [9; 10; 11], this method is used, obtaining good results in the identification of S1 and S2 segments. The Shannon energy equation is defined as  
\[E=-x(i)^{2}log(x(i)^{2}) \tag{2}\]  
where \(x\) (\(i\)) represents the samples of the signal and \(E\) is [PERSON]'s energy. When calculating the quadratic value of a sample, large oscillations can be generated; the amplitude of the sample increases when the absolute value of the original amplitude is greater than 1 and decreases  
Figure 2: Decomposition of heart sound using EWT. **(A)** Heart sound recording; **(B)** FFT of heart sound with the frequency bands determined; **(C)** EWT components defined between 1–40 Hz. **(D)** EWT components defined between 40–80 Hz. **(E)** EWT components defined between 80–350 Hz. **(F)** EWT components defined at 350 Hz and above. otherwise. Therefore, it is convenient to use normalized energy, as in the case of the normalized average Shannon energy (NASE) [47], defined as follows:  
\[En=\frac{E-\mu}{\sigma} \tag{3}\]  
where \(\mu\) is the average value of energy \(E\) of the signal, \(\sigma\) is the standard deviation of energy \(E\) of the signal and \(En\) is the normalized average Shannon Energy. After calculating the NASE in the HS signal decomposed by the EWT--that is, that signal that has the S1 and S2 sounds--the negative values are equaled to zero and the signal is normalized. In Figure 3B, the result of an NASE signal of a heart sound recording can be observed. Analyzing the NASE signal, we will proceed to identify the edges of each lobe of the signal; this helps to determine the beginning and the end of the sound S1 or S2. The limits obtained from each lobe are shown in Figure 3C. A problem commonly occurs when there are lobes that are very close to each other; in this case, the lobe that has less energy is eliminated. This process is repeated three times. Lobes of short duration and low amplitude are also eliminated. Subsequently, the peaks in each lobe are calculated as shown in Figure 3D. Unwanted peaks are removed using the following steps:  
Figure 3: Stages of segmentation: (**A**) EWT component: heart sound; (**B**) NASE of the signal; (**C**) identification of borders of each lobe; (**D**) identification of S1 and S2 sounds. 1. Calculate the average of the intervals between peak (i) and peak (i + 1). 2. Eliminate the peaks that belong to an interval less than 0.25 * on average. 3. Eliminate the peaks that belong to an interval less than 0.3 * on average. 4. Eliminate the peaks that belong to an interval less than 0.4 * on average. 5. Eliminate the peaks that belong to an interval less than 0.55 * on average. There are cases in which the sound of S1 or S2 has a low amplitude and short duration, as seen in Figure 4A. Generally, the methods presented in the state-of-the-art approaches fail in this case. Taking into account the fact that the duration of the cardiac cycle is approximately 0.8 s and the diastolic interval is approximately 0.6 s [48], a condition is established in which the interval between each peak is evaluated, and if in most cases the interval is greater than 650 milliseconds, it can be said that there is a sound (S1 or S2) in that interval. Then, each interval is normalized as shown in Figure 4C. Subsequently, all the previous stages are performed to find sound S1 or S2. To identify the S1 and S2 sounds in a recording, it is enough to know that the systolic interval is located between S1 and S2, while than the diastolic is located between S2 and S1 of the next cycle. In addition, it is known that the systolic interval is always shorter than the diastolic [48]. With these criteria, it is easy to identify which are the sounds S1 and S2, systole and diastole. Figure 4: Segmentation of heart sounds with S1 of low amplitude and short duration.