A detailed description of the apdet algorithm and its application can be found in: Detection of Obstructive Sleep Apnea from Cardiac Interbeat Interval Time Series. This article originally appeared in Computers in Cardiology 2000, vol. 27, pp. 753-756 (Piscataway, NJ: The Institute of Electrical and Electronics Engineers, Inc.). Please cite this publication when referencing this material.
The software described here was developed for the Computers in Cardiology Challenge 2000. Additional information regarding apnea detection from the ECG, as well as data to test the software, can be found at the challenge page.
Hilbert Transform based Sleep Apnea Detection using a Single Lead Electrocardiogram (apdet)
JE Mietus, C-K Peng, PCh Ivanov, AL Goldberger.
Beth Israel Deaconess Medical Center and Harvard Medical School, Boston, USA
The apdet software package uses a new automated method to diagnose and quantify obstructive sleep apnea from single-lead electrocardiograms based on detection of the periodic oscillations in cardiac interbeat intervals that are often associated with prolonged cycles of sleep apnea. This technique employs the Hilbert transformation of the sinus interbeat (NN) interval time series to derive the instantaneous amplitudes and frequencies of the series, and calculates their averages and standard deviations over a moving 5-minute window. We then apply a thresholding technique and detect continuous sequences of those windows that lie within threshold limits.
When applied to the training set of the Apnea-ECG Database created for the CinC Challenge 2000, this algorithm correctly classified 26 of 30 subjects (86.6%), and correctly identified the presence or absence of sleep apnea in 13895 of 17045 minutes (82.1%). When applied to the test set of the Apnea-ECG Database, this algorithm performed even better, correctly classifying 28 out of 30 cases (93.3%) of subjects, and 14591 of 17268 minutes (84.5%).
Obtaining the apdet package
The apdet software package is available in source form and as prebuilt binaries for Linux and MS-Windows.
Before building or using the apdet software, you must install the free WFDB software package. Under MS-Windows, you will also need to install the free Cygwin environment before building or using the apdet software.
Unpacking the apdet package requires tar and gzip, and running the software requires sh (or a compatible shell such as bash), and awk, all of which can be found on all Unix, Linux, and Mac OS/X systems, and in the Cygwin environment for MS-Windows. Cygwin also includes the gcc C compiler and all other utilities needed to compile the apdet package from sources if desired.
Downloading and installing the apdet package
Once you have installed the WFDB software package (and, under MS-Windows, the Cygwin environment), download and install the apdet package of your choice:
- Download apdet.src.tar.gz. (You may also view or download the sources as individual files.)
- Unpack it:
tar xfvz apdet.src.tar.gz
tar is included in all versions of Unix, Linux, and MacOSX, and in Cygwin for MS-Windows. If your version of tar doesn't support the z option, unpack the package in two steps:
gzip -d apdet.src.tar.gz
tar xfv apdet.src.tar
- Enter the source directory (apdet-1.0) and compile the
(under MS-Windows, make -f Makefile.w32 all).
- Install the software:
(under MS-Windows, make -f Makefile.w32 install). You will probably need root (administrator) permissions to install in the default location; change the value of BINDIR in Makefile (Makefile.w32) if you need to use a different location.
- Linux (x86) binaries:
- Download apdet.i386-linux.tar.gz.
- As root, unpack it:
tar xCfvz / apdet.i386-linux.tar.gz
- MS-Windows binaries:
- Download apdet.cygwin.tar.gz.
- In a Cygwin/bash window, unpack it:
tar xCfvz / apdet.cygwin.tar.gz
Using the apdet package
Open a terminal window (under MS-Windows, a Cygwin/bash window) and type a command such as
get_apdet apnea-ecg/a03 qrsThe first argument is the record name, and the second is the annotator name for a beat annotation file. In the example above, get_apdet will analyze record a03, annotator qrs from the Apnea-ECG Database. (If you have not previously downloaded the input data into a local apnea-ecg directory, get_apdet obtains the data directly from PhysioNet.)
The get_apdet command prints the times of detection of sleep apnea
heart rate oscillations and the total fraction of time with such detections.
For the example above, the output is:
00:05:59 - 00:59:59 01:39:59 - 02:28:59 03:04:59 - 03:52:59 03:57:59 - 04:22:59 04:38:59 - 05:03:59 05:56:59 - 06:48:59 06:58:59 - 07:24:59 07:45:59 - 08:39:59 tot = 05:33:00 / 08:42:25 = 0.637
See an illustration of these detections.
get_apdet relies entirely on normal-to-normal beat interval data, which it normally derives from a beat annotation file. Beat annotation files are available for most of the PhysioBank records that include ECGs. If you wish to study a recording for which no beat annotation file is available, you may be able to create one using sqrs. If you have interbeat interval data but not a beat annotation file, you can modify get_apdet as needed, or you can use rr2ann to put your data into the standard format before processing them.
For information about record and annotation conventions see the PhysioNet FAQ.
How does get_apdet work?The sequence of steps involved in the detection of the RR interval oscillations, as implemented by get_apdet, is as follows:
- The normal-to-normal (NN) intervals are derived:
rrlist $ANN $REC -a N
If the input files ($REC.$ANN and $REC.hea) are not in the current directory, rrlist looks for them in the PhysioBank archives on PhysioNet.
- The NN interval series is then filtered to remove outliers:
filt 0.2 20 -x 0.4 2.0
- The series is then linearly resampled at 1 Hz ...
- ... then locally detrended using a moving 40 second window ...
- ... and smoothed using a moving 5 second window: smooth 5
- Next, the Hilbert transform is applied to derive instantaneous
amplitudes and frequencies:
- The Hilbert amplitudes and frequencies are then median filtered
using a 60 second window:
- The amplitudes are normalized such that the average amplitude equals 1.0 (using awk).
- The midpoint of the Hilbert amplitudes is found (using awk and
mm), and the minimum Hilbert amplitude threshold is set to
THRES = a + b*(mid+1)/2
where a = -0.555 and b = 1.3 (note: the values of a and b were given incorrectly in the original publication; please refer to the posted version instead.)
- The mean Hilbert amplitudes and frequencies, their standard deviations
and fraction of time within their specified threshold limits are
calculated over 5-minute windows incremented each minute:
htavsd 1:00 5:00 THRES
- Those windows where the means, standard deviations and threshold times of the Hilbert amplitudes and frequencies are all within their specified limits are selected (using awk).
- Apnea is detected whenever at least 15 consecutive windows are selected
in the previous step, and the times of the detected apneic periods are
detruns 1:00 5:00 15:00
This program correctly identifies the presence or absence of apnea in in 82.1% of the data in the CinC test set and 84.5% of the data in the CinC training set.
It is recommended that the accuracy of the oscillation detections be verified by visual inspection of the original RR interval series.
If you would like help understanding, using, or downloading content, please see our Frequently Asked Questions.
If you have any comments, feedback, or particular questions regarding this page, please send them to the webmaster.
Comments and issues can also be raised on PhysioNet's GitHub page.
Updated Thursday, 09-Jul-2015 17:08:18 CEST
PhysioNet is supported by the National Institute of General Medical Sciences (NIGMS) and the National Institute of Biomedical Imaging and Bioengineering (NIBIB) under NIH grant number 2R01GM104987-09.