Highlights
1 The aim of the lab
Implement and investigate real-time algorithm for detection of QRS complexes in electrocardiogram signals.
2 Lab scenario
2.1 Practical problem
Emerging technologies provide many ways to monitor heart rhythm and detect cardiac arrhythmias. However, in order to obtain heart rate (HR) or analyze the signal for arrhythmias, QRS complexes have to detected, and the peaks of R waves have to be accurately located (see Fig. 1). Then, the RR interval, the time between consecutive contractions of the ventricles, is estimated, which is inversely related to the HR (HR = 60/RR). Note that RR interval is expressed in seconds, while HR is in beats per minute.
Fig. 1. R wave detection in electrocardiogram (ECG). Here VPB stands for ventricular premature contraction, which usually has different morphology compared to normal QRS complexes
It is well known that heart rate is not constant but varies over time. This variation, known as heart rate variability (HRV), is as result of balancing between the sympathetic (increases heart rate) and the parasympathetic (decreases heart rate) nervous systems and cardiovascular system response to that activity. Low HRV may indicate that cardiovascular system does not respond well to the activity of the sympathetic and parasympathetic nervous systems. Therefore, many serious conditions are associated with reduced HRV, namely, myocardial infarction, congestive heart failure, depression, etc. To ensure reliable HRV analyses, R waves in ECG must be accurately detected. Although many QRS detector have been developed [1], QRS detector proposed by Pan and Tompkins in 1985 is the most widely used [2].
2.2 QRS detector
In this lab work, you will implement and investigate the simplified version of Pan and Tompkins QRS detector. Block diagram of this QRS detector is shown in Fig.2.
Bandpass filter. Firstly, ECG signal is filtered with the bandpass filter, which is needed to reduce the influence of T wave interference, electromyographic noise, powerline interference and baseline wander. This filter removes ECG component below 5 Hz and above 15 Hz, thus mostly energy contained in the QRS complexes is retained. The bandpass filter is composed of serially connected low-pass and high-pass filters. The transfer function of the low-pass filter is
Differentiator. Next, the bandpass filtered ECG signal is differentiated to further reduce the amplitude of slowly changing ECG components. The derivative can be approximated by the digital filter
Nonlinear operator. Nonlinear operator is also used to emphasize large amplitude ECG components (QRS) and reduce the low amplitude components (T wave). The simplest nonlinear operator – point by point signal squaring. The difference equation of this filter is
It should be noted that the signal squaring transforms the signal to positive, thus makes QRS detector independent of ECG lead used for R wave detection (e.g., negative QRS components dominate in precordial lead V1).
Impulse formation (integrator). Finally, signal integration is used to form smooth impulses and is implemented as a moving averager
where N is the number of samples in the integration window. This number is determined empirically depending on the desired smoothing level. It is recommended to choose N from the interval of [20-80]. Note that if N is chosen too large, the top of the integrated signal will be flat. On the other hand, if N is selected too small, several peaks will be produced. Both situations will lead to inaccurate QRS detection, thus a reasonable compromise must be found to ensure that the number of inaccurately detected QRS complexes is low.
Adaptive threshold detection. Peak detection is based on a search for a local maxima, however to make a detector resistant to non QRS related maxima, the threshold has to be applied, above which the peak search is only activated. Threshold detector can be realized in various ways. In this lab, you will implement adaptive threshold, which is needed since QRS amplitude usually varies over time. Adaptive threshold is determined according the maximal amplitude of current QRS complex and is updated each time a new QRS complex is detected. In such a way, the search of the impulse peak is started only when the impulse exceeds the threshold. Besides the possibility to adapt to rapidly changing QRS amplitude, the other advantage of the adaptive threshold is the ability to be realized in real-time systems. It should be noted that when the goal is to reduce the number of false positives (incorrectly detected R peaks), the threshold level has to be increased, and vice versa, when the goal is to reduce the number of undetected R peaks, the threshold level has to be reduced. Usually, it is desirable to reduce the number of undetected peaks, thus the threshold is set at the lower level, at 30-40% of the maximal amplitude of detected QRS complex. It is obvious that this approach will increase the number of incorrectly detected QRS complexes. This often happens when QRS complex is followed by the larger T wave. The problem of T wave detection can be mitigated by also implementing the time-dependent threshold. That is, peak search is stopped for 200-300 ms after each R wave is detected. This duration is motivated by the heart recovery time during which the heart is unable to respond to an electrical stimulus and normally no QRS complex can appear within this range.
2.3 Implementation of QRS detector
Thirty ECG signals, sampled at 360 Hz, will be provided (download file ecg_signals.rar). Each ECG has a duration of 1 minute. Ten ECGs are with normal sinus rhythm (ECG_SR), 10 with ventricualr premature beats (ECG_VPB), and the remaining 10 with atrial fibrillation arrhythmia (ECG_AF).
1. Display each type of ECG signals (SR, VPB, AF) in a single plot (use subplot function). Consider what are the differences between these signals? How could different ECG morphology affect QRS detection? Pay attention to the quality of the signals: baseline wander, electromyographic activity, etc. Note that low amplitude waves in signals with atrial fibrillation are fibrillatory f-waves.
2. Find filter coefficients, impulse response, and frequency response for each digital filter given above.
3. Select the ECG signal you want to use to illustrate the steps of QRS detection. It is recommended to start with the sinus rhythm signal, which is without abnormal and difficult to detect QRS complexes. Remember that you must implement all the operations described in subsection 2.2. Use the subplot function to show ECG after each signal processing step.
4. Implement adaptive threshold and find R wave time moments (indexes) in the ECG. Adaptive threshold based detector should be implemented using this logic:
a) Set the initial threshold level. Only the samples that are above the threshold will be used for peak detection. The initial threshold can be determined according to the maximal value within the first 1.5 seconds. The initial threshold level has to be
b) Peak detector should find the maximal value of the impulse, update the threshold value and remember the index of maximal value (sample number). It is likely that this maximal value corresponds to R wave. After R wave is detected, the algorithm should not search for a new maximal value for 200-300 ms to avoid false QRS detection due to T wave. The same steps have to be repeated until all peaks are detected and all R wave indexes are stored in the index array.
5. Show raw ECG signal, and detected R waves (use Matlab function stem) in a single illustration. Pay attention whether the detected peaks are not shifted with respect to R waves. What is the reason of this shift? Compensate this shift manually by subtracting the constant from the R wave index array.
6. Investigate the algorithm using different types of ECG signals (SR, VPB, AF). Which type of signals is the most challenging for QRS detector? Consider what should be done to improve QRS detection.
7. Optimize the QRS detector by changing the parameters (e.g., the length of the integrator filter, the threshold). Describe optimization process and provide the selected parameter values.
8. Show heart rate sequences (in beats per minute) for each ECG signal type.
3 Deliverable
Deliverable has to be prepared according to the given template (two column format). The deliverable cannot exceed 4 pages (without supplement). All illustrations must have self-explaing captions. All the results have to be discussed. Illustrations without discussion are meaningless. Matlab code has to be provided as a supplement.
4 Literature
[1] Köhler B. U., Hennig C., Orglmeister R. The principles of software QRS detection. IEEE Engineering in Medicine and Biology Magazine, vol. 21, no. 1, 2002. P.42 – 57.
[2] Pan J., Tompkins W.J. A Real-Time QRS Detection Algorithm. IEEE Transactions on Biomedical Engineering, vol. 32, iss. 3, 1985. P. 230 – 236.
This Nursing Assignment has been solved by our Nursig Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.
Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.
© Copyright 2026 My Uni Papers – Student Hustle Made Hassle Free. All rights reserved.