## 3 Materials and Methods
### Removing Noise from ECG Signals Using a Discrete Wavelet Transform  
Any digital signal is distorted by noises of varying nature. To isolate signal features, it is necessary to clean noise from them. An ECG signal that is distorted by noise can be written as:  
\[W(t)=S(t)+N(t), \tag{1}\]  
where \(W(t)\) is the ECG signal, \(S(t)\) is the ECG signal without noise distortion, \(N(t)\) is the noise on the ECG signal.  
Wavelet transform is a common way to remove noise from a signal [22]. To clean the noise from the ECG signals, a discrete wavelet transform (DWT) of the symlet family was used, which is a Daubechies wavelet with the least asymmetry and a compact carrier. The detail factor for each case is set empirically.  
There are three stages of using wavelet transform to clean the noise from the ECG signal. The first step is to obtain noisy wavelet coefficients using the DWT of a noisy signal. The second stage is the choice of thresholding. The third stage is an inverse wavelet transform to obtain a purified signal [23]. The DWT of the ECG signal is:  
\[DWT(a,b)=\frac{1}{\sqrt{2}}\sum_{j=0}^{N}W_{j}\int\limits_{j}^{j+1}\psi\bigg{(} \frac{t-b}{a}\bigg{)}dt, \tag{2}\]  
where \(N\) is the number of samples on the ECG signal, \(W\) is the ECG signal distorted by noise, \(\psi\) is a symlet, \(a\) and \(b\) variables can take on the values \(a=1\ldots N\), \(b=1\ldots N-1\).  
To obtain DWT, a low-pass analysis filter with an \(g\) impulse response and a high-pass analysis filter with an \(h\) impulse response are used. As a result of filtering, approximating and detailing coefficients are obtained [24].  
\[y_{low}(t)=\sum_{k=-\infty}^{\infty}W(k)g(2t-k), \tag{3}\]  
\[y_{high}(t)=\sum_{k=-\infty}^{\infty}W(k)h(2t-k). \tag{4}\]  
With each DWT application, the number of samples on the ECG signal is halved by Table 1[24,25]. Each subsequent decomposition is carried out in terms of the low-frequency component by Figure 3.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Number of DWT Levels** & **Number of Samples on the ECG Signal** \\ \hline
1 & \(\frac{N}{\pi^{2}}\) \\
2 & \(\frac{N}{\pi^{2}}\) \\... &... \\ n & \(\frac{N}{\pi^{2}}\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Length of ECG signals in DWT, where \(N\) is the initial number of samples on the ECG signal.  
The next step in clearing noise from the ECG signal is to select a threshold function and thresholding. The thresholding is a value that determines whether there is noise in the signal. If the value of the wavelet coefficient at a certain moment is greater than the value of the threshold, then it is considered the value of the signal, if less, then the noise [24]. To determine the threshold limit of the ECG signal, the minimax threshold was used [26]:  
\[T\leq\sqrt{2\ln N},\ T^{2}=2\ln(N+1)-4\ln(\ln(N+1))-\ln 2\pi \tag{5}\]  
The wavelet coefficients are transformed by thresholding, using the threshold functions. The functions of hard- and soft-threshold determination are most often used [24]. To determine the noise on the ECG signal, the soft-threshold function was used [26]:  
\[0\leq\max\biggl{(}1-\frac{T}{|x|},0\biggr{)}\leq 1, \tag{6}\]  
where \(x\) is the value of the wavelet coefficient.  
The reverse DWT for obtaining a cleaned ECG signal is as follows [24]:  
\[S(t)=\sum_{k=-\infty}^{\infty}\widetilde{g}_{k}y_{low_{k}}(t)+\sum_{m=-\infty} ^{\infty}\sum_{k=-\infty}^{\infty}\widetilde{h}_{m_{k}}y_{high_{k}}(t), \tag{7}\]  
where \(S(t)\) is the ECG signal without noise distortion, \(\widetilde{g}_{k}\) and \(\widetilde{h}_{m_{k}}\) are approximating and detailing coefficients after processing by the threshold function. The reverse DWT of the ECG signal is performed according to Figure 4.