BSP Lab Report 04
BSP Lab Report 04
Lab Title:
Abstract- This report investigates the implementation and evaluation of the Pan-Tompkins
algorithm for real-time QRS detection in noisy electrocardiogram (ECG) signals. Using
MATLAB, the ECG signal was preprocessed and analyzed through a series of filtering,
transformation, and decision-making steps. The results demonstrate the algorithm’s robustness
in handling noise and its efficiency in identifying QRS complexes even under varying signal-
to-noise ratios (SNRs).
Objectives:
I. INTRODUCTION
Electrocardiography (ECG) is a widely used diagnostic tool for monitoring the electrical
activity of the heart. It is essential for detecting various heart conditions, including arrhythmias,
ischemia, and myocardial infarction. One of the most critical features in an ECG signal is the
QRS complex, which represents the rapid depolarization of the ventricles. Accurate detection
of the QRS complex is vital for determining heart rate, rhythm, and identifying potential
abnormalities.
The QRS complex detection process is a crucial step in automated ECG analysis, particularly
in the development of real-time monitoring systems. A robust and reliable algorithm for QRS
detection can significantly improve the efficiency and accuracy of heart disease diagnostics.
Among the many algorithms proposed for QRS detection, the Pan-Tompkins algorithm has
emerged as one of the most widely used due to its ability to detect QRS complexes accurately
in noisy ECG signals and its computational efficiency
Page | 40
BME 3204 LAB REPORT 04
Page | 41
BME 3204 LAB REPORT 04
factors, such as muscle activity, skin movements, electrical devices, or improper use of the
equipment (Fariha et al., 2020). There are four common types of noise in ECG signals:
Motion Artefact (MA) is typically the most difficult to manage, resulting from subject
movement and being closely related to random limb motion. Baseline Wander (BW) is a
common low-frequency signal, often caused by subject motion or lead displacement. Muscle
Noise (EMG) refers to contamination of the ECG signal by muscular contraction artifacts,
while Power Line Interference occurs at multiples of the mains frequency (50 Hz or 60 Hz)
(Lastre-Dominguez et al., 2019)
1.3 Overview:
The primary software tool used for the implementation and analysis in this study was
MATLAB version R2021a. MATLAB is a high-level programming and numerical computing
environment widely recognized for its capabilities in signal processing, data visualization, and
algorithm development.
Page | 42
BME 3204 LAB REPORT 04
III. METHODOLOGY:
The explanations of each process are given with the output. These show the implementation
of the algorithms using the NST database (Record 118e12) and the MIT database (Record 118).
In Figure 2, the output of each process in the algorithm is presented. Since Record 118e12
(NST) with 12 dB SNR was produced from Record 118 (MIT), a comparison between both
records of noisy and clean data can also be observed.
Derivative Squaring
MWI (dy)2
d(fy) (dy)2
Fiducial R
Detection
Page | 43
BME 3204 LAB REPORT 04
ECG data was obtained from the Ricky AER3-L05 dataset, loaded into MATLAB, and
preprocessed to extract the first channel for analysis. The signal was normalized and
downscaled for further processing. Sampling frequency (fs) was set to 250 Hz.
a) Bandpass Filtering:
ii. Low-Pass Filter (LPF): Mitigated high-frequency noise like power line
interference and EMG noise.
b) Derivative Filtering: Enhanced the slope information of the QRS complex while
suppressing low-frequency components (P and T waves).
d) Moving Window Integration: Integrated the signal over a window width of 150 ms (30
samples at 200 Hz) to capture the waveform’s slope and width.
Dynamic thresholds were applied to distinguish true QRS complexes from noise peaks.
R-peaks were identified based on amplitude and temporal constraints.
Page | 44
BME 3204 LAB REPORT 04
xlabel('Time (s)');
ylabel('Voltage (V)');
title('ECG Signal after High-Pass Filtering');
xlim([0 max(t)]);
hold on;
plot(t(200:600), x1(200:600) / max(x1));
box on;
xlabel('Time (s)');
ylabel('Integrated Signal');
xlim([1 3]);
% Detect Q, R, S, P points
for i = 1:length(left)-1
[R_value(i), R_loc(i)] = max(x1(left(i):right(i)));
R_loc(i) = R_loc(i) - 1 + left(i); % Offset for location
Page | 47
BME 3204 LAB REPORT 04
III. RESULTS
Figure description:
This figure displays the raw ECG signal data before any processing, showing the original
amplitude variations and the inherent noise present in the signal.
Figure description:
This figure demonstrates the ECG signal after the application of a low-pass filter (5-15 Hz),
which removes high-frequency noise such as power line interference and EMG noise.
Page | 48
BME 3204 LAB REPORT 04
Figure description:
This figure shows the ECG signal after applying a high-pass filter (5-15 Hz), effectively
eliminating low-frequency noise like baseline wander.
Figure description:
This figure illustrates the ECG signal after derivative filtering, which enhances the slope of the
QRS complex and reduces low-frequency components.
Page | 49
BME 3204 LAB REPORT 04
Figure description:
This figure depicts the squaring of the ECG signal, which amplifies higher-frequency
components, emphasizing the QRS complexes while suppressing T wave interference.
Figure Description:
This figure illustrates the ECG signal after applying a moving average filter, which smooths
the signal by reducing high-frequency noise. This step enhances the detection of QRS
complexes by improving signal consistency and minimizing false detections.
Page | 50
BME 3204 LAB REPORT 04
Figure Description:
This figure provides a zoomed-in view of the ECG signal, showcasing detected QRS complex
features such as R-peaks, Q-points, and S-points. It highlights the effectiveness of the Pan-
Tompkins algorithm in accurately identifying key fiducial points.
Figure 9: ECG Signal after Moving Window Integration for QRS Detection
Figure Description:
This figure presents the result of moving window integration (MWI), which smooths the
squared signal, capturing the QRS complex's amplitude and width for peak detection.
Page | 51
BME 3204 LAB REPORT 04
IV. DISCUSSION
The Pan-Tompkins algorithm demonstrated effective real-time QRS detection in noisy ECG
signals, showing robustness across various signal-to-noise ratios (SNRs). The preprocessing
steps, including bandpass filtering, derivative filtering, squaring, and moving window
integration (WMI), were pivotal in enhancing the QRS complex and reducing interference from
noise, allowing the algorithm to consistently identify R-peaks in both clean and noisy ECG
data. Key findings include the following:
1. The bandpass filters (low-pass and high-pass) played a significant role in removing
unwanted noise and baseline wander from the signal. The high-pass filter successfully
eliminated low-frequency interference such as baseline drift, while the low-pass filter
mitigated high-frequency noise, including power line interference and
electromyographic (EMG) noise. These filters effectively enhanced the quality of the
ECG signal, facilitating more accurate QRS detection.
2. Derivative filtering further improved the QRS complex's slope, making it more distinct
from other features like the P and T waves. This step was essential for enhancing the
sharpness of the R-peak, which is central to the QRS detection process. By focusing on
the slopes, the algorithm suppressed unwanted low-frequency components, such as the
T and P waves, which could have been mistaken for QRS complexes.
3. The squaring function further emphasized the QRS complex, amplifying high-
frequency components to reduce the impact of low-frequency components and noise.
The squaring operation helped in minimizing false positives caused by the T-wave
interference, which is often problematic in noisy ECG signals. This was particularly
important when the ECG signal contained noise or artefacts that could have led to
inaccurate peak detection.
4. Moving window integration (MWI) was another essential step that contributed to the
algorithm's ability to identify the QRS complex. By integrating the squared signal over
a specified window width, the algorithm smoothed the signal and highlighted the QRS
complex's amplitude and width. This step provided a more consistent and reliable
representation of the QRS complex, enabling accurate peak detection.
5. The thresholding and decision rules in the Pan-Tompkins algorithm played a crucial
role in distinguishing true QRS complexes from noise peaks. Dynamic thresholds were
applied to adapt to varying signal conditions, ensuring that only valid R-peaks were
detected.
Page | 52
BME 3204 LAB REPORT 04
V. CONCLUSION
The results obtained from this experiment demonstrate that the Pan-Tompkins algorithm can
be effectively applied in clinical settings for real-time QRS detection, even in the presence of
noise and other signal distortions. This study provides a solid foundation for the application of
the algorithm in automated ECG analysis systems, with potential implications for improving
diagnostic capabilities in clinical environments.
Future work may explore the integration of machine learning techniques to further enhance the
algorithm's adaptability to diverse ECG signal conditions and improve the accuracy of
detection in more complex scenarios. Additionally, the use of other datasets with varying
characteristics could be investigated to test the algorithm's generalizability across different
populations and signal types.
REFERENCES
Fariha, M. A. Z., Ikeura, R., Hayakawa, S., & Tsutsumi, S. (2020). Analysis of Pan-Tompkins
Algorithm Performance with Noisy ECG Signals. Journal of Physics: Conference Series,
1532(1), 012022. https://doi.org/10.1088/1742-6596/1532/1/012022
Pan, J., & Tompkins, W. J. (1985). A Real-Time QRS Detection Algorithm. IEEE Transactions on
Biomedical Engineering, BME-32(3), 230–236.
https://doi.org/10.1109/TBME.1985.325532
Page | 53