RR Intervals, Heart Rate, and HRV Howto (2024)

The new PhysioNet website is available at: https://physionet.org. We welcome your feedback.

George B. MoodyHarvard-MIT Division of Health Sciences and Technology

This mini-tutorial offers a brief overview of how to obtain inter-beat (RR)interval and heart rate time series, and of some basic methods forcharacterizing heart rate variability (HRV), using freely availablePhysioToolkit software. If you have not already done so, install theWFDB Software Package, which includesmost of the software mentioned below. A few other components ofPhysioToolkit are optional, and can be installed later if desired.

The starting point for any study of RR intervals, heart rate, or HRV is usuallyan electrocardiogram (ECG). PhysioBank contains many digitized ECGs that are already annotated beat-by-beat, by which we mean thateach QRS complex (the ECG waveform corresponding to the contraction of theventricles) has been identified and its exact time of occurrence within the ECGhas been recorded (in a beat annotation file). If you already havea beat annotation file, skip ahead to the section titledInter-beat (RR) Intervals.

PhysioToolkit software can read a wide variety of digital formats, collectivelyknown as PhysioBank-compatible formats. If you already have a binary signal(.dat) file and a text header (.hea) file, your data mayalready be in PhysioBank-compatible format. To test it, you will need to knowthe record name, which is the first part of the file name of theheader file. For example, if your header file is named ecg01.hea, the record name is ecg01. To check if your record is already inPhysioBank-compatible format, try this command:

wfdbdesc ecg01
(substituting your record name for ecg01).If the output is similar to
init: record name in record ecg01 header is incorrect
then you will need to reformat your data.

If you need to study an ECG that is not already in a PhysioBank-compatibleformat, the first step is to convert it. Otherwise, you can skip ahead to thesection titled Creating a beat annotation file.

Creating a PhysioBank-Compatible Record

There are many ways to create a PhysioBank-compatible record. Here is an easyway to do so:

  1. If the ECG is still in analog format, digitize it. We recommend using a sampling frequency of at least 120 Hz, with at least 8 bit resolution over a ±5 mV range (ideally, 250 Hz to 1 KHz, with 12 to 16 bit resolution over a ±10 mV range). As is necessary whenever digitizing any signal, use an appropriate antialiasing filter (a low-pass filter with a cutoff no higher than about 40% of the sampling frequency).
  2. Write the samples into a file in text form, as a column of decimal numbers. If you have digitized more than one signal, use a separate column for each signal. (The software that was used to digitize the ECG may include a means for doing this.)
  3. Read about wrsamp to see how to prepare a binary signal file and a header file from the text file. Typically, you will need to use a command such as
    wrsamp -F 128 -G 102.4 -i ecg01.txt -o ecg01 0
    This example reads a text file named ecg01.txt, and creates the files needed for a record named ecg01, namely, a signal file named ecg01.dat and a header file named ecg01.hea. (Download these files by clicking on their links above if you would like to work through the examples below.) The arguments of -F and -G specify that the signal was sampled at 128 Hz and that the signal was amplified in such a way that a step of 1 millivolt would appear as sample values that differ by 102.4 units. The final argument (0) indicates that the leftmost column in the input (column 0) contains the data.

Other methods for creating a PhysioBank-compatible record are discussed inthe FAQ.

Creating a Beat Annotation File

At this point you should have a PhysioBank-compatible record, including.dat and .hea files. Before you can begin studying RRintervals, however, you will need to know the exact locations (times ofoccurrence) of the QRS complexes in the ECG. In PhysioBank, this informationis encoded in beat annotation files. Annotation files have names that beginwith the record name and end with an annotator name (such asqrs, ecg, ann, or atr; other names arepossible, though less commonly used). For example, a beat annotation file forrecord ecg01 might have a name suchas ecg01.ann. If your record comes from aPhysioBank data collection, look for a (plain text) filenamed ANNOTATORS in the directory thatcontains your record; if the file exists, it contains a list of annotator namesthat may be associated with your record.

