## 2 Materials and Methods
### Estimation of the SF Performance  
The inputs of the SF algorithm are simulated as follows: the differential-mode signal \(V_{SIG}\) is generated by superposition of an original ECG signal (without noise) and artificially generated PLI sinusoid with predefined amplitude (\(A_{PLI}\)) and frequency (\(f_{PLI}\)), as shown in (17); the common-mode reference input \(V_{REF}\) is generated as an artificial sinusoid with a reference amplitude (\(A_{REF}\)), frequency (\(f_{PLI}\)), and phase shift (\(\varphi_{PLI}\)) as defined in (18):  
\[V_{SIG}=ECG(n)+A_{PLI}(n)\sin(2\pi f_{PLI}(n)n/F_{s}) \tag{17}\]  
\[V_{REF}=A_{REF}\sin(2\pi f_{PLI}(n)n/F_{s}+\varphi_{PLI}) \tag{18}\]  
where \(n\) denotes the sample number within the duration of the signal with \(N\) samples (\(n=1,\,2,\dots\) N). \(A_{PLI}\) and \(f_{PLI}\) can be linearly changing values, starting from a baseline \(A_{PLI0}\) and \(f_{PLI0}\) with predefined slew rates, namely, \(\Delta A_{PLI}\) (uV/s) and \(\Delta f_{PLI}\) (Hz/s), formally written as:  
\[A_{PLI}(n)=A_{PLI0}+n\Delta A_{PLI}/F_{s} \tag{19}\]  
\[f_{PLI}(n)=f_{PLI0}+n\Delta f_{PLI}/F_{s} \tag{20}\]  
When \(\Delta A_{PLI}\) = 0 uV/s or \(\Delta f_{PLI}\) = 0 Hz/s, the generated PLI sinusoid has a constant baseline amplitude or frequency, respectively. This simulation study considered ECG and PLI signals with duration of 10 s sampled at \(F_{s}\) = 2 kHz, N = 20,000 samples. The following ranges of PLI parameters were defined:  
* PLI with constant amplitude: \(A_{PLI0}\) = 50-1000 uV r.m.s. computed over 10 s. The maximal setting was chosen to represent a severe realistic scenario with peak-to-peak PLI amplitude reaching 2800 uV. * PLI with constant frequency: \(f_{PLI}\) = 48-52 Hz, exceeding the standards for maximal mains frequency deviation in the synchronous European grid of 49.8 Hz to 50.2 Hz. Figure 6: Optimized architecture of the closed-loop SF algorithm for PLI filtering. * PLI with linear amplitude change: \(\Delta A_{PLI}=\pm\)(10-200) \(\mu\)V/s. The maximal slew rate was chosen to represent the worst realistic scenario with peak-to-peak PLI amplitude span from 0 to 4000 \(\mu\)V within 10 s.
* PLI with linear frequency change: \(f_{PLI}=50\) Hz, \(\Delta f_{PLI}=\pm\)(0.01-0.1) Hz/s. The maximal slew rate was chosen to represent the worst realistic scenario for a change in the frequency of 1 Hz over 10 s, e.g., covering a span of 49-50 Hz and 50-51 Hz. * PLI with phase shift of the reference input \(V_{REF}\): \(\varphi_{PLI}=\) 0-360\({}^{\circ}\) in Equation (18). The SF algorithm performance was estimated by means of three benchmark metrics, namely, maximal error (_MAXE_), root-mean-square error (_RMSE_), and improvement in the signal-to-noise ratio (_SNRimp_), as follows:  
\[MAXE=\underset{1\leq n\leq N}{\max}\sqrt{\left[ECG(n)-V_{SF}(n)\right]^{2}} \tag{21}\]  
\[RMSE=\sqrt{\frac{1}{N}{\sum}_{n=1}^{N}{\left[ECG(n)-V_{SF}(n)\right]^{2}}} \tag{22}\]  
\[SNR_{imp}=SNR_{out}-SNR_{in} \tag{23}\]  
where the input SNR (_SNRin_) and output SNR (_SNRout_) are computed as follows:  
\[SNR_{in}=10 log_{10}{\left(\frac{\sum_{n=1}^{N}{\left[ECG(n)\right]^{2}}}{\sum _{n=1}^{N}{\left[V_{SIG}(n)\right]^{2}}}\right)} \tag{24}\]  
\[SNR_{out}=10 log_{10}{\left(\frac{\sum_{n=1}^{N}{\left[ECG(n)\right]^{2}}}{\sum _{n=1}^{N}{\left[V_{SF}(n)\right]^{2}}}\right)} \tag{25}\]  
MAXE and RMSE are the peak value and the root mean square value of the filter error equal to the difference between the filtered and original ECG signals. MAXE can be considered representative of the ringing noise after QRS complexes, which are typically the steepest ECG waves producing the maximal filter error. Smaller values of MAXE and RMSE imply a better performance of the filter. _SNRimp_ is the improvement in the SNR levels between the input and the output. A higher _SNRimp_ represents a better quality of the filtered ECG.