Module HRV¶
-
class
HRV.HRV.HRV¶ This class allows to perform a basic Heart Rate Variability Analysis from an RR-Interval time series. It is supposed that a numpy array (n_samples, 1) with RR intervals is available, as well as beat label numpy array vector.
HRV is the term used to describe the variations in the time intervals between consecutive heart beats. HRV is usually studied by analyzing the RR-interval time series (beat-to-beat time interval) derived from the ECG. The extraction of the RR-intervals from the ECG can be achieved by measuring the time intervals between QRS complexes, which are the electrical marks registered in an ECG when a cardiac beat occurred. RR-interval time series (sometimes called RR tachogram) is usually constructed as a function of the interval number. HRV is due to the activity of the SA node, as the source of the repetitive impulses that generate the normal beats. The SA node is in turninfluenced by the ANS, namely by the parasympathetic and sympathetic branches, which interact in a complex way with a variety of reflexes and systems. HRV has been suggested as a noninvasive tool to assess the state of the system that controls the heart rhythm and its relationship with cardiovascular mortality. The clinical relevance of the HRV has been established in several studies. Hon and Lee reported in 1965 that fetal distress was preceded by alterations in the interbeat intervals. Wolf et al. established in 1977 an association of higher risk of post-infarction mortality in patients with reduced HRV. Indeed, it has been shown that low HRV is associated with some cardiac illness: myocardial infarction, atherosclerosis, heart failure, and even with ageing. The underlying assumption, when studying HRV, is that short-term and long-term variations in HR have different physiological origins and the magnitude of these variations has been shown to be indicative of the autonomic state of the subject. For instance, after a myocardial infarction, the innervation level of the heart decreases, and part of the nervous control of this organ can be lost. The HRV reflects this control loss and it makes possible the classification of SCD risk groups. The degeneration of the ANS due to the ageing can also be inferred by the analysis of the HRV. Therefore, it would be possible to characterize different cardiovascular states by just measuring the HRV. The methods used in HRV analysis can be very roughly divided into three main groups, namely, time-domain methods, frequency-domain methods, and nonlinear methods. Time-domain methods are the simplest ones in computational terms. They treat the RR-interval sequence as an unordered set of intervals and employ different techniques to express the variance of such data. They can be split into two categories statistical descriptors, and geometrical descriptors. Frequency-domain methods are based on PSD estimation, which providesthe basic information on how the power (i.e. the variance) is distributed as a function of frequency. The different systems modulating the HR (i.e. modulating the behavior of the ANS) oscillate spontaneously with specific frequencies. Thus, when the PSD is taken from a HRV signal, it is expected to extract information on those systems related to cardiac autonomic function, that is, to identify the harmonic frequency components that correspond to each system. It is possible, for example, to quantify the power of the different spectral components in PSD as a measurement of the contribution of each system to the global variability. PSD is generally estimated from the RR-Interval time series. Since it is a representation of the beat-to-beat variability, it is inherently a discrete and uneven time series (this is the reason for the variability). However, almost all of the PSD estimation methods require evenly sampled data.
In this class, Time-Domain and Frequency-Domain methods are implemented.
This introduction was taking from:
- Barquero-Pérez: “Robust Signal Processing in Cardiac Signals: Applications
in Heart Rate Variability, Heart Rate Turbulence and Fibrillatory Arrhythmias”. PhD Dissertation. 2014 (Spain).
-
Welch_Periodogram(rr, fs=4.0, window=u'hamming', nperseg=256, noverlap=128, nfft=1024)¶ Estimate power spectral dnesity using Welchs method.
It is just a wrapper function of the method provided by
scipy.signal.welch
[1] - Welch, “The use of the fast Fourier transform for the
estimation of power spectra: A method based on time averaging over short, modified periodograms”, IEEE Trans. Audio Electroacoust. vol. 15, pp. 70-73, 1967. .. [2] M.S. Bartlett, “Periodogram Analysis and Continuous Spectra”, Biometrika, vol. 37, pp. 1-16, 1950.
-
artifact_ectopic_correction(rr, ind_not_N, method=u'cubic')¶ Function that corrects artifact-ectopic beats by interpolation.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- ind_not_N_beats: boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
- method : “cubic”, “linear”,”nearest”,”zero”,”slinear”, “quadratic”,”cubic”, default = “cubic”
- Kind of interpolation, by default spline interpolation of third order. For more details see
- rr_correcte : numpy array (n_samples,1)
- RR interval time serie with interpolated RR intervals in places detected as non-sinusal.
scipy.interpolate.interp1d
-
artifact_ectopic_detection(rr, labels, prct, numBeatsAfterV=4)¶ Artifact detection function. This function call all the methods and combine the artifact-ectopic detection from them.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- labels : char numpy array (n_samples, 1)
- Labels for each beat indicating the nature (‘N’: Normal, ‘V’: Ventricular, else).
- prct : float
- Percentage used in the equation.
- numBeatsAFterV : int , optional. Default = 4
- Number of beats after a ventricular one (‘V’) that are considered non-sinusal.
- ind_not_N_beats: boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
As a recommendation use this function usgin a detrended rr interval signal, it usually produces better results.
-
avnn(nn)¶ Compute AVNN time domain index. The average value of all NN intervals computed over the complete time series.
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- mu : float
- AVNN time domain index [ms].
-
beat_label_filter(beat_labels, numBeatsAfterV=4)¶ Artifact detection function using beat labels. It processes the RR interval time series in a beat-wise fashion. An interval is identified as non-sinusal using the information of the beat detection label. Every label different from “N” is considered a nont-sinusal beat. Additionally, beats labele as “V” (ventricular), induces that the posterior beats are considered non-sinusal, even if the label is “N”. The number of beats after the “V” is controlled by “numBeatsAfterV”.
- beat_labels : char numpy array (n_samples, 1)
- Labels for each beat indicating the nature (‘N’: Normal, ‘V’: Ventricular, else).
- numBeatsAFterV : int , optional. Default = 4
- Number of beats after a ventricular one (‘V’) that are considered non-sinusal.
- ind_not_N : boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
-
elipse(xc, yc, theta, sd1, sd2, pintar=None)¶ Function that constructs an ellipse using a center localization given by xc and yc, the angle of the coordinates axes with respect to the horizontal given by theta, and lenthg of semi-axes given by sd1 and sd2. This funcionts is used to plot the estimation of the of the HRV Geometrical indices SD1 and SD2.
- xc : float
- Coordinate x of the center of the ellipse.
- yc : float
- Coordinate y from the center of the ellipse.
- theta : float
- Angle of the coordinate axes of the ellipse, with center c (xc, yc), with respect to the horizontal.
- sd1 : float
- Length of the x axis of the ellipse.
- sd2 :
- Length of the y axis of the ellipse.
- x : numpy array (n,1)
- X coordinates of the points of the ellipse along the x-axis.
- Y: numpy array (n,1)
- Y coordinates of the points of the ellipse along the y-axis.
-
hrvTriangIndex(rr, flag=None)¶ Compute HRV traingular geometrical index. Total number of all NN intervals divided by the height of the histogram of all NN intervals measured on a discrete scale with bins of 7.8125 ms (1/128 seconds).
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- flag : boolean
- It allows to sketch the histogram used to compute the HRV triangular index
- res : float
- HRV traingular index.
-
interp_to_psd(rr, t=None, fs=4.0, method=u'cubic')¶ Function that interpolates the RR interval time series to provide an evenly-sampled rr interval time series to be used in HRV frequency domain analysis. By default, the new RR interval time series is reinterpolated at fs = 4Hz.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- t : numpy array (n_samples, 1), optional
- Time instants vector. If it is not provided, t is built as the cumsum of the rr intervals time series.
- fs : float, optional
- Sampling frequency of the new reinterpolated signal. By default is 4 Hz
- method : “cubic”, “linear”,”nearest”,”zero”,”slinear”, “quadratic”,”cubic”, default = “cubic”
- Kind of interpolation, by default spline interpolation of third order. For more details see
- rr_interp : numpy array (n_samples,1)
- RR interval time serie reinterpolated at 4Hz.
- t_new : numpy array (n_samples, 1)
- Time vector instant at which occurr RR intervals.
scipy.interpolate.interp1d
-
is_valid(ind_not_N, perct_valid=0.2)¶ Function that checks the validity of a RR-interval time seris to be used in the HRV analysis. Usually if there are more than 20% of non-sinusals beats the segment is discarded for the posterior analysis.
- ind_not_N : boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
- perct_valid : float
- Percentage of the allowed Non-sinusal beats to use the segment for further HRV analysis.
- res : boolean
- If True, the segment is valid to be used in HRV analysis.
-
load_HRV_variables(rr)¶ Returns a dictionary with all the considered values of the heart rate variability calculated from the list of the rr intervals passed as a parameter
-
logIndex(rr, pintar=None)¶ Compute the Logarithmic index. Coefficient phi of the negative exponential curve k * exp(−phi*t), which is the best approximation of the histogram of absolute differences between adjacent NN intervals.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- pintar : boolean
- It allows to sketch the histogram used to compute the HRV triangular index
- res : float
- Logarithmic Index.
-
main_interp(rr, t=None, duration=5)¶ Helping fuction to create a new interpolated rr interval time series.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- t : numpy array (n_samples, 1), optional
- Time instants vector. If it is not provided, t is built as the cumsum of the rr intervals time series.
- duration: int, optional. Default = 5 (min)
- Length, in minutes, of the RR interval time series.
- numpy array (n_samples,1)
- RR interval time serie reinterpolated at 4Hz.
- t_new : numpy array (n_samples, 1)
- Time vector instant at which occurr RR intervals.
-
main_spectral_indices(Pxx, f=None, duration=5)¶ Wrapping funciton to obtain the spectral indices.
-
main_welch(rr_interpolated_4_hz, t=None, duration=5)¶ Wrapping function to obtain the Power Spectral Density of the RR interval time series.
: Welch_Periodogram
-
mediasPoincare(rr, flag=None)¶ Computes the geometric HRV indices based on the Poincare Plot.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- pintar : boolean
- It allows to sketch the histogram used to compute the HRV triangular index
- sd1 : float
- Dispersion of map points perpendicular to the axis of the identity line
- sd2 : float
- Dispersion of map points along the axis of the identity line
- cup : float
- Contributions for the decelerations of the heart rhythm by the Poincare points, based on the asymmetries of the map.
- cdown : float
- Contributions for the accelerations of the cardiac rhythm by the points of the Poincare, based on the asymmetries of the map.
-
nn50(nn)¶ Compute NN50 time domain index. The index is computed as the number of consecutive NN intevals that differ by more than 50 msec.
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- res : int
- NN50 time domain index [ms].
-
perct_filter(rr, prct)¶ Artifact detection function using information from previous interval. It processes the RR interval time series in a beat-wise fashion. Te actual RR interval is identified as non-sinusal if the following equation holds:
RR(n) > prct * RR(n-1) then RR(n) is non-sinusal- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- prct : float
- Percentage used in the equation.
- ind_not_N : boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
-
pnn50(nn)¶ Compute pNN50 time domain index. The index is computed as the fraction of consecutive NN intervals that differ by more than 50 msec.
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- res : float
- pNN50 time domain index.
-
pnnX(nn, x)¶ Compute pNNx time domain index. The index is computed as the fraction of consecutive NN intervals that differ by more than x msec.
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- x : float
- X in ms, difference between consecutive NN intervals.
- res : float
- pNNx time domain index.
-
rmssd(nn)¶ Compute RMSSD time domain index. The index is computed as the root mean square of successive RR interval differences
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- res : float
- RMSSD time domain index, [ms].
-
sdann(nn, t=None, window_min=5)¶ Compute SDANN time domain index. The index is the standard deviation of the average NN intervals for each 5 min segment of a 24 hh HRV recording
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- t : numpy arrary (n_sample, 1), optional
- Vector of time in ms units.
- window_min : int, optional
- Segment length in minutes.
- stadev : float
- SDANN time domain index, [ms].
-
sdnn(nn)¶ Compute SDANN time domain index. The index is the standard deviation of the average NN intervals for each 5 min segment of a 24 hh HRV recording
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- t : numpy arrary (n_sample, 1), optional
- Vector of time in ms units.
- window_min : int, optional
- Segment length in minutes.
- stadev : float
- SDANN time domain index, [ms].
-
sdnnidx(nn, t=None, window_min=5)¶ Compute SDNN-index time domain index. Mean of the standard deviations of all NN intervals for all 5-minute segments of the entire recording. Usually 24 hh Holter recordings
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- t : numpy arrary (n_sample, 1), optional
- Vector of time in ms units.
- window_min : int, optional
- Segment length in minutes.
- res : float
- SDNN-index time domain index, [ms].
-
sdsd(nn)¶ Compute SDSD time domain index. Standard deviation of differences between adjacent NN intervals.
- nn : numpy array (n_samples, 1)
- NN intervals time series, in ms units.
- res : float
- SDSD time domain index, [ms].
-
spectral_indices(Pxx, f, duration=5)¶ Function that computes the HRV frequency domain indices. It computes the following indices using the PSD. Definition of the frequency bands depends on the segment duration. By default, spectral indices are computed for 5 min segments.
- Total Power [ms^2]. The variance of NN intervals over the temporal segment. Frequency range <= 0.4 Hz.
- PULF [ms^2]. Power in ULF range. Frequency range <= 0.003 (Only segments with more than 5 min).
- PVLF [ms^2]. Power in VLF range. Frequency range <= 0.04 Hz (5 min), [0.003,0.04] Hz (>= 5 min).
- PLF [ms^2]. Power in LF range. Frequency range [0.04-0.15] Hz.
- PHF [ms^2]. Power in HF range. Frequency range [0.15-0.4] Hz.
- LF/HF. Ratio PLF/PHF.
- Pxx : numpy array (n_samples,1)
- Power spectral density of the rr interval time series. [ms^2/Hz]
- f : numpy array (n_samples, 1)
- Frequency vector [Hz]
- duration: int, optional. Default = 5 (min)
- Length, in minutes, of the RR interval time series.
- Ptot : float
- Total power.
- Pulf : float
- Power in the ULF range.
- Pvlf : float
- Power in the VLF range.
- Plf : float
- Power in the LF range.
- Phf: float
- Power in the HF range.
- lfhf_ratio : float
- Ration PLF/PHF.
-
threshold_filter(rr)¶ Artifact detection function using threshold method. It processes the RR interval time series in a beat-wise fashion. An interval is identifiead as non-sinusal if RR(n) > thr_up or RR(n) < thr_low where: thr_up = 2000 (ms); thr_low = 300 (ms).
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- ind_not_N : boolean numpy array (n_samples,1)
- Boolean array with True in locations where the corresponding RR interval is non-sinusal (not Normal).
-
tinn(rr, flag=None)¶ Function that computes TINN index. Baseline width of the minimum square difference triangular interpolationof the highest peak of the histogram of all NN intervals.
- rr : numpy array (n_samples, 1)
- RR intervals time series, in ms units.
- flag : boolean
- It allows to sketch the histogram used to compute the HRV triangular index
- res : float
- TINN index [ms].