Garmin FIT files for RHRV analysis

2. csv to beats files for RHRV analysis

Author

Kizen Sasaki

First version

2023 November 29

Modified

2023 December 04

** 2.1. Load readr package to read/write csv, Excel files.**

Code
if(!require("readr", quietly = TRUE)){
  install.packages("readr");require("readr")
}

2.1.1. Read the csv file created in the previous part.
*Note: Enter the file number to be processed in FileNo<-xx.
Pre-process data files so that they can be processed by RHRV.

Code
FileNo <- 1
FileName <- paste0("time_HR_", FileNo, ".csv")

data <- read.table(file.path("csv_xls", FileName), header = TRUE, sep = ",", colClasses = c("character", "numeric"))

hr <- data[,2]
rr <- 1/hr
rr = rr*60*1000

2.1.3. Load the package RHRV.

Code
if(!require("RHRV", quietly = TRUE)){ install.packages("RHRV");require("RHRV") } 

library(RHRV)

2.1.4. Create a data frame for RHRV analysis.

To compute the HRV time series the BuidNIHR function is used (Build Non Interpolated Heart Reate).
This function constructs both the RR (Equation 2.1) and instantaneous heart rate (HR) series (Equation 2.2) described in Section 2.1**Getting started with RHRV version 2.0.

RR{n}=a(t_{n}-t_{n-1})~~~~~~~~~~(2.1)~~~~~~~~~~   HR{n}=\frac{β}{t_{n}-t_{n-1}}~~~~~~~~~~(2.2)

Code
hrv.data <- CreateHRVData()
hrv.data <- SetVerbose(hrv.data, TRUE)
hrv.data$Beat$RR = rr
hrv.data$Beat$niHR = hr
hrv.data$Beat$Time = cumsum(rr)/1000

2.1.5. Create a data frame for RHRV analysis.

Figure 1: Plot of the episodic information

Code
hrv.data <- FilterNIHR(hrv.data)
PlotNIHR(hrv.data)
hrv.data <- InterpolateNIHR(hrv.data, freqhr = 4)
PlotHR(hrv.data) 

(a) Non-interpolted Heart Rate time plot

(b) Interpolted Heart Rate time plot

Figure 1: Heart Rate time plot (Marathon 2023/11/29)

2.1.6. Create a data frame for RHRV analysis.

Code
hrv.data <- CreateTimeAnalysis(hrv.data, size = 300, interval = 7.8125)
Code
library(tidyverse)

df <- hrv.data$TimeAnalysis %>%
    as.data.frame() %>%
    slice(1, 2) %>%
    select(2:11)
Code
# Table 1: Summary of the previous pages
knitr::kable(df[1:10], caption = "Table 1: Summary of the analysis", digits = 3, booktabs = TRUE)
Table 1: Summary of the analysis
SDNN SDANN SDNNIDX pNN50 SDSD rMSSD IRRR MADRR TINN HRVi
19.234 15.853 8.287 0 1.717 1.717 21.533 0 51.92 3.323