We are going to use the physioscripts
suite of functions to use peak signal detection and compute the IBI series. In order to use the built-in signal detection utilities in this suite of functions, each participant needs a few additional files to tell the program how to handle the raw data. The phys_file()
and phys_info()
functions helper functions I wrote to put the raw ECG signal into a format that the automatic R peak detection algorithm (from the physioscripts
package) is expecting.
source('R/hrv_tutorial/physio_functions.R')
df <- readRDS(data, file = 'data/hrv_tutorial/sub1101a.RDS')
# create and write each new ecg file and event file
phys_file(df, c('time','ecg'), 'data/hrv_tutorial/sub1101')
phys_info('sub1101', 'data/hrv_tutorial/', fs = 1000, origin = NA)
Now, we can pass the .phys.csv
file to the process and extract functions.
files <- list.files('data/hrv_tutorial/', pattern = 'phys.csv', full.names = TRUE)
process.ecg(in.file.list = files, processing.mode = "batch")
extract.ibi(in.file.list = files, processing.mode = "batch")
Let’s take a look at the ibi file that was created:
head(read.csv('data/hrv_tutorial/sub1101.phys.csv'))
## time ecg r
## 1 0.000 0.01647949 NA
## 2 0.001 0.01647949 NA
## 3 0.002 0.01861572 NA
## 4 0.003 0.02227783 NA
## 5 0.004 0.02593994 NA
## 6 0.005 0.02929688 NA
head(read.csv('data/hrv_tutorial/sub1101.ibi.gz'))
## time ibi
## 1 1.323 887
## 2 2.195 872
## 3 3.064 869
## 4 3.898 834
## 5 4.643 745
## 6 5.375 732