Converting data from .mat to .edf in MATLAB

Dear community,

I am trying to save epoched data that is stored in .mat file as .edf using ft_write_data. For example, one of my .mat files has 1713 trials with 651 datapoints in each trial amounting to 1713 * 651 = 1115163 columns in total. I use the following code to concatenate data of these trials and save it as .edf file.

mat_data = load(mat_file_name);
filehdr = ft_fetch_header(mat_data.data);
concat_data = cat(2,mat_data.data.trial{:});
ft_write_data(edf_file_name , concat_data, ‘header’, filehdr);

I get a .edf file which has only 1115000 columns. Similarly, in another case, original file has 1257081 columns but the generated .edf file has only 1257000 columns.

Could anyone please tell what could be causing this to happen? Or, could anyone please suggest a better approach for this conversion?

Thanks and regards,
Akshi
IIIT-Bangalore, India

1 Like

Python option- pyedflib (and scipy.io.loadmat)
https://pyedflib.readthedocs.io/

1 Like

Hi Akshi,

The EDF format writes data in blocks, and by default (in line with the online specification at https://www.edfplus.info) these blocks are one second long. In your case the 1115163 samples are truncated to 1115000, i.e. 163 samples are dropped because they don’t form a complete block. If you want all samples to be written, you should pad your data to an integer multiple of seconds.

best regards,
Robert

2 Likes

Hello sir,

This explains it! Thank you very much for this insight.

Sincerely,
Akshi

Hi brai,

Thank you for your reply. I’d gone ahead with some other approach (not involving edf). I’ll keep this in mind for future.

Sincerely,
Akshi

2 Likes