## 2 Materials and Methods
### Optimization of SF Architecture for PLI Suppression in ECG Signals  
Although the presented SF principle is fundamental, the SF architecture was further optimized for the specific application for PLI filtering in ECG signals. The implementation and optimization of the digital SF algorithm was performed in Matlab 2020b (MathWorks Inc., Natick, MA, USA) using artificial and clinical ECG signals from CTS-ECG and PTB databases, respectively. The proposed optimal architecture of the SF filter is shown in Figure 6. Both inputs \(V_{SIG}\) and \(V_{REF}\) were considered at a sampling frequency \(F_{s}=2\) kHz, which is higher than the original ECG databases. Therefore, all ECG signals at \(V_{SIG}\) input were preliminarily upsampled using the Matlab function resample(). The reference input \(V_{REF}\) is originally generated as a sinusoidal wave at 2 kHz sampling rate. The branch for PLI estimation includes a simple FDF band-pass filter with a transfer function (16). FDF has a unity gain response for the PLI frequency. It removes the DC offset and differentiates QRS complexes. Next, QRS limiter is necessary to cut extreme signal amplitudes, such as QRS complexes and high T waves exceeding a certain amplitude threshold. The threshold of the limiter is adaptively defined as follows. The absolute value of the signal at the FDF output is processed in a window of 10 ms (half PL period), and the maximum value is measured. In the next step, the extracted maximal values are averaged in a window of 50 ms in order to remove accidental spike artifacts. Finally, the averaged values are evaluated within a window of 200 ms (chosen to exceed the longest QRS duration). The minimum value is deduced and used as the positive and negative thresholds of the QRS limiter, thus being adapted to the current PLI level. The QRS limiter does not introduce group delay in the loop. It just limits the amplitude and helps to reduce the QRS influence on the demodulated signals fed to the two integrators in the loop filter. The loop filter is simplified and the two averagers are removed. It consists only of an integrator and a stability coefficient \(k_{i}\). If we assume \(k_{i}=2^{-21}\), the Q factor of the SF filter would be Q \(\approx\) 9, rejecting a bandwidth of \(\pm\)2.8 Hz around the PLI frequency. The added FDF and QRS limiter do not reduce the stability reserve in the closed loop, as it passes the PLI frequency by approximately zero phase shift.  
The used AGC open-loop architecture has already been discussed in Section 2.3. Its stabilized \(V_{AGC}\) amplitude was set to 200 \(\upmu\)V as an approximation of the geometric mean between the minimal and maximal PLI amplitude in the real ECG signals, (e.g., 50 and 1000 \(\upmu\)V, respectively), and thus it ensures symmetrical control range of AGC LPF was implemented in AGC as a simple one PL period averager. For better filtering, the widow of this averager is adjusted when PL frequency deviates from its nominal value. Although many other LPF architectures can be used, the average gives the fastest response. While there is no need for linear-phase LPF, the minimum-phase LPFs explained in [13] or cascaded LPFs could also be used for better filtering. It should be noted that the implemented absolute value converter doubles the PLI frequency. Thus, LPF should accurately cancel the second harmonic of PLI, otherwise it would be converted in a third harmonic at the AGC output.