The subtraction procedure for PL elimination was first elaborated some two decades ago [22]. This procedure does not affect the ECG components neighbouring the PL frequency. This theoretical study is carried out for the basic PL frequency, but the conclusions are also valid for its harmonics and, consequently, for an arbitrary interference waveform. The efficiency of the procedure does not depend on the amplitude of the interference, as long as the amplifier is not saturated. Moreover, the procedure copes successfully with changes in amplitude and frequency of the interference. The procedure has been continuously improved over the years [12, 13, 23–32], and implemented in thousands ECG instruments and computeraided systems [33, 34]. Similar approaches have also been published by other researchers [35–41].
Principles
The subtraction procedure is applied originally with sampling frequency f_{
S
}, a multiple of, and hardware synchronized with the PL frequency f_{
PL
}. The procedure consists of the following steps [22]:

ECG segments with frequency band near zero are continuously detected using an appropriate criterion. They are referred to as linear segments and are found mainly in the PQ and TP intervals, but also in sufficiently long straight parts of the R and T waves.

The samples of these segments are moving averaged, i.e., subjected to a linear phase comb filter [42] with first zero set at f_{
PL
}. Thus, the filtered samples do not contain interference.

Interference amplitudes, called corrections, are calculated for each of the phaselocked samples, n, in the PL period, T_{
PL
}, by subtracting the filtered samples from the corresponding ones of the contaminated (original) ECG signal.

