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

`= hrv_detect(eeg) nn_seg, r_idx `

Output:

```
[ Info: ECG channel found: 24
[ Info: Detected NN segments: 1288
```

Check peaks:

```
= eeg.data[24, :, :][:]
ecg = Plots.plot(ecg[1:20*sr(eeg)], # 20 seconds
p =:black,
lc=0.5,
lw=false,
legend=false,
yticks=false)
xticks= Plots.vline!(r_idx[1:21], # 21 peaks
p =:dot,
ls=:red,
lc=0.5)
alphaplot_save(p, file_name="images/rr.png")
```

`hrv_analyze(nn_seg)`

Results:

```
menn = 926.176
mdnn = 937.5
vnn = 6966.958
sdnn = 83.468
rmssd = 68.297
sdsd = 68.323
nn50 = 27
pnn50 = 0.021
nn20 = 67
pnn20 = 0.052
```