Biomedical Engineering - ECG Assignment
The deadline for this assignment is 5pm on Tuesday 13th February 2007


This page contains information on the ECG assignment from semester 1 of the Biomedical Engineering course (for students of programs DT084 and DT092). We have received feedback from some students that they are having problems with the assignment, so I will try to clarify here what is expected of you and give some useful tips on how to go about analysing the signal.

Heart Rate and Heart Rate Variability

A stylised representation of a typical Lead II ECG signal is shown in the following figure.

ECG graph

The heart rate (HR) can be estimated by measuring the R-R intervals of the signal. While the subject remains at rest, these R-R intervals should not change a huge amount. However, some variability in these intervals is normal, as described in the following quote (from p.555 of "Introduction to Biomedical Engineering" by John Enderle, Susan Blanchard, Joseph Bronzino, 2nd edition).

"Real biological signals almost always have some unpredictable noise or change in parameters and, therefore, are not entirely deterministic. The ECG of a normal beating heart at rest is an example of a signal that appears to be almost periodic but has a subtle unpredictable component. The basic waveform shape consists of the P wave, QRS complex, and T wave and repeats. However, the precise shapes of the P waves, QRS complexes, and T wave are somewhat irregular from one heartbeat to the other. The length of time between QRS complexes, which is known as the R-R interval, also changes over time as a result of heart rate variability (HRV). HRV is used as a diagnostic tool to predict the health of a heart that has experienced a heart attack. The extended outlook for patients with low HRV is generally worse than it is for patients with high HRV."

There are several definitions for heart rate variability (HRV), but perhaps the most intuitive is simply to variance of a series of consecutive R-R intervals. For the purpose of this assignment, you may use this definition. A definition for the variance of a set of values can be found in many general maths textbooks. If you use another definition of HRV, please give a full explanation of why you chose it, ideally with one or more references to reputable sources.

MATLAB Program, Written Report and Submission

The deadline for this assignment is 5pm on Tuesday 13th February 2007

Written Report

You will need to submit a working program and a written report. I'd rather not specify a minimum or maximum length for the report, since quality is definitely more important than quantity. However, as a rule of thumb, 4 or 5 pages is probably about right. This should includes diagrams. Yes, there should be diagrams in your report. As with everything you submit, effective communication and standard of presentation is very important, so please make it neat and proof read it. Needless to say, plagiarism of any kind is totally unacceptable, so the report (and program) should be entirely your own work. Where you quote or make reference to other sources (books, journal articles, etc) a complete reference should be provided. Incidentally, since you didn't invent the concept of HRV yourself, it is a very good idea to make appropriate references to other materials. I'm not sure exactly what James covered in class with you, but your discussion of the ECG, HR and HRV, should ideally make reference to some of the concepts that he covered. One thing that would be of particular importance in your report would be a description of some potential applications (clinical or otherwise) or HR and HRV. This will probably require some independent research on your part. See if what you find can be used to draw any inferences from the data you analysed. Of course, this may not be possible but if not try to explain why. A little hint to get you started: One application of HRV that you could research is mentioned in the quote above from Enderle et al.

MATLAB Program

Regarding the program itself, I'm reluctant to impose any strict criteria since many of you will already have approached the problem in your own way. However, for those of you that are at a complete loss as to where to begin, you can use the following as a guideline. Your program should be a MATLAB script or function (in either case, it should be stored in an m-file). The user of the program should be able to specify the name of a file containing an ECG recording, from which your program will calculate two numerical values - heart rate (in beats per minute) and heart rate variability (the variance of the set of R-R intervals in the recording). You may also choose to incorporate into your program the generation of appropriate graphs for use in your written report. In the interest of readability, please include plenty of clear comments in your MATLAB code. In MATLAB, any line of code starting with a "%" is a comment. A printed copy of your MATLAB code should be appended to your report (see below).

Assignment Submission

The deadline for submitting this assignment is 5pm on Tuesday 13th February. At that time, you will submit your written report, printed on paper. A printed copy of your MATLAB code should be appended to your written report. This deadline coincides with one of my lectures in 4-005, so you can just bring your report to class and hand it in then. Assignments that are submitted late are likely to be penalised, so please submit on time. We will probably also request a copy of the MATLAB m-file containing your program, so please bring it along on a USB key or have it available to email to us at the same time that you submit the written report.

Alternative ECG Data

Since some of the data files recorded during the ECG lab seem to be corrupted, we are providing the following alternative data set for people who cannot use their own ECG data. If your own data seem ok, you can completely ignore this. If however, you are sure that your data are seriously corrupted, you can use this until you get to check with either myself (Ted Burke) or James Condron. This is a link to the alternative data (you may need to right click and "Save link as..." or something like that):


Unfortunately, some people have encountered problems opening the above data file in older versions of MATLAB. The following link is to a file for MATLAB version 6 containing the same data. If you received an error message when trying to open the file above (possibly referring to a "corrupted" file), try the file below instead. The data in both files is exactly the same, only the MATLAB file version is different.


The file "signals.mat" (or "signals6.mat") is a MATLAB workspace file. You can load it in MATLAB using the command "load signals" (or "load signals6"), provided that you are currently in the directory where you have saved the file. The workspace contains 6 variables in total:

The data record five leads over about 38.4 seconds. For the purpose of measuring heart HR and HRV, it shouldn't really matter which one of the five signals you use. The sampling frequency of all signals is 1kHz. Best of luck!

Useful MATLAB Information

Dave has provided the following introductory MATLAB worksheet which you used at the beginning of the previous semester. It may be of use to you in writing your program. Here's the link:

Lab 1.doc