## 3 Methods
### Signal Preprocessing
#### 3.2.2 Data Generalization  
The length of audio files in the dataset is diverse, ranging from 4 s to 120 s. However, CNN takes a constant size of image as an input. If the audio signals of 4 s and 120 s are made into spectrograms of the same size, the difference is large even within the same class. Additionally, the different lengths of the data make feature extraction more difficult if the data are not sufficient. Therefore, the following method was used to make constant lengths of data. Two assumptions were made for the experiment:  
* Heart sounds can be judged to be about 5 s.
* Abnormal heart sounds are observed within 5 s.  
To achieve a constant length of data, we assumed that it took about 5 s to judge between normal and abnormal heart sounds. However, extracystoles, where the pulse beats normally and then skips once, can occur once or twice or dozens of times a minute. Atrial fibrillation, in which the heart beats irregularly, can also be temporary or persistent. \begin{table}
\begin{tabular}{c c c c} \hline \hline  & \multicolumn{2}{c}{**Cardiac Signal**} & \multicolumn{2}{c}{**Frequency Range (Hz)**} \\ \cline{2-4} Heart sounds & First heart sound & Normal & 100–200 \\ \cline{2-4}  & Second heart sound & Normal & 50–250 \\ \hline  & & Aortic stenosis & 100–450 \\ \cline{2-4}  & & Pulmonary stenosis & 150–400 \\ \cline{2-4}  & Systolic murmur & Mitral regurgitation & 60–400 \\ \cline{2-4}  & & Tricuspid regurgitation & 90–400 \\ \cline{2-4}  & & Atrial septal defect & 60–200 \\ Heart & & Ventricular septal defect & 50–180 \\ murmurs & & Mitral stenosis & 45–90 \\ \cline{2-4}  & & Tricuspid stenosis & 90–400 \\ \cline{2-4}  & & Aortic regurgitation & 60–380 \\ \cline{2-4}  & & Pulmonary regurgitation & 90–150 \\ \cline{2-4}  & & Patient ductus arteriosus & 90–140 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Types of heart sounds and corresponding frequency ranges. Therefore, in the experimental data, the assumption that this irregular abnormal heartbeat occurs within 5 s was added. The number of samples in the audio file was equalized to adjust the length of the heart signal. Sampling range was determined using the cardiac sound peaks. The peaks of S1 and S2 can be found using the time interval features of S1 and S2. Figure 3 shows S1 and S2 detection through time difference. The time difference between S1 and S2 ranges from 250 to 350 ms, and between S2 and the next S1 the time ranges from 350 to 800 ms. Therefore, after finding peaks larger than a certain amplitude, the intervals between the peaks were calculated. If the previous interval was between 250 and 350 ms and the current interval is between 350 and 800 ms, then S1 and S2 can be identified [22]. Ref. [22] was able to find S1 and S2 easily in ideal heartbeats, but there are many exceptions for diseased heartbeats. For example, as shown in Figure 4, S1 and S2 were not found when the size of a particular heartbeats were large or small, when the intervals between the extracted peaks were irregular, when the intervals of the heart signals were not constant, or if the heart signals were not clear. In this paper, we propose a method of finding peaks and make them into constant length data. Normally, S1 is louder than S2 at the apex, and softer than S2 at the base of the heart. Empirically, the louder heart sound was close to 1, and the softer heart sound had about half the amplitude of the loud sound in the normalized signal. Thus, 0.65 was set as the threshold, and then peaks larger than the threshold were selected from the normalized signals. Since the cardiac cycle is 800 ms, a peak larger than 0.65 with at least 800 ms intervals was considered the main cycle S. The coordinates of the S were obtained through the Scipy python library. Among them, the first S and sixth S coordinates were truncated to produce data. However, if the heart beats irregularly or if the murmur is large, it is impossible to find S1 using this method and to cut it at regular intervals.