If you don't have a beat annotation file for your record, there are severalways to create one using PhysioToolkit software:

  • Use sqrs, a good, fast and simple QRS detector.
  • Use wqrs, a reasonably fast QRS detector that generally works better than sqrs.
  • Use gqrs, a very good and fast QRS detector that generally performs better than the others listed here. Like the others, gqrs is optimized for use with adult human ECGs; unlike the others, gqrs can be configured easily for analysis of infant, pediatric, and non-human ECGs.
  • Use ecgpuwave, a very good QRS detector that also locates the P- and T-waves and their boundaries. Follow the link above to obtain ecgpuwave.

You should always review the beat annotation file generated by any of thesedetectors; although all of them work well in most cases, there is widevariability among ECG recordings, and any QRS detector will make errorsif the data quality is insufficient. There are, once again, several waysto do this:

  • Use WAVE. Using WAVE, you can view the signals and annotations interactively, and you can correct QRS detection errors (missed beats, false detections, and misplaced annotations) manually if you wish to do so.
  • Use pschart or psfd. Both produce PostScript output. If you don't have a PostScript printer, you can view or print the output using GhostScript (a free PostScript-compatible rasterizer; follow the link to obtain GhostScript from its developers).

All four of the detectors above mark all detected beats as normal (N). If yourrecord includes abnormal beats, change the N annotations for these beats to thecorrect annotations (a complete list of annotation types can be found here). This can be done manuallyusing WAVE.

Another possibility is to use OSAS, free software for QRS detection and beatclassification available from its author (follow the link for details). Thismay be particularly helpful if your records contain more than a handful ofabnormal beats, since OSAS can find most abnormal beats and annotate themappropriately, but it is still necessary to review the automatically-generatedannotation file and correct any errors.

Even a small number of uncorrected QRS detection or classification errors canlead to grossly erroneous HRV analysis results. Careful use of the outlierrejection features of the software described below can reduce this risk.

(Download ecg01.qrs, a corrected annotation filefor the simplified example above, if you want to work through the examplesbelow.)

Inter-beat (RR) Intervals

The time intervals between consecutive heart beats are customarily measured inthe electrocardiogram from the beginning of a QRS complex to the beginning ofthe next QRS complex, so these intervals might be called QQ intervals, but theyare conventionally named RR intervals. Although custom dictates using thebeginning of the QRS complex as the reference (fiducial) point, it should benoted that this point can be difficult to locate in noisy or low amplitudeECGs, leading to measurement error. Many investigators prefer to measureinter-beat intervals using the R-wave peak as the reference point, reasoningthat this measurement can be made with smaller errors. If the measurementsare being made for the purpose of studying RR or heart rate variability, itis appropriate to make such a choice in order to obtain more accuratemeasurements of intrinsic variability.

As a practical matter, the choice of reference point is made by the QRSdetector. Each of the three QRS detectors available from PhysioToolkituses a slightly different method, but all have the advantage of using robustintegrative methods that are relatively insensitive to noise spikes.

Often, you may be interested only in intervals between normal (sinus) beats;these are usually called NN intervals.

Extracting RR Intervals from an Annotation File

Stop! Before you extract RR intervals, is this really what you want to do? Ifyour ultimate goal is to study heart rate variability using methods other thanthe classical scalar HRV parameters (SDNN, pNN50, RMSSD), you can skip thisstep and go directly to the next one, extractinginstantaneous heart rate from an annotation file.

If you are still reading, you must be interested in RR intervals per se. Inthis case, use ann2rr to read anannotation file and produce a list of the RR intervals. Typically, if you wishto obtain intervals from an annotation file named ecg01.qrs, this canbe done using a command such as

ann2rr -r ecg01 -a qrs
This command writes the intervals to the standard output in text form.To save the output in a file, redirect it:
ann2rr -r ecg01 -a qrs >ecg01.rr1.txt
This saves the output in the (text) fileecg01.rr1.txt.

If you wish to see the beat types that end each interval, use the -woption, as in:

