# mhrv.rri¶

## ansrr()¶

mhrv.rri.ansrr(rri, freqs, varargin)

Add Noised Sines to RR interval time series. This function generates a signal of sines embedded in gaussian white noise and adds it to an RR interval time series.

Parameters: rri – RR-intervals values in seconds. freqs – Vector containing desired sine frequencies, in Hz. varargin – Pass in name-value pairs to configure advanced options: var_r: Desired variance of the RR intervals. Can be used the scale the intervals before adding the noised sines. Leave empty to forgo scaling. mix: Mixture ratio between the given RR intervals and the generated sines. Default: 0.5 i.e. sines will have alf the variance of the RR intervals (after scaling). snr: Signal to Noise ratio of the white gaussian noise that will be added to the sines. Default: 2. rri_out: RR intervals after adding noised sines.

## detrendrr()¶

mhrv.rri.detrendrr(rri, lambda, Fs, varargin)

A detrending method [4] for the RR intervals. This is used when analysing RR interval time series over a long window thus where the stationarity assumption is not valid anymore. Of note: a number of HRV methods such as the fragmentation measures and the DFA measures do not assume the intervals to be stationary. Thus usage of this detrending tool is specific to what HRV measures are being studied. Detrending will also likely affect the low frequency fluctuation information contained in the VLF band.

Parameters: rri – Vector of RR-interval dirations (seconds) lambda – lambda (lambda=10 for Human) Fs – the sampling frequency of the original ECG signal (Hz) varargin – Pass in name-value pairs to configure advanced options: plot: true/false whether to generate a plot. Defaults to true if no output arguments were specified (boolean). rri_detrended: detrended rri interval (seconds)

Example: process an ecg recording sampled at 1000 Hz and specifying a refractory period of 250 ms (a standard value for Human ECG) and with a threshold of 0.5.

recordName = 'mitdb/105';
[ecg,fs,~] = rdsamp(recordName,1);
bpfecg = bpfilt(ecg,fs,5,45,[],0); % prefilter in range [5-45] Hz
anns_jqrs = wjqrs(bpfecg,fs,0.3,0.250,10); % jqrs running on each segment of 10 sec length
z = diff(anns_jqrs)/fs; % get the RR intervals

