hrvtools

hrv_features

get_domain_function(domain)[source]
Parameters:

domain (str) –

Return type:

Callable

get_hrv_features(sampling_rate, signal_length, signal_type='PPG', input_type='ppi', peaks_locs=None, troughs_locs=None, ppi=None, feature_types=['Freq', 'Time', 'Nonlinear'], prefix='hrv')[source]

Calculates HRV parameters

Parameters:
  • sampling_rate (float) – Sampling rate of the ppg/ecg signal.

  • signal_length (float) – Length of ppg/ecg signal (seconds).

  • signal_type (str, optional) – Signal type to calculate hrv parameters. Should be ‘ppg’ or ‘ecg’. Defaults to ‘ppg’.

  • input_type (str, optional) – Input type for the analyses. Should be ‘ppi’, ‘peaks’ or ‘troughs’. Defaults to ‘ppi’. Depending on the input type, corresponding input array should be provided.

  • peaks_locs (ArrayLike, optional) – Peak locations of the ppg/ecg signal. Defaults to None.

  • troughs_locs (ArrayLike, optional) – Onset locations of the ppg signal. Defaults to None.

  • ppi (ArrayLike, optional) – Peak-to-peak intervals of the ppg/ecg signal (miliseconds). Defaults to None.

  • feature_types (ArrayLike, optional) – List of the type of hrv parameters to be calculated. Defaults to [‘Freq’,’Time’,’Nonlinear’].

  • prefix (str, optional) – Prefix for the calculated parameters. Defaults to ‘hrv’.

Raises:
  • ValueError – If elements of feature_types are not ‘Freq’, ‘Time’ or ‘Nonlinear’.

  • ValueError – If ‘ppi’ is None although the input type is ‘ppi’.

  • ValueError – If ‘peaks_locs’ is None although the input type is ‘peaks’.

  • ValueError – If ‘trough_locs’ is None although the input type is ‘troughs’.

  • ValueError – If the input_type is not ‘ppi’, ‘peaks’ or ‘troughs.

Returns:

Dictionary of calculated HRV parameters.

Return type:

dict

hrv_freqdomain

hrv_freq_features(ppi, sampling_rate, prefix='hrv')[source]

Calculates frequency-domain hrv parameters.

vlf: Spectral power pertaining to very low frequency band (0.0033 to 0.04 Hz by default.) lf: spectral power pertaining to low frequency band (0.04 to 0.15 Hz by default.) hf: spectral power pertaining to high frequency band (0.15 to 0.4 Hz by default.) lf_hf_ratio: ratio of lf to hf total_power: sum of vlf, lf and hf lfnu: normalized spectral power pertaining to low frequency band (ratio of lf to total_power) hfnu: normalized spectral power pertaining to high frequency band (ratio of hf to total_power) lnLF: log transformed low-frequency power lnHF: log transformed high-frequency power vlf_peak: max peak of power spectral density in very low frequency band lf_peak: max peak of power spectral density in low frequency band hf_peak: max peak of power spectral density in high frequency band

Parameters:
  • ppi (ArrayLike) – Peak-to-peak interval array (miliseconds).

  • prefix (str, optional) – Prefix for the calculated parameters. Defaults to ‘hrv’.

  • sampling_rate (int) –

Returns:

Dictionary of frequency-domain hrv parameters.

Return type:

dict

hrv_nonlinear

hrv_nl_features(ppi, sampling_rate, prefix='hrv')[source]

Calculates nonlinear hrv parameters.

SD1: standard deviation of Poincare plot perpendicular to the line of identity SD2: standard deviation of Poincare plot along the line of identity SD2SD1: ratio of SD2 to SD1 CSI: cardiac stress index CVI: cardiac vagal index CSI_modified: modified cardiac stress index ApEn: approximate entropy of peak to peak intervals SampEn: sample entropy of peak to peak intervals

Parameters:
  • ppi (ArrayLike) – Peak-to-peak interval array (miliseconds)

  • prefix (str, optional) – Prefix for the calculated parameters. Defaults to ‘hrv’.

  • sampling_rate (int) –

Returns:

Dictionary of nonlinear hrv parameters.

Return type:

dict

hrv_timedomain

hrv_time_features(ppi, sampling_rate, prefix='hrv')[source]

Calculates time-domain hrv parameters.

mean_nni: mean of peak to peak intervals sdnn: standard deviation of peak to peak intervals. Often calculated over a 24-hour period. rmssd: root mean square of successive differences between peak to peak intervals sdsd: standard deviation of successive differences between peak to peak intervals nni_50: number of pairs of successive intervals that differ by more than 50 ms pnni_50: ratio of nni_50 to total number of intervals nni_20: number of pairs of successive intervals that differ by more than 20 ms pnni_20: ratio of nni_20 to total number of intervals cvnni: ratio of sdnn to mean_nni cvsd: ratio of rmssd to mean_nni median_nni: median of absolute values of successive differences between peak to peak intervals range_nni: range of peak to peak intervals mean_hr: mean heart rate min_hr: minimum heart rate max_hr: maximum heart rate std_hr: standard deviation of heart rate mad_nni: mean absolute deviation of peak to peak intervals mcv_nni: ratio of mead_nni to median_nni iqr_nni: interquartile range of peak to peak intervals

Parameters:
  • ppi (ArrayLike) – Peak-to-peak interval array (miliseconds).

  • prefix (str, optional) – Prefix for the calculated parameters. Defaults to ‘hrv’.

  • sampling_rate (int) –

Returns:

Dictionary of time-domain hrv parameters.

Return type:

dict