# Detection of Respiratory Phases in a Breath Sound and Their Subsequent Utilization in a Diagnosis
## 2 Materials and Methods
### Signal Processing
#### 2.2.2 Data Processing and Detection of Respiratory Phases  
The respiratory phase identification is based on the assumption that the lauder sound has a higher amplitude deviation than the quieter sound during the time of respirator phase change. For easier, faster and more accurate identification of maximal and minimal deviation of pressure amplitude, it is appropriate to use an envelope of the signal calculated as:  
\[e(t)=\sqrt{x(t)^{2}+\hat{x}(t)^{2}}, \tag{1}\]  
where \(\hat{x}(t)\) is the Hilbert transform of input signal \(x(t)\)[14]. The Hilbert transform, using a 32-points Parks-McClellan FIR filter, is a specific linear operator that creates the envelope of the signal while remaining the same time distribution as the original signal. The upper part of the envelope includes positive values of amplitudes only, while whole signal oscillates between positive and negative values. Therefore, it can be effectively smoothed--Figure 4.  
Figure 3: Unfiltered respiratory sound of a healthy female participant-Patient No. 1. Recorded at jugular, age 13 years old, without bronchial obstruction. Chaotic progress of the acoustic pressure due to the noise in the sound. The phonendoscope Littmann 3200 records the amplitude of the acoustic pressure as a relative quantity normalized to maximum value 1. The amplitude of the acoustic pressure is therefore in arbitrary units. Unfortunately, the envelope is greatly affected by the phonendoscope manipulation artefacts. These artefacts cause a random increase of the amplitude in the recording and because the artefacts are not related to the respiratory sounds, they need to be removed from the recording. The removal is performed according to the following algorithm:  
\[\text{if: }x_{i+1}>x_{i}+\widetilde{r}_{1/2}, \tag{2}\]  
\[\text{then: }x_{i+1}=x_{i+1}-\widetilde{r}_{1/2}, \tag{3}\]  
where \(i=\langle 1,k\rangle\), \(x\) is the value of the envelope at a specific time, \(k\) is the length of signal interval approximately equal to the length of the defect (the approximate value of the variable \(k\) is set to 0.06 s) and \(\widetilde{r}_{1/2}\) is the median value of the lower half of the set of differences of consecutive values of the envelope in the interval \(k\). The algorithm is applied along the entire length of the recording. The recording without an abrupt change in the amplitude returns relatively constant values at the interval of \(k\) and the value \(\widetilde{r}_{1/2}\) remains low. If the amplitude changes rapidly at the interval \(k\), the value \(\widetilde{r}_{1/2}\) also increases. This increase in \(\widetilde{r}_{1/2}\) indicates a presence of noise and the amplitude is consequently attenuated in the envelope. The edited envelope can be further processed for calculating the local minima with the parameter \(f_{rp/2}\) (approximate duration of the respiratory phase). To identify the local minima precisely, the envelope was smoothed with the moving average with the window length of 100 data points. As there is an inter-individual variation in breath sound, it is necessary to manually control more parameters in the algorithm for the correct automatic identification of the respiratory phases. A favorable and easily adjustable parameter is the approximate rate of the change of the respiratory phases \(f_{rp/2}\) that reflects duration of one phase--inspiration or expiration. This feature varies according to patient's age and the health condition. The software is able to work with an approximate value \(f_{rp/2}\), which is advantageous in the cases of different lengths of the respiratory phases and changes of these phases length during the audio recording. For most participants, it is possible to define the same value of the respiratory phases \(f_{rp/2}=1\) s but for larger deviations from a given value \(f_{rp/2}\), it is necessary to define a specific duration of one phase for each participant individually, e.g., using age-specific normative values for respiratory rate [15].