nni_detrend = detrend_nn(z',10,'Fs',Fs ,'plot',true); % detrend and plot

 [4] Tarvainen, Mika P., Perttu O. Ranta-Aho, and Pasi A. Karjalainen. “An advanced detrending method with application to HRV analysis.” IEEE Transactions on Biomedical Engineering 49.2 (2002): 172-175.

## dfa()¶

mhrv.rri.dfa(t, sig, varargin)

Detrended fluctuation analysis, DFA [1]. Calculates the DFA of a signal and it’s scaling exponents $$\alpha_1$$ and $$\alpha_2$$.

Parameters: t – time (or x values of signal) sig – signal data (or y values of signal) varargin – Pass in name-value pairs to configure advanced options: n_min: Minimal DFA block-size (default 4) n_max: Maximal DFA block-size (default 64) n_incr: Increment value for n (default 2). Can also be less than 1, in which case we interpret it as the ratio of a geometric series on box sizes (n). This should produce box size values identical to the PhysioNet DFA implmentation. alpha1_range: Range of block size values to use for calculating the $$\alpha_1$$ scaling exponent. Default: [4, 15]. alpha2_range: Range of block size values to use for calculating the $$\alpha_2$$ scaling exponent. Default: [16, 64]. n: block sizes (x-axis of DFA) fn: DFA value for each block size n alpha1: Exponential scaling factor alpha2: Exponential scaling factor
 [1] Peng, C.-K., Hausdorff, J. M. and Goldberger, A. L. (2000) ‘Fractal mechanisms in neuronal control: human heartbeat and gait dynamics in health and disease, Self-organized biological dynamics and nonlinear control.’ Cambridge: Cambridge University Press.

## filtrr()¶

mhrv.rri.filtrr(rri, trr, varargin)

Calculate an NN-interval time series (filtered RR intervals). Performs outlier detection and removal on RR interval data. This function can perform three types of different outlier detection, based on user input: Range based detection, moving-average filter-based detection and quotient filter based detection.

Parameters: rri – RR-intervals values in seconds. trr – RR-interval times in seconds. varargin – Pass in name-value pairs to configure advanced options: filter_range: true/false whether to use range filtering (remove intervals smaller or larger than ‘rr_min’ and ‘rr_max’). filter_ma: true/false whether to use a moving-average filter to detect potential outliers in the rr-intervals. If an interval is greater (abs) than ‘win_percent’ percent of the average in a window of size ‘win_samples’ around it, excludes the interval. filter_quotient: true/false whether to use the quotient filter. This fliter checks the quotient between an interval and it’s predecessor and successors, and only allows a configured change percentage (‘rr_max_change’) between them. win_samples: Number of samples in the filter window on each side of the current sample (total window size will be 2*win_samples+1). Default: 10. win_percent: The percentage above/below the average to use for filtering. Default: 20. rr_min: Min physiological RR interval, in seconds. Intervals shorter than this will be removed prior to poincare plotting. Default: 0.32 sec. rr_max: Max physiological RR interval, in seconds. Intervals longer than this will be removed prior to poincare plotting. Default: 1.5 sec. rr_max_change: Maximal change, in percent, allowed between adjacent RR intervals. Intervals violating this will be removed prior to poincare plotting. Default: 25. plot: true/false whether to generate a plot. Defaults to true if no output arguments were specified. nni: NN-intervals (RR intervals after removing outliers) values in seconds tnn: NN-interval times in seconds

## freqfiltrr()¶

mhrv.rri.freqfiltrr(rri, fc, varargin)

Performs frequency-band filtering of RR intervals. This function can apply a low-pass or high-pass filter to an RR interval time series.

Parameters: rri – RR-intervals values in seconds. fc – Filter cutoff frequency, in Hz. varargin – Pass in name-value pairs to configure advanced options: resamp_freq: Frequency to resample the RR-intervals at before filtering. Must be at least twich the maximal frequency in the signal. Default: 5 Hz. forder: Order (length in samples) of the filter to use. Default: 100. ftype: A string, either ‘low’ or ‘high’, specifying the type of filter to apply. plot: true/false whether to generate a plot. Defaults to true if no output arguments were specified. rri_out: RR intervals after filtering. trr_out: Times of filtered RR intervals, in seconds.

## mse()¶

mhrv.rri.mse(sig, varargin)

Calculates the Multiscale Entropy [2], MSE, of a signal, a measure of the signals complexity. The algorithms calculates the Sample Entropy of the signal at various ‘scales’ from 1 to max_scale. At each scale, the signal is downsampled by averaging ‘scale’ samples and the Sample Entropy is calculated for the downsampled signal.

Parameters: sig – Signal to calculate MSE for. varargin – Pass in name-value pairs to configure advanced options: mse_max_scale: Maximal scale to calculate up to. Default: 20. sampen_r: Value of ‘r’ parameter to use when calculating sample entropy (max distance between two points that’s considered a match). Default: 0.2. sampen_m: Value of ‘m’ parameter to use when calculating sample entropy (length of templates to match). Default: 2. normalize_std: Whether or not to normalize the signal to std=1 before calculating the MSE. This affects the meaning of r. plot: true/false whether to generate a plot. Defaults to true if no output arguments were specified. mse_result: The sample entropy value at each scale. scale_axis: The corresponding scale values that were used.
 [2] Costa, M. D., Goldberger, A. L. and Peng, C.-K. (2005) ‘Multiscale entropy analysis of biological signals’, Physical Review E - Statistical, Nonlinear, and Soft Matter Physics, 71(2), pp. 1–18.

## poincare()¶

mhrv.rri.poincare(rri, varargin)

Calculates HRV metrics from a Poincaré plot of the input data.

Parameters: rri – Row vector of RR-interval lengths in seconds. varargin – Pass in name-value pairs to configure advanced options: sd1_factor: Factor to multiply the standard devation along the perpendicular line (SD1) to get the radius of the ellipse along that axis. Default is 2 (so over 95% of points will be inside the ellipse). sd2_factor: As above, but for the standard deviation along the line of identity (SD2). Default: 3. plot: true/false whether to generate a plot. Defaults to true if no output arguments were specified. sd1: Standard deviation of RR intervals along the axis perpendicular to the line of identity. sd2: Standard deviation of RR intervals along the line of identity.

## sample_entropy()¶

mhrv.rri.sample_entropy(sig, m, r)

Calculate sample entropy [3] (SampEn) of a signal. Sample entropy is a measure of the irregularity of a signal.

Parameters: sig – The input signal. m – Template length in samples. r – Threshold for matching sample values. The sample entropy value of the input signal.
 [3] Richman, J. S., & Moorman, J. R. (2000). ‘Physiological time-series analysis using approximate entropy and sample entropy.’ American Journal of Physiology. Heart and Circulatory Physiology, 278(6), H2039?H2049.