## 2 Materials and Methods
### Automatic Common-Mode Gain Control  
The amplitude of the common-mode voltage \(V_{REF}\) (Figure 2) corresponds to the actual PLI level and can vary in a wide range depending on the stray capacitances of the body to the power grid and earth. It depends on the physical position of the body and its proximity to the mains-powered household appliances. Thus, \(V_{REF}\) amplitude must be stabilized by AGC to remain independent of the PLI amplitude. A closed-loop software AGC has been previously developed to stabilize the amplitude of the common-mode voltage, used for SPLL synchronization to the line frequency [37; 45]. Generally, the gain control element could be implemented either with digitally controlled analog circuits (e.g., multiplying digital-to-analog-converters (DACs), digital potentiometers, analog switches, and opamps in the AFE) or with a digital multiplier in the digital part. The major advantage of the closed-loop AGCs is their ability to minimize some deficiencies of the multiplier transfer function. The accuracy of the digital multiplier depends on the digital word of the multiplicands, i.e., on the ADC resolution. Because of the ideal transfer characteristics of the digital multipliers and detectors, the entire AGC could be implemented in the digital part, and thus to have an all-digital implementation. The simplest AGC has the open-loop architecture shown in Figure 5a. It relies on the ideal transfer characteristic of the digital multiplier. The major advantages of the open-loop AGC are related to the stable control system as well the independent settling time from the input signal level. The settling time is determined only by the settling time of the implemented low-pass filter (LPF) [49]. The open-loop AGC operates as follows. Assuming that \(V_{REF}\) has a sinusoidal waveform expressed by (2), the output of the low-pass filter (\(V_{LPF}\)) equals the averaged absolute value of \(V_{REF}\). Thus, the AGC output \(V_{AGC}\) can be expressed by (15), where \(V_{REF}\) is substituted by (2):  
\[V_{AGC}=\frac{V_{REF}V_{tar}}{V_{r}2/\pi}=\frac{V_{r}\sin(\omega t)V_{tar}}{V_ {r}2/\pi}=\frac{\pi}{2}V_{tar}\sin(\omega t) \tag{15}\]  
From Equation (15), it is clear that the amplitude \(V_{r}\) drops, and the stabilized amplitude depends only on the target value \(V_{tar}\). The latter should be selected taking into account the introduced \(\pi/2\) gain. For example, if the stabilized \(V_{AGC}\) amplitude is 200 LSB (1 LSB corresponds to 1 uV), \(V_{tar}\) should be preset to 128 LSB. For proper operation of AGC, any \(V_{REF}\) offset should be removed with a high-pass pre-filter. An appropriate digital  
Figure 5: Open-loop automatic gain control: (a) architecture, (b) start-up simulation. solution is a simple first difference filter (FDF), which removes the offset and passes the PLI fundamental frequency at a unity gain. Its transfer function for a sampling rate of 2 kHz is given by (16):  
\[T_{FDF}(z)=\frac{1-z^{-20}}{2} \tag{16}\]  
Just after turning on the system, the LPF output starts from zero, which produces very high values in AGC output \(V_{AGC}\). Therefore, an output limiter is added to truncate the output to \(\pm V_{lim}\), where the limiter threshold is equal to the nominal peak value of \(V_{AGC}\). Thus, at start-up, V\({}_{AGC}\) begins as a rectangular wave, which automatically converts to a trapezoidal wave, then to a truncated sine wave, and finally when LPF is settled it becomes a pure sine wave, according to the start-up simulations in Figure 5b. It should be noted that the open-loop AGCs are also known as feed-forward AGCs; however, the published architectures require complex computations with logarithmic and exponential functions [50]. The presented open-loop AGC has the advantage of being much simpler. The open-loop AGC architecture is based on the ideal transfer characteristics of the implemented digital blocks, such as digital detectors and multipliers. When a peak detector is used, AGC can operate even without LPF.