This is the Python and MATLAB implementation of the algorithm proposed in the paper:
Pei, Soo-Chang, and Chien-Cheng Tseng."Elimination of AC interference in electrocardiogram using IIR notch filter with transient suppression." IEEE transactions on biomedical engineering 42.11 (1995): 1128-1132.
Full credit goes to the authors.
This technique uses vector projection to minimize the problem of transient values, common to the use of IIR filters:
The top signal corresponds to the original ECG signal with AC interference noise. The middle signal corresponds to the filtered ECG signal using a typical IIR notch filter. The bottom signal corresponds to the filtered signal using an IIR notch filter with the proposed transient suppression technique.
An example ECG signal is included (as a .mat file) for quick testing of the algorithm, which was obtained from the MIT-BIH Polysomnographic Database.