NeuroAnalyzer tutorials: HRV

Load data:

using NeuroAnalyzer
using Plots
eeg = load("files/eeg.hdf");
[ Info: Loaded: EEG (24 × 282991 × 1; 1105.43 s)

Heart rate variability (HRV) is the physiological phenomenon of variation in the time interval between heartbeats. It is measured by the variation in the beat-to-beat interval (source: Wikipedia).

NeuroAnalyzer allows detecting and analysis of HRV using ECG channel.

The following time-domain parameters are analyzed:

  • MENN: the mean of NN intervals
  • MDNN: the median of NN intervals
  • VNN: the variance of NN intervals
  • SDNN: the standard deviation of NN intervals
  • RMSSD: (“root mean square of successive differences”), the square root of the mean of the squares of the successive differences between adjacent NNs
  • SDSD: (“standard deviation of successive differences”), the standard deviation of the successive differences between adjacent NNs
  • NN50: the number of pairs of successive NNs that differ by more than 50 ms
  • pNN50: the proportion of NN50 divided by total number of NNs
  • NN20: the number of pairs of successive NNs that differ by more than 20 ms
  • pNN20: the proportion of NN20 divided by total number of NNs

First, detect peaks:

nn_seg, r_idx = hrv_detect(eeg)
[ Info: ECG channel found: ECG
[ Info: Detected NN segments: 1287
(nn_seg = [945.3125, 929.6875, 929.6875, 945.3125, 941.40625, 929.6875, 820.3125, 929.6875, 941.40625, 933.59375  …  19.53125, 31.25, 19.53125, 19.53125, 19.53125, 23.4375, 19.53125, 19.53125, 19.53125, 19.53125],
 r_idx = [146.0, 388.0, 626.0, 864.0, 1106.0, 1347.0, 1585.0, 1795.0, 2033.0, 2274.0  …  282829.0, 282837.0, 282842.0, 282847.0, 282852.0, 282858.0, 282863.0, 282868.0, 282873.0, 282878.0],)

Visualize peaks to check if were detected correctly:

ch = get_channel(eeg, ch="ecg")
ecg = eeg.data[24, :, :][:]
Plots.plot(ecg[1:10*sr(eeg)],               # 10 seconds
           lc=:black,
           lw=0.5,
           ylims=(-2000, 2000),
           legend=false,
           yticks=false,
           xticks=false)
Plots.vline!(r_idx[1:11],                   # 11 peaks
             ls=:dot,
             lc=:red,
             alpha=0.5)

Finally, analyze peaks properties:

hrv_analyze(nn_seg)
(menn = 858.137,
 mdnn = 937.5,
 vnn = 67015.708,
 sdnn = 258.874,
 rmssd = 89.096,
 sdsd = 89.128,
 nn50 = 46.0,
 pnn50 = 0.036,
 nn20 = 86.0,
 pnn20 = 0.067,)