Software Open Access
Automated Detection and Removal of Pacing Artifacts from ECG Signal
Rajkumar Dhar , Shivangi Kewalramani , Larisa Tereshchenko
Published: April 24, 2026. Version: 1.0.0
When using this resource, please cite:
Dhar, R., Kewalramani, S., & Tereshchenko, L. (2026). Automated Detection and Removal of Pacing Artifacts from ECG Signal (version 1.0.0). PhysioNet. RRID:SCR_007345. https://doi.org/10.13026/hq2h-8p89
Please include the standard citation for PhysioNet:
(show more options)
Goldberger, A., Amaral, L., Glass, L., Hausdorff, J., Ivanov, P. C., Mark, R., ... & Stanley, H. E. (2000). PhysioBank, PhysioToolkit, and PhysioNet: Components of a new research resource for complex physiologic signals. Circulation [Online]. 101 (23), pp. e215–e220. RRID:SCR_007345.
Abstract
Pacing artifacts in electrocardiogram (ECG) signals can interfere with accurate waveform analysis, making their detection and removal essential for reliable interpretation. We present an algorithm and provide MATLAB code to detect and remove pacing artifacts from raw digital 12-lead ECG recordings. The algorithm was developed using the Chronic Renal Insufficiency Cohort (CRIC) data, which includes 493 paced ECGs, and validated on an external dataset (273 paced ECGs). A graphical user interface (GUI) was designed to allow user-friendly quality control of automated algorithm performance. Users can adjust settings to achieve the desired result: complete removal of the pacing spike without removing the ECG waveform. The algorithm automatically detected and removed pacing artifacts in 82.8% of the 10-second ECG files in the validation set, while the remaining files required user input. The overall sensitivity and specificity for pacing artifact detection were 98.4% and 76.5%, respectively. In summary, the proposed algorithm effectively detects and removes ECG pacing artifacts with high automation, thereby minimizing the need for manual fine-tuning.
Background
Cardiac pacing is a vital treatment modality for managing heart rhythm disorders [1]. A pacemaker, a battery-powered device, regulates the heart rhythm by stimulating the heart as needed. The rate of Cardiac Implantable Electronic Device (CIED) implantation is increasing gradually due to expanding indications and broader therapeutic benefits [1].
Atrial and ventricular pacing can be identified by recognizing pacing artifacts preceding the P-wave and the QRS complex, respectively. Unfortunately, large pacing artifacts interfere with most ECG signal processing algorithms used for ECG fiducial point detection.
Given the clinical value of paced ECGs, efforts have been made to remove pacing artifacts from the signal to obtain an artifact-free ECG waveform. An open-source semi-automated algorithm was previously developed in our laboratory to identify the onset and offset of a pacing spike based on the steepness of the slope of the pacing artifact [2]. Developed by Haq et al. [2], the algorithm removed pacing spikes from the vector magnitude ECG signal, calculated from the orthogonal XYZ ECG after Kors transformation of the initially recorded 12-lead ECG, rather than from the 12-lead ECGs. The algorithm's advantage was its gentle approach to pacing artifact removal, starting with a narrow window of 8-15 ms for the suggested pacing artifact width, thereby aiming to preserve the manifestation of physiological activation. Then the user could gradually adjust the algorithm's parameters, incrementally widening the pacing artifact width window by 2 ms. Haq et al. observed the mean maximum window size of nearly 30 ms, resulting in inevitable distortion of QRS morphology after pacing spike removal [2]. Furthermore, a semi-automated algorithm was time-consuming. Therefore, we conducted this study to develop a novel algorithm to remove pacing artifacts from the initially recorded 12-lead ECG signal, aiming to minimize ECG distortion and increase automation.
Software Description
The algorithm follows a three-step approach. In step 1, it attempts to detect and remove both ventricular and atrial pacing artifacts. However, if any atrial pacing artifacts remain, the algorithm incorporates user feedback to refine the detection in step 2. Finally, the user can manually review and refine the results by addressing residual artifacts or correcting any misdetections in step 3.
Step 1 includes the following procedures:
- Reduce QRS complex amplitude by high-pass filtering. First, all 12-lead ECG signals are passed through a high-pass filter with a cut-off frequency of 120 Hz. This mostly removes the QRS complexes, resulting in signals containing only high-frequency pacing artifacts.
- Enhance pacing artifacts by Shannon energy computation: The algorithm then computes the Shannon energy for each high-pass filtered ECG lead, which further enhances the pacing artifacts. This nonlinear transformation converts the signal amplitude into squared energy values weighted by their logarithm, effectively amplifying pacing artifacts while suppressing low-amplitude noise.
- Principal component analysis (PCA): Principal component analysis is applied to the 12-lead ECGs. The first principal component (PC1) is correlated with the pacing artifacts. The other components are discarded from the analysis as they correspond to high-frequency noises. PC1 retains pacing artifacts as high-frequency spikes.
- PC1 peak detection as potential pacing artifact: The pacing artifact locations are potentially identified as peaks in PC1 using MATLAB's 'findpeaks’ function with a minimum peak height threshold of 4000 and a minimum distance of 10 samples (=20 ms) between consecutive peaks. The height threshold was set to filter out high-frequency signal components unrelated to pacing artifacts. Smaller spikes that appeared around the dominant PC1 spikes were excluded using the distance threshold. These thresholds could be adjusted using a graphical user interface (GUI) application that displayed PC1.
- Artifact width: The width of the pacing artifacts was determined by applying an envelope around the peaks in PC1. In this method, the width is defined by the envelope width, where the amplitude drops by 30% of the peak (default value). There is another option in the GUI application, where a certain number of samples (default 5 samples or 10 ms) before and after the PC1 peaks determine the width of the pacing artifacts.
- Artifact removal: Pacing artifacts do not affect all ECG leads uniformly; some leads exhibited high-amplitude pacing artifacts, while others remained completely unaffected in the same ECG. After identifying potential artifact locations and determining their widths, the maximum absolute slope values were calculated for each location in each lead. A threshold value was established to determine the presence of artifacts.
- Artifacts were removed by linear interpolation between the start and end of the width when the maximum absolute slope within the width exceeded the threshold value. The user could still decide whether to remove the artifact by reviewing the 12-lead in the GUI application, when required.
Step 2
The amplitude threshold cannot distinguish atrial pacing artifacts from QRS complexes. Since QRS complexes are significantly wider than pacing artifacts, a width threshold was introduced in this step to detect atrial artifacts in the presence of QRS complexes. The user will choose to proceed with this step after reviewing the ECG signals in the viewer.
The detection process follows removal of ventricular pacing artifacts as described in Step 1, leaving only atrial pacing artifacts and HF-QRS in PC1. PC1 is smoothed with a 20-sample moving average to attenuate low-amplitude, high-frequency noise. The starts and ends of potential artifacts in PC1 are defined as the points at which PC1 crosses a predefined threshold of 30. The first crossing marks the artifact onset, and the second crossing indicates its offset. A threshold value of 80 ms is chosen to differentiate atrial pacing artifacts from HF-QRS.
Step 3
Undetected artifacts can be manually detected and removed, while incorrectly detected artifacts can be removed in step 3 through the ‘Add/Remove’ option in the GUI.
Technical Implementation
The software code is written in MATLAB. The development process involved creating a user-friendly interface with components such as buttons, labels, switches, and tables. The software follows an object-oriented approach with a class-based structure, leveraging MATLAB's AppBase for GUI components. Various MATLAB functions are implemented for core tasks. The uigetfile function is used to load ECG data files, allowing users to select one or more files for analysis. The butter and filtfilt functions are employed to apply high-pass filtering to the 12-lead ECG signal, removing QRS complex. Once the signal is filtered, the app uses Principal Component Analysis (PCA) via the pca function to reduce the dimensionality of the signal, focusing on the first principal component for further analysis. The findpeaks function is used to detect artifact peaks in PCA data, based on user-defined or default threshold values. The app also incorporates the Hilbert transform (via the envelope function) to compute the envelope of the ECG signal around the pacing artifacts for artifact width determination. Finally, the app uses linear interpolation (linspace) to replace detected spikes with interpolated values, removing artifacts and generating a corrected ECG signal. The app integrates advanced data visualization, including 12-lead ECG, with the ability to display the original and corrected signals for comparison. Users can interactively select leads for artifact removal process as not all leads are affected by pacing. The design emphasizes ease of use, allowing the user to process, analyze, and visualize ECG data with customizable settings for peak detection, thresholding, and artifact removal.
Installation and Requirements
This code has been developed in MATLAB and tested on MATLAB version 2024a. For the latest version of this software, please refer to the associated GitHub repository [3]. The repository includes:
ECGApp_final.m
This file serves as the central component of the entire workflow. This is the main MATLAB application that implements the pacing artifact detection and removal algorithm. It provides a graphical user interface (GUI) that allows users to:
- Load ECG recordings.
- Run automatic detection of pacing artifacts.
- Visualize signals (12-lead ECG, orthogonal leads, and processed signals).
- Adjust detection thresholds.
- Manually refine detected artifact locations.
- Apply artifact removal and review corrected signals.
kors.m
This function performs the Kors transformation, which converts standard 12-lead ECG signals into orthogonal X, Y, and Z leads. This function is automatically called by the main application.
Test_file1.mat, Test_file2.mat
These are example 12-lead ECG recordings provided for testing and demonstration purposes. Each file contains raw digital ECG signals with the following characteristics:
- Sampling rate: 500 Hz
- Amplitude resolution: 1 µV
These files allow users to quickly run the application and understand the workflow without requiring external data.
user_manual.pdf
This document provides a detailed, step-by-step guide for using the software. It includes instructions on running the application, adjusting parameters, interpreting outputs, and manually refining pacing artifact detection results. It serves as a supplementary guide for users.
Usage Notes
This software is designed for research purposes to detect and remove pacing artifacts from 12-lead ECG recordings. It is particularly useful for preprocessing ECG signals prior to downstream analysis, such as waveform delineation, feature extraction, or machine learning applications, where pacing spikes may interfere with accurate interpretation.
The algorithm is intended for ECG signals:
- Recorded at standard clinical sampling rates (500 Hz).
- Containing ventricular and/or atrial pacing artifacts.
Step-by-step procedure to detect and remove pacing artifacts from the ECG signal:
- Download ECGApp_final.m, kors.m, Test_file1.mat, Test_file2.mat.
- Open the file (ECGApp_final.m) in MATLAB.
- Run
- Click on ‘Load ECG’ to load the test file.
- Kors-transformed orthogonal leads X, Y, Z, and 12-lead will be displayed in separate figures.
- Click on ‘Process’.
- PC1 will be displayed with detected peaks (red circled) and locations (in sample) using default thresholds.
- If thresholds need to be adjusted, turn on the Custom Threshold switch.
- Put custom height and distance threshold and click Process to ensure all spikes in PC1 are detected.
- If atrial artifacts are present and cannot be detected (in PC1 figure) using the above method (5 and 6), click on ‘Step 2’.
- Check PC1 plot again.
- If artifacts are still undetected (or in case of misdetection), click on ‘Add’ or ‘Remove’. To remove a mis-detected location, select the location from the ‘Peak Index’ list and click on ‘Remove’. To add an undetected location, click on ‘Add’ and provide the location (in sample) to the pop-up box.
- After all the peaks are selected, click on ‘Plot Results’.
- A new window will pop up with two separate lists of leads. One list belongs to the leads with artifacts, and another without. Users can override the algorithm's decision by checking/unchecking the boxes next to each lead. Click on ‘Apply Correction’.
- Corrected (after removing pacing artifacts), 12-lead and orthogonal X, Y, Z leads will be displayed in the figure on top of the leads with pacing artifacts.
- To change the artifact width, enable the switch under ‘%Envelope/Sample’, to increase the width enter values below 0.3, to decrease the width enter values above 0.3 (default 0.3), alternatively, switch the method to Sample and enter the amount of data to remove, this value will be removed both before and after the artifact peak.
- Click on ‘Reviewed’ to move the processed file to the ‘Reviewed’ folder.
- If an error occurs, click on ‘Error’ to move the file to the ‘Error’ folder and review the file later.
- If the user decides that there are no pacing artifacts in the signal, click on ‘No transformation’ to move the file to the ‘No change’ folder.
Limitations
- Detection of low-amplitude atrial pacing artifacts may be challenging, especially in the presence of high-frequency QRS components.
- Performance may degrade in noisy ECG signals or recordings with significant artifacts unrelated to pacing.
- The algorithm is developed based on ECG signal digitized at 500 Hz. Tuning may be required for signals acquired at different sampling rates.
- The software has been developed and tested on a limited dataset and may not generalize to all ECG formats or acquisition systems.
- This tool is intended for research purposes only and is not validated for clinical decision-making.
Release Notes
Version 1.0.0: Initial release.
Ethics
The study was approved by the Cleveland Clinic Institutional Review Board (IRB ref. 22-803, 22-598, and 23-364). All human participants in the study provided written informed consent before participating.
Acknowledgements
The study was supported through the CRIC Study Opportunity Pool Program (to Tereshchenko) and the Clinical and Translational Science Collaborative of Cleveland, UM1TR004528 from the National Center for Advancing Translational Sciences (NCATS) component of the National Institutes of Health and NIH roadmap for Medical Research (to Tereshchenko).
Conflicts of Interest
The authors declare no conflicts of interest related to the development, implementation, or publication of this software.
References
- Cheng A, Tereshchenko LG. Evolutionary innovations in cardiac pacing. J Electrocardiol. 2011;44(6):611-615.
- Haq KT, Javadekar N, Tereshchenko LG. Detection and removal of pacing artifacts prior to automated analysis of 12-lead ECG. Comput Biol Med. 2021;133:104396.
- Tereshchenko Lab. Pacing spike removal v2 [Internet]. GitHub; [cited 2026 Apr 15]. Available from: https://github.com/Tereshchenkolab/Pacing_spike_removal_v2/tree/main
Access
Access Policy:
Anyone can access the files, as long as they conform to the terms of the specified license.
License (for files):
MIT License
Discovery
DOI (version 1.0.0):
https://doi.org/10.13026/hq2h-8p89
DOI (latest version):
https://doi.org/10.13026/xd1x-zt03
Programming Languages:
Topics:
artifact
electrocardiogram
cardiac pacing
digital signal processing
Project Website:
https://github.com/Tereshchenkolab/Pacing_spike_removal_v2/tree/main
Project Views
6
Current Version6
All VersionsCorresponding Author
Versions
Files
Total uncompressed size: 998.3 KB.
Access the files
- Download the ZIP file (959.7 KB)
-
Download the files using your terminal:
wget -r -N -c -np https://physionet.org/files/ecg-pacing-artifact-removal/1.0.0/
-
Download the files using AWS command line tools:
aws s3 sync --no-sign-request s3://physionet-open/ecg-pacing-artifact-removal/1.0.0/ DESTINATION
| Name | Size | Modified |
|---|---|---|
| ECGApp_final.m (download) | 40.0 KB | 2026-03-25 |
| LICENSE.txt (download) | 1.1 KB | 2026-04-15 |
| README.md (download) | 1.8 KB | 2026-03-25 |
| SHA256SUMS.txt (download) | 545 B | 2026-04-15 |
| Test_file1.mat (download) | 450.5 KB | 2026-03-25 |
| Test_file2.mat (download) | 449.4 KB | 2026-03-25 |
| kors.m (download) | 345 B | 2026-03-25 |
| user_manual.pdf (download) | 54.6 KB | 2026-03-25 |