ann2rr -r ecg01 -a qrs -w >ecg01.rr2.txt
This command prints the mnemonics for the beat types (N for normal, etc.)in the second column, following the intervals inecg01.rr2.txt.

By default, the units used to express the RR intervals are the samplingintervals (e.g., if the original recording was sampled at 128 samples persecond, then an interval of 1 second appears in the output as "128"). Sincethe reference points used to determine the RR intervals have a resolution of1 sampling interval, this representation is as precise as possible. It isusually desirable to keep the RR intervals in this representation since itavoids introducing roundoff error in subsequent computations, but if you preferto see RR intervals in seconds and milliseconds, use the -i s option:

ann2rr -r ecg01 -a qrs -i s >ecg01.rr3.txt

If you wish to study only NN intervals, use a command such as:

ann2rr -r ecg01 -a qrs -p N >ecg01.rr4.txt

Notice that the first interval in these files is very short compared with theothers. By default, ann2rr calculates the first interval as if therewere a beat at the beginning of the record; this allows interval series to beconverted back into properly-aligned annotation files, since the timestamp forany annotation is simply the sum of all of the preceding intervals. Use the-c option to exclude intervals (such as the first one in the previousexamples) that are not boundedat both ends by valid annotations:

ann2rr -r ecg01 -a qrs -p N -c >ecg01.rr5.txt

See the manual page for ann2rr foradditional options and details.

Visualizing RR intervals

RR Intervals, Heart Rate, and HRV Howto (1)

If you have installed plt, you can usethe rrplot shell script to view an RR intervaltime series (obtained using ann2rr). The figure at left wasmade using the command:

rrplot -r mitdb/100 -a atr
RR Intervals, Heart Rate, and HRV Howto (2)

It is often useful to create a histogram of RR intervals, as shown atleft. Look in the script rrhist to see howthis can be done, using ann2rr together with sort anduniq (both of these utilities are standard components of Unix,GNU/Linux, Mac OS/X, and MS-Windows/Cygwin).The figure at left was made using the command:

rrhist -r mitdb/100 -a atr

Discontinuities in an NN interval sequence

There are many reasons why an NN interval sequence may be discontinuous,including poor signal quality, loss of signal, or interruption by ectopic(abnormal) beats. In some cases, careful selection of continuous sequences issufficient, but even non-cardiogenic interruptions, such as noise, may becorrelated with physical activity or symptoms that are in turn correlated withheart rate. For this reason, it is necessary to take care that selection biasis not introduced when discarding noisy data.

RR Intervals, Heart Rate, and HRV Howto (3)

To avoid having to discard noisy data, some investigators prefer to reconstructthe missing sinus beat intervals. You can use nguess to do this; as its nameimplies, nguess makes (reasonable) guesses about the locations ofmissing beats. At left is an NN time series based on nguess's guessesfor the same data shown in the previous plots.

Not all methods for time series analysis require continuous series; someinvestigators avoid those methods that have such a requirement because theyforce a choice among poor alternatives. We will return to this subjectin the next section.

Extracting Instantaneous Heart Rate from an Annotation File

In clinical practice, heart rate is measured in beats per minute (bpm) and isalmost always computed by extrapolation (for example, by counting the beats ina six-second interval and multiplying by ten).

In studies of heart rate variability (HRV), however, heart rate is modelled asas a quasi-continuous signal, and the RR interval series is used to obtainsamples of that signal at more frequent intervals.

The simplest and in many ways the best way to do this is to calculate thereciprocal of each interval in minutes; to do so, useihr. For example, use a commandsuch as

ihr -r ecg01 -a qrs
This command writes the reciprocals of the intervals (i.e., the time seriesof instantaneous heart rates) to the standard output in text form.To save the output in a file, redirect it:
ihr -r ecg01 -a qrs >ecg01.ihr.txt
This saves the output in the (text) fileecg01.ihr.txt. The first column in theoutput is the elapsed time in seconds, and the second column is theinstantaneous heart rate in beats per minute.
RR Intervals, Heart Rate, and HRV Howto (4)

