ziyujia/GraphSleepNet

data pre-processing from EDF to mat

famousgrouse opened this issue · 1 comments

Hi Ziyu Jia,

Could you please upload the EDF processing code or tools as well?

BW
Ben

Thanks for your attention,

In order to convert .edf files to other formats, one method is to use the "edflib" library (https://www.teuniz.net/edflib/index.html) to read the edf file.

The following is a brief C/C++ code that can read the data in the edf file into the memory.

#include "stdio.h"  
#include "edflib.h"  
  
#define num_channel 26      // number of channels  
#define max_timepoint 7950005 // max sampling time points  
  
double data[num_channel][max_timepoint]; // data matrix  
edf_annotation_struct annot[1000];      // label (annotation)  
  
int main() {  
    int i;  
    char path[200] = "XXXX.edf"; // edf file path  
  
    edf_hdr_struct hdr; // edf header  
    edfopen_file_readonly(path, &hdr, 2); // open the edf file, header info->hdr  
  
    // Read labels (annotations) ->annot  
    for (i = 0; i < hdr.annotations_in_file; i++)  
        edf_get_annotation(0, i, &annot[i]);  
  
    // Read data matrix ->data  
    for (i = 0; i < num_channel; i++)  
        edfread_physical_samples(0, i, hdr.file_duration / hdr.datarecord_duration * hdr.signalparam[i].smp_in_datarecord, data[i]);  
    edfclose_file(0);  
  
    /* 
    You can use any method (txt, mat...) to save the data matrix and labels here. 
    Note:The timepoint of some channels may not use the pre-allocated maximum length. 
    */  
  
    return 0;  
}  

Of course, this is just a demo, and you need to carefully adjust the code for specific use.
In addition, tools such as EDFbrowser and mne may also be helpful to you.

Best Regards.