rmatlabeeglabeuropean-data-format

Reading EDF header


I have 100+ EEG EDF files. I want to extract the start time and date along with the recording duration into a data frame. Is there any easy way to extract this data? Preferabely in R or Matlab.

I have succesfully extracted the data using:

library(edfReader)
CHdr <-  readEdfHeader("E:/data/EDF/Rtest/EEG1 (2).edf")
summary(CHdr)

format (CHdr$startTime, format="%Y-%m-%d %H:%M:%S",  usetz = FALSE)
CHdr$recordedPeriod

But doing this for the 100+ EDF files, might get a bit tiresome...


Solution

  • You can use lapply with readEdfHeader to get all the headers in one code line.

    First, a working example with the package data sets.

    old_dir <- getwd()
    libDir <- system.file("extdata", package = 'edfReader')
    setwd(libDir)
    

    Get the .edf filenames and read their headers.

    fls <- list.files(pattern = '\\.edf')
    edf_headers <- lapply(fls, readEdfHeader)
    

    Next, extract the relevant information and rbind it to create a data.frame.

    res <- lapply(edf_headers, function(x){
      startTime <- x[['startTime']]
      startDate <- substr(x[['recordingId']], 11, 21)
      recordDuration <- x[['recordDuration']]
      data.frame(startTime, startDate, recordDuration)
    })
    res <- do.call(rbind, res)
    res
    #            startTime   startDate recordDuration
    #1 2000-01-01 14:15:16 01-JAN-2000            0.1
    #2 2009-12-10 12:44:02 10-DEC-2009            1.0
    #3 2009-12-10 12:44:02 10-DEC-2009            1.0
    

    Reset the working directory.

    setwd(old_dir)