signal <- sin(seq(0, 10, 0.01))
channels <- list(
# signal
as_edf_channel(channel_num = 1, signal,
sample_rate = 375.5),
as_edf_channel(channel_num = 2, signal,
sample_rate = 200),
# annotation
as_edf_channel(channel_num = 3, data.frame(
timestamp = c(0, 1, 2),
comments = c("Start", "half to go", "Finish!")
))
)
# write to file
path <- tempfile(fileext = ".edf")
write_edf(con = path, channels = channels)
edf <- read_edf(con = path, extract_path = tempdir())
annot <- edf$get_annotations()
annot
ch1 <- edf$get_channel(1)
# around 1e-5 due to digitization
range(ch1$value[seq_along(signal)] - signal)
ch2 <- edf$get_channel(2)
range(ch2$value[seq_along(signal)] - signal)
plot(ch1$time, ch1$value, type = "l",
main = "Toy-example")
lines(ch2$time, ch2$value, col = "red")
abline(v = annot$timestamp, col = "gray", lty = 2)
edf$delete()
unlink(path)
Run the code above in your browser using DataLab