# A Dual-Adaptive Approach Based on Discrete Cosine Transform for Removal of ECG Baseline Wander
## 2 Methods
### The Proposed Dual-Adaptive Scheme
#### 2.2.2 Searching for the Optimal Cut-Point before CFF  
According to Equation (2), ECG signals can be decomposed into a combination of cosine waves. An example of the decomposition of the low-frequency part of the ECG, whose frequency is below CFF, is shown in Figure 3. In Figure 3b, each cosine waveform is generated from one DCT coefficient, as shown in the following formula.  
\[x_{k}(n)=w(k)y(k)\cos(\pi(2n-1)(k-1)/2N) \tag{5}\]  
where \(x_{k}(n)\) is the cosine waveform generated from the \(k^{th}\) DCT coefficient \(y(k)\).  
These cosine waves could have overlapped with each other, but certain amounts of offset were added to separate them exactly for a good presentation. Two phenomena are illustrated in Figure 3b. Firstly, the cosine waves tended to have higher frequencies while the indexes of the DCT coefficient were increasing. Secondly, the waves near both the BW area and the CFF area had higher magnitudes, so the optimal cut-point to distinguish BW and the ECG could be regarded as a certain value in the area where the cosine waves bunched up together. The summation of those cosine waves below the cut-point yielded a trend signal (the red curve in Figure 3a), which was the ideal estimation of BW.  
The goal of determining the optimal cut-point was transformed to search for the area where cosine waves were the flattest as shown in Figure 3b. Assume that there were a total number of \(I_{CFF}\) waves whose frequencies were below CFF, where \(I_{CFF}\) was calculated according to CFF by Equation (4).  
These waves were uniformly divided into \(G\) groups, therefore each group contained the same number \(M\) of waves, where \(M\) is the quotient of \(I_{CFF}\) divided by \(G\).  
\[g_{min}=\argmin_{g}\sum_{k=(g-1)*M+1}^{g*M}2*A_{k}1\leq g\leq G \tag{6}\]  
where \(A_{k}\) is the amplitude of the \(k^{th}\) cosine waveform, and \(g\) denotes the group's index. As illustrated in Figure 3c, the way to determine where the optimal cut-point is located is to calculate the \(g_{min}\) group which has the minimum value of amplitudes by Equation (6).  
With Equations (3) and (5), we can deduce that:  
\[A_{k}=|w(k)|*|y(k)|=\left\{\begin{aligned} |y(k)|/\sqrt{N}& \ k=1\\ |y(k)|*\sqrt{2}/\sqrt{N}&\ 2\leq k\leq N\end{aligned}\right. \tag{7}\]  
Therefore, we obtain the equivalent of (6) without considering the constant:  
\[g_{min}=\argmin_{g}\sum\
olimits_{k=(g-1)*M+1}^{g*M}|y(k)|\ 1\leq g\leq G \tag{8}\]  
where \(|y(k)|\) is the absolute value of the \(k^{th}\) DCT coefficient.  
Based on the above analysis, we searched the optimal cut-point directly according to Equation (8) by analyzing DCT coefficients whose frequencies were below CFF:  
Figure 3: Determine the optimal cut-point between BW and ECG (lead AVF of PTB record patient004/s0020 arem). (**a**) Raw ECG signal (blue curve) and BW (red curve). (**b**) Cosine waves, each of which is generated from one DCT coefficient. (**c**) Amplitude of low-frequency components, each component is generated from two DCT coefficients.  
The lower order DCT coefficients of the ECG signal \(x(n)\) were calculated according to the following equation.  
\[y(k)=w(k)\sum_{n=1}^{N}x(n)\cos(\pi(2n-1)(k-1)/2N),\;k=1,2,\ldots,I_{CFF} \tag{9}\]  
These coefficients were used to construct an amplitude vector \(A=[a_{1},a_{2},a_{3},\ldots,\;a_{G}]\), each element of \(A\) was a summation of the same number \(M\) of \(|y(k)|\). The minimum element in vector \(A\) was investigated to obtain its index, \(g_{min}\). The index \(I_{OCP}\) of the optimal cut-point in \(y(k)\) was calculated from the following equation.  
\[I_{OCP}=M*g_{min} \tag{10}\]