If you have installed plt, you can usehrplot to view a heart ratetime series (generated on-the-fly by ihr). The figure at left wasmade using the command:

hrplot -r mitdb/100 -a atr
See the manual page for hrplotfor further details and options.

Most (but not all) methods for frequency-domain analysis of time series requirethat the series be sampled at uniform intervals. The heart rate time seriesobtained by ihr is sampled at non-uniform intervals in general (in fact,it is precisely the non-uniformity that one wishes to study). If you plan tostudy heart rate in the frequency domain, you might want to resample the heartrate signal at uniform intervals. The standard algorithm for doing so, IPFM,is implemented by tach. Usetach to obtain a uniformly sampled heart rate time series with a commandsuch as

tach -r ecg01 -a qrs -F 4
The argument of the -F option indicates the desired sampling frequencyfor the heart rate signal, in this case 4 samples per second.This command writes the resampled heart rate time series to the standardoutput in text form. As for ihr, the outputcan be saved in a file by redirecting it. Unlike ihr, the output fromtach contains only one column by default (the instantaneous heart rates)since the time intervals between samples of the heart rate signal are uniform.

Both ihr and tach offer powerful techniques for outlierrejection, which is almost always needed when studying long heart rate timeseries. Read their manual pages for details (follow the links above). Aproblem unique to tach, however, is that once outliers have beenrejected, the heart rate samples calculated for those intervals are incorrectand may unduly influence subsequent analysis. For this reason, you may preferto reconstruct the NN interval time series using nguess (see theprevious section) before using tach, or to postprocess tach'soutput to remove impulse noise, if it is necessary to use tach on noisydata or on data that include ectopic beats.

It should be understood that reconstruction and resampling is a controversialoperation for many reasons, and that it is not necessary unless you wish to usecertain specific frequency-domain techniques. For example, power spectraldensity estimation using FFT or maximum entropy (autoregressive)methods requires resampling, but the Lomb-Scargle algorithm does not requireresampling, and has other advantages. For further discussion, see this paper.

There is a third approach to study of heart rate time series, which is to useclassical frequency-domain algorithms such as the FFT with theirregularly-sampled heart rate time series. This approach, since it treatsthe time series as a "beat number" series, yields spectra that are notin the frequency domain, but in the sequency (sometimes called"beatquency") domain.

Heart Rate Variability

The commonly quoted scalar measures (SDNN: the standard deviation of NNintervals, pNN50: the fraction of NN intervals that differ by more than 50 msfrom the previous NN interval, RMSSD: the root-mean-square of successivedifferences of NN intervals) offer only a limited view of HRV. PhysioToolkitdoes not currently offer software for computing these measures, but you caneasily compute them from the NN intervals obtained using ann2rr. Thesemeasures were developed at a time when the standard technology for assessingHRV was a pair of calipers and a hand calculator. They represent only theaspect of HRV that is visible by inspection of a chart recording.Nevertheless, it is clear from many studies that these simple measures capturesignificant information that relates to age, health, mental and physicalworkload, and severity of disease.

The pNNx software package goes beyond theclassical time-domain measures, and calculates a family of statistics of whichpNN50 is a member. The study that introduced pNNx demonstrated that thesestatistics can be better discriminators than pNN50 between young and old,periods of wakefulness and sleep, and health and disease.

What these scalar measures do not capture is any information relating to theorder of the intervals, except for pairwise coupling. Such information can beobtained only by the use of more sophisticated analyses. Frequency-domainanalysis of HRV reveals much more. You may wish to explore HR power spectraobtained using lomb (Lomb-Scargleperiodogram estimation), fft (Fouriertransform), or memse (maximumentropy/all poles/autoregressive estimation).