The set of corrections obtained is continually updated in linear segments and used in nonlinear segments (usually around QRS complexes and highamplitude T waves) to subtract the interference from the original ECG signal.
One of the first results obtained by the subtraction method is shown in Fig. 1 [22]. Interference was added to a clean simulated ECG signal in order to evaluate the errors and the efficiency of the method.
Linear criterion
A linear criterion, Cr, usually corresponds to the second difference of the signal (mathematical evaluation of the linearity). The first Cr [22] is defined in the following manner. Six consecutive first differences, FD_{
i
}, are calculated using signal samples, X_{
i
}, spaced at one T_{
PL
}:
FD_{
i
} = X_{
i+n
}  X_{
i
}, for i = 1 ... 6 (1)
The PL interference in the first differences is suppressed if n = f_{
S
}/f_{
PL
}. In this case n = 5, since the procedure was developed initially for rated f_{
PL
} = 50 Hz and f_{
S
} = 250 Hz. Furthermore, the maximum FD_{
max
}and minimum FD_{
min
}values are taken to determine Cr:
Cr =  FD_{
max
} FD_{
min
} <M, (2)
where M is the threshold value.
Typical linear and nonlinear segments are shown in Fig. 2. Real ECG signal (trace a) is superimposed by interference (trace b). The linear segments include low frequency signal and powerline frequency components. An approximate frequency spectrum of such linear segments is shown in Fig. 3.
This criterion works accurately, but can hardly be applied in real time because its relatively slow implementation. This drawback is overcome by Christov and Dotsinsky [23] who use a modified criterion of just two subsequent differences.
Cr =  FD_{i+1} FD_{
i
} <M. (3)
The first sample, which does not fulfill equation (3), is associated with the beginning of a nonliner segment. In the nonlinear to linear transition, equation (3) should be satisfied consecutively n times in order to avoid premature detection of the linear segment. The criterion is implemented in real time for f_{
S
}= 400 Hz and n = 8.
Later, Dotsinsky and Daskalov [13] defined the criterion as two nonsubsequent differences:
Cr = FD_{i+k} FD_{
i
} <M, for k >1 (4)
This approach makes the transition from linear to nonlinear segment more precise.
Compensation of PL amplitude variations
The more frequently the corrections are updated, the better compensation of the amplitude variations of the PL is achieved. Therefore, the linear criterion threshold, M, has to be reasonably less restrictive so that the errors, committed by averaging some segments that depart from the ideal linear signal, are smaller than the errors, that will appear if M initiates sporadic updating of the correction. Initially, M was fixed at 160 μV [22]. Later, heuristic values were found to be M = 150 μV [23] and M = 100 μV [13].
Linear filtering
For odd sample number n = 2m + 1 in one period of the PL interference, the filtered value:
is phasecoincident with the nonfiltered one.
In case of even number n = 2m, the two values are phaseshifted by a half of the sample period:
but become inphase coincidence using the formula
It is possible to take for averaging every second, third or q^{th}sample if n/q is integer. Depending on whether n/q is odd or even, equation (7) or (8) is used, respectively.
A special case of maximum sample reducing arises with q = n/2 [28]. The corresponding formula:
is called 'threepoints' filter. In addition to equation (8), the following formula
can also be applied if q is even. In case of q = n/2, the filter becomes 'twopoints' and is represented by:
Reduced sample number in a period of the interference will lead to enhanced steep slope of the comb filter lobes and will shorten the computation time. However, these 'advantages' must be assessed carefully in order not to violate the Nyquist rule with a large amount of the third harmonic present. The other harmonics are not taken into consideration since the highest odd harmonics are usually suppressed by lowpass filters with cutoff in the range of 100–150 Hz, while the even ones are practically absent because of the precise pole manufacturing of the electric power station generators.
Compensation of PL frequency variation
The allowed deviation from the rated PL frequency is limited in some countries up to 1% by the standards. In practice, deviation is oftentimes higher. Kumaravel et al. [43] reported for variation of 3%. McManus et al. [44] found considerable changes in the interference frequency, which is superimposed on recordings taken from the Common Standards for Electrocardiography (CSE) database.
Frequency variations lead to a special case of nonmultiple sampling with real n, instead of integer one. This complication can be bypassed if the deviations are detected by continuous hardware measurement of f_{
PL
}and corrected by small adjustments of the sample interval t_{
S
}around its rated (R) value, t_{
RS
}= T_{
RPL
}/n (here, T_{
RPL
}= 20 ms is the rated T_{
PL
}for f_{
RPL
}= 50 Hz). For f_{
PL
}, deviation between 49.5 and 50.1 Hz, the t_{
S
}variations are in the range of 1%, and consequently they do not introduce errors beyond the accepted measuring accuracy of parameters that are usually used for automatic ECG classification.
A first approach associates the triggering of each first sample, S_{
1
}, of the sequences S_{
k
}(k = 1, 2...n) in the periods T_{
PL
}with arbitrary chosen but constant amplitude of the PL voltage. The next samples, S_{
k
}(k = 2...n), are spaced at t_{
S
}, which is obtained by t_{
S
}= T_{
RTL
}/n. For 50 Hz, and n = 5, t_{
S
}= 4 ms. Two types of errors committed using this approach are studied by Dotsinsky and Daskalov [13]. The first, due to intersample irregularities, may reach 1% at f_{
S
}= 400 Hz and 1.2% at f_{
S
}= 250 Hz, in case of 1% deviation around the f_{
RPL
}. The second type of error does not exceed 3% and is a consequence of the additionally shifted location of the filtered sample.
Dotsinsky and Daskalov [13] reported an improved approach. The ongoing period T_{
PL
}is measured and divided by n. The obtained t_{
S
}is used in the subsequent T_{
PL
}.
Efficiency assessment of the procedure
Subtraction procedure examples are shown in Fig. 4 and Fig. 5. The ECG signals are taken from the American Heart Association database. The signals are notch filtered to suppress the 60 Hz (PL frequency in the US) interference. Then, the signals are mixed with 50 Hz interference, amplitude modulated from 0 through 3.2 mV_{pp} by a slew rate of 200 μVs^{1}. The traces are identified as follows: i) input signal; ii) synthesized interference; iii) mixed signal; iv) processed signal; v) difference between original and processed signals and vi) zoomed difference. Actually, the discarded components also include electromyographic (EMG) and other noises. A nonsuppressed part of the signal, together with small residual interference and distortions due to compromise with the M value are also present in the differences.
Two signals are used to assess the efficiency of the subtraction procedure with respect to the interference only. The first, taken from our own database, is called conditionally 'clean' (Fig. 6). The result shows small differences between input and processed signals, visually due to the noise presented in the input. This result is verified with the second synthesized signal, which does not contain any disturbances (Fig. 7). As can be seen, no distortions are introduced. The same synthesized signal is superimposed by interference and processed (Fig. 8). No residual interference can be found.
Influence of EMG noise
Sometimes EMG noise is so high that the linear segment finding is hampered. As a consequence, inaccurate corrections, which do not correspond to the last change of the interference amplitude, will cause errors (see the residual noise between the 11^{th} and 14^{th} s in Fig. 9).
A very simple approach for suppression of EMG noise influence on the procedure introduces an additional parallel buffer where ongoing portions of the signal are unconditionally averaged [31]. This buffer is used for accurate linearity detection. Fig. 10 and Fig. 11 show the comparison of results without and with the parallel buffer. The traces 'a' represent ECG signal mixed with interference and EMG noise. The traces 'b' in Fig. 10 and 'c' in Fig. 11 indicate transitions from linear to nonlinear segments (onoff functions). As can be seen, the averaged signal part in Fig. 10 is very limited. As a consequence, the procedure efficiency is reduced (Fig. 10c and 10d. In contrast, the parallel buffer allows detection of long linear segments (Fig. 11c and the residual noise in the processed signal (Fig. 11d is low. However, the noise is not totally suppressed because a part of it participates in the correction calculation.
Further improvement in EMG noise suppression is obtained by Christov [29] by using adaptive threshold value M, which is calculated with respect to the noise/signal ratio Rt, defined as Rt = S_{
NL
}/S_{
F
}, where the noise level S_{
NL
}equals the summary width of the nonlinear segments in an epoch S_{
F
}, approximately corresponding to the RR interval under consideration. Linearity search with a criterion of M = 150 μV for 'clean' ECG (Fig. 12a) and for the same signal, but contaminated with EMG noise (Fig. 12b) show different S_{
NL
}, (Fig. 12c and 12d). The method is developed in MATLAB environment. The initial threshold M is chosen equal to 30 μV. Then, it is gradually increased until Rt reaches 10%, after which the subtraction procedure is started. The level Rt ≤ 0.1 value is suggested by the ratio 'QRS width versus its RR interval', which is usually around 10%. The elimination of both interference and EMG noise can be observed in Fig. 13b and 13d, where M = 420 μV is used. For comparison, the 'clean' ECG signal is processed with M = 35 μV (Fig. 13a and 13c).
Linear segments cannot be regularly found in patients with atrial and ventricular fibrillation. However, the total preservation of the wave shape is not necessary for fibrillation detection and therefore, all kinds of traditional filters may be applied.
Interference suppression in highresolution ECG
The subtraction procedure is not directly applicable to the bodysurface HisECG, as the low amplitude and relatively low frequency Hiswave can not be distinguished in linear segments. Thus, the Hiswave will be, in practice, suppressed or even removed from the signal. The EMG noise is usually of higher amplitude and with much higher frequency content compared to the surface Hiswave. Therefore, simple change of the threshold value, M, does not result in acceptable delineation of linear and nonlinear segments.
Bazhina et al. [45, 46] implemented the following modification. The beginning of the detected nonlinear segment before a QRS complex is shifted 100 ms to the left, thus defining the Hiswave region as a nonlinear segment by default (Fig. 14).
The subtraction procedure and three other methods: notch filters, spectral interpolation [47], and regression subtraction [35] are tested against minimal distortion of the original signal [45]. The subtraction and the regressionsubtraction procedures proved to be the best, as Baratta et al. [35] use a similar concept for noise estimation in linear segments. Regressionsubtraction deals poorly with amplitude changes of the interference within the current segment.
Case of batterysupplied devices and computer aided ECG systems
The hardware measurement of f_{
PL
}, necessary for compensation of the interference frequency modulation, is not feasible in batterysupplied devices and in some computer aided ECG systems. Dotsinsky and Stoyanov [12] studied the range of frequency changes of interference with constant amplitude, for which the residual part is restricted to acceptable levels without use of synchronized sampling. They found that residual interference below 20 μV_{pp} could be obtained with the procedure by: i) interference amplitude ≤ 0.4 mV_{pp} and ii) frequency change with a rate ≤ 0.0125 Hzs^{1}. Since such requirements for the powersupply can often be exceeded, a software interference measuring was developed.
The ECG signal is processed initially by a 49–51 Hz bandpass filter. The amplitudes of two adjacent samples, Br_{
L
}and Br_{
R
}, taken from a positivegoing slope of the interference, located below and above the zero line, are measured (Fig. 15). The distance, t_{
CP
}, between the crossing point CP and the right sample, Br_{
R
}, is computed continually by:
In case of T_{
PL
}change, t_{
S
}is redefined using
This approach was implemented in the MATLAB environment. For sampling frequency f_{
S
}= 500 Hz and f_{
RPL
}= 50 Hz, n is equal to 10. The product kn determines the time recommended to elapse before calculating and substituting new t_{CP,i + kn}for the previous t_{CP,i}. Fig. 16 shows a processed 1 mV ECG signal after being mixed by interference with 2 mV_{pp} constant amplitude and extremely fast varying by 1 Hz per 8 s frequency (first trace). To assess the efficiency obtained, the zoomed difference without synchronized sampling (last trace) is also presented.
The next logical step to be taken consists of: i) keeping the rated t_{
S
}of the ECG instrument, ii) resampling the signal according to the ongoing measured f_{
PL
}in order to eliminate the interference and iii) returning to the rated t_{
S
}. The first results of such an approach are highly promising [48]. Thus, the software compensation of the variable f_{
PL
}, as well as a total implementation of the subtraction procedure in an instrument, including automatic adjustment for f_{
RPL
}of 50 or 60 Hz, will be completed regardless of the hardware circuits and the corresponding software.
Automatic adaptation to the rated PL frequency
A common program for alternative interference subtraction in 50 and 60 Hz environment leads to nonmultiple sampling, i.e. to real n. Widely used values of t_{
S
}for f_{
RPL
}= 50 Hz, such as 250, 500 and 1000 Hz, correspond to irrational n of 4.1(6), 8.3(3) and 4.1(6) if 60 Hz interference has to be eliminated. In the inverse case, f_{
S
}= 360 Hz requires n = 7.2. Rounded values n* are unacceptable to use, since they would introduce considerable error.
A very simple solution not needing f_{
S
}change was found by Dotsinsky and Stoyanov [30]. The original procedure applies a comb filter over one period, T_{
PL
}, of the interference. Thus, the program runs faster. Generally, n may be taken from k > 1 entire periods. The procedure is operated if:
n = kT_{
PL
}/t_{
S
}is an integer.
For t_{
S
}= 2 ms (f_{
S
}= 500 Hz) and f_{
RPL
}= 50 Hz, the smallest value of k satisfying equation (14) is really k = 1. However, in case of 60 Hz, k equals 3. Zeros associated with the subharmonics 20 and 40 Hz will appear too but they have no influence on the procedure. Therefore, it is quite enough to switch n between 10 (k = 1) and 25 (k = 3) in order to operate with both interferences. For this purpose two digital bandpass filters check the incoming signal. Fig. 17 shows that the filter with frequency band overlapping the interference generates an order of magnitude higher output signal than the other filter.
Theoretical procedure development
The theory of the subtraction procedure was developed further by Mihov [27], Levkov and Mihov [28], and Mihov et al. [32]. They proposed four types of filters, implemented in a generalized structure that may overcome the problems with almost all cases of nonmultiple sampling, including interference frequency variations, without using synchronized AD conversion.
The socalled Dfilter in multiple sampling is defined as is Cr in equation (2), where the second difference, D_{
i
}, is obtained with FD s that are spaced at one T_{
PL
}:
D_{
i
}= (X_{
i+n
} X_{
i
})  (X_{
i
} X_{
in
}) = X_{
in
} 2X_{
i
}+ X_{
i+n
} (15)
The transfer function of the Dfilter has zeros at f = 0 and f = f_{
PL
}Hz, which is shown equal to 50 Hz in Fig. 18.
The Kfilter describes the moving average presented by equations (5) and (6). Its transfer function is given in Fig. 19 for n = 5 in case of odd multiplicity.
The equation used for ongoing calculation of the interference components:
B_{
i
}= X_{
i
} Y_{
i
} (16)
actually defines a digital filter called (1K)filter.
Furthermore, the filters are redefined for nonmultiple sampling, and f_{
S
}= 250 Hz in conjunction with f_{
RPL
}= 60 Hz is taken in consideration to illustrate the software improvement.
In order to preserve the transfer function zeros, the Dfilter has to be subtracted with a correction filter with zero at f = 0 and gain of D_{
RPL
}at f = f_{
RPL
}, equal to the gain of the Dfilter for the same frequency, f_{
RPL
}. The correction filter synthesis is based on a threepoints auxiliary filter given by the equation:
where (n/2)* is the rounded value of n/2.
Since A_{
RPL
}is the gain of the auxiliary filter for f = f_{
RPL
}, the correction filter is multiplied by the ratio D_{
RPL
}/A_{
RPL
}. Using the corresponding transfer functions, D_{
RPL
}and A_{
RPL
}are computed in advance by:
Finally, the corrected D*filter is presented as
and is shown in Fig. 20 by trace 'c', where traces 'a' and 'b' are the Dfilter and the correction filter, respectively.
The transfer function of the Kfilter must preserve zero for f = f_{
RPL
}, unity gain for f = 0 and linear phase response. The procedure of the Kfilter correction is similar to the previous one. An auxiliary filter is given by the formula used for corrections computation:
A_{
i
}= X_{
i
} Y_{
i
}, (20)
The filter gain is equal to 1  K_{
RPL
}for f = f_{
RPL
}, where K_{
RPL
}is the Kfilter gain for the same frequency f_{
RPL
}. The auxiliary filter is multiplied by K_{
RPL
}/(1  K_{
RPL
}) and subtracted from the Kfilter. The equation for the corrected K*filter is:
The constant K_{
RPL
}can be estimated by:
for odd or even multiplicity, respectively.
An example of Kfilter correction is shown in Fig. 21, where traces 'a', 'b' and 'c' represent the primary Kfilter, the auxiliary filter, and the corrected K*filter.
In case of nonmultiple sampling, a phase difference appears between the ongoing ECG samples and the interference components B_{
i
}(equation 16) usually located in a temporary firstinfirstout (FIFO) buffer. Therefore, B_{
i
}must be modified being subtracted from the ECG samples during nonlinear segments. The compensation procedure is relatively complicated. Fig. 22 shows the contents of the temporary buffer. The current interference sample, B_{
in
}*, does not coincide with the restored sample, B_{
i
}. Its amplitude must be recalculated in order to compensate the phase difference between them. This is accomplished by a new filter with linear phase response and unity gain for f = f_{
RPL
}, denoted as the Bfilter. It is synthesized from the known Kfilter, with a window equal to the interference period. In case of odd n*, it can be described as:
where K_{
RPL
}is the gain for the interference of the averaging filter given by equation (22).
The restored buffer value B_{
i
}can be calculated by:
In case of even n*:
The Bfilter transfer function is shown in Fig. 23.
The generalized structure is presented in Fig. 24, where the modules of the subtraction procedure are as follows:

Linearity detection. Dfilter is applied to evaluate the linearity of each signal sample neighbourhood.

Interference extraction. (1K)filter is used to calculate the interference component.

Criterion. The condition Cr <M sends either extracted or restored PL interference to Subtraction.

Interference temporary buffer. The extracted or restored interference component used as correction in nonlinear segment is saved at the position locked with the ongoing phase of the powerline interference.

Interference restoring. Bfilter is called in case of nonmultiple sampling in order to restore the true correction values, which have to be subtracted from the input signal samples in nonlinear segments.

Delay buffer. Compensates the delay, which appears with the Dfilter and (1K)filter and is imperative if the procedure is run in quasireal time. Otherwise, the buffer could be disregarded.

Subtraction. Extracted or restored interference value is subtracted from the delayed input signal to output 'clean' ECG signal. In case of nonlinearity both Interference extraction and Subtraction implement the Kfilter.
An improved algorithm according to the generalized structure has been tested offline. The results for f_{
S
}= 250 Hz and f_{
RPL
}= 60 Hz are shown in Fig. 25.