RR Intervals, Heart Rate, and HRV Howto (5) RR Intervals, Heart Rate, and HRV Howto (6)
RR Intervals, Heart Rate, and HRV Howto (7)
The three spectra above and at left were created using these three methods fromthe HR time series shown in the previous section. If you have installed plt, you can duplicate these spectra by
hrlomb -r mitdb/100 -a atrhrfft -r mitdb/100 -a atrhrmem -r mitdb/100 -a atr
See the manual page for hrfftfor further details and options.

These samples illustrate the similarities and differences of these techniques.The AR method (memse / hrmem) yields much cleaner spectrathan the others; this property is an artifact of the method, however, whichmodels the spectrum using a relatively low-degree polynomial that cannotreproduce fine detail, whether that detail represents the signal or the noise.Although many papers on the subject of HRV contain attractively drawn ARspectra, it is simply not possible to know from a single AR spectrum if themodel order was adequate to capture the important frequency components of theinput. If you choose to use AR spectra anyway, always check your resultsagainst those obtained using one of the other methods illustrated here.

The Lomb and Fourier spectra more closely resemble each other. A uniqueproperty of the Lomb method is that it permits estimation of frequencycomponents at higher frequencies than the other methods, because there isno clearly defined Nyquist frequency in a non-uniform time series. Theresampling required by the other methods, by contrast, has the side effectof low-pass filtering the time series, so that components above roughly0.4 Hz are severely attenuated.

Even the best spectral density estimation algorithm cannot save you if the dataare contaminated, however. All three of these spectra exhibit this problem.The peaks at 0.167 and 0.28 Hz in this recording have previously beenidentified as artifacts of themechanical components of the analog tape recorder and playback unit used forthe original recording, and the 0.42 Hz peak in the Lomb spectrum wasidentified as another recorder drive train frequency, not previously observedas an artifact in a recording.

RR Intervals, Heart Rate, and HRV Howto (8) RR Intervals, Heart Rate, and HRV Howto (9)
RR Intervals, Heart Rate, and HRV Howto (10)
The important point is that one needs to look at spectra critically. In thiscase, it's relatively easy to spot these peaks in the Lomb and FFT spectra asimpossibly narrow for anything of physiologic origin; in the AR spectrum,however, they can easily be mistaken for peaks that have significance in termsof physiology, such as the broad peak centered around 0.33 Hz that reflectsrespiratory sinus arrhythmia (RSA). This peak is visible in the Lomb spectrumat upper left, obtained from the same data as above, in which the powerspectrum has been log-transformed; note that this peak is not readily apparentin the log-transformed FFT and MEM spectra above and at left.

The frontiers of research in HRV measurement lie in applications oftechniques such as approximateentropy (ApEn), sample entropy(SampEn), detrended fluctuationanalysis (DFA), information-basedsimilarity (IBS), multiscale entropy(MSE) analysis, and multifractal analysis. Thesemethods may be capable of revealing features of HRV that are notexposed using other methods of analysis, and that may have diagnosticand predictive value complementary to that obtainable using othermethods.

There is no general agreement about how to characterize (or how to interpret)heart rate variability. By choosing to study HRV, you will need to makechoices about the algorithms that you use, how to prepare the input to thosealgorithms, and what to do with their output.

Send feedback about this page to PhysioNet

Your comments and suggestions are welcome. Please send them to webmaster@physionet.org.

For general enquiries about PhysioNet and its contents and usage, please see our FAQ.

Updated Wednesday, 4 May 2016 at 09:58 EDT


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.
RR Intervals, Heart Rate, and HRV Howto (2024)

References

Top Articles
Latest Posts
Article information

Author: Terrell Hackett

Last Updated:

Views: 6000

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Terrell Hackett

Birthday: 1992-03-17

Address: Suite 453 459 Gibson Squares, East Adriane, AK 71925-5692

Phone: +21811810803470

Job: Chief Representative

Hobby: Board games, Rock climbing, Ghost hunting, Origami, Kabaddi, Mushroom hunting, Gaming

Introduction: My name is Terrell Hackett, I am a gleaming, brainy, courageous, helpful, healthy, cooperative, graceful person who loves writing and wants to share my knowledge and understanding with you.