Convert EDFfile in .mat

MNE version: 1.0.3
operating system: Google Collab

The essence, or context, of my question is regarding EDF conversion to .MAT,

The problem is that file structures are so different that make me lost, in the process of writing the algorithm. I have no idea how I could identify similar data samples in order to structure it in the proper places.

  1. MAT Data samples from BCI IV Competition, Berlin dataset 1. Matlab files (BCI Competition IV)

  2. EDF Data samples from Physionet EEG Motor Movement/Imagery Dataset v1.0.0

The goal is to run a python script, (neuroscience_tutorials/3. Imagined movement.ipynb at master · wmvanvliet/neuroscience_tutorials · GitHub) which works fine with MAT sample files, but with another data sample. For instance, I’ve chosen Physionet EDF files.

That’s why I need to convert Physionet .EDF files to .MAT files, within the same file structure, to be able to run the script and analyze if the processing ( i.e. feature extraction, classification, Spatial filters, PSD - Potential Spectral Density, confusion matrix, accuracy, etc), are still valid/consistent.

Let me know if my approach makes any sense. Please.

Below, I will try to explain the scenario by writing examples of codes and comments.

i) .MAT file has beendefined as :
Sample Shape: triasl[cl1] (59, 200, 100) # trials[cl1].shape
Sample Shape: triasl[cl2] (59, 200, 100) # trials[cl2].shape
Channels: 59
Sample rate: 100Hz

ii) while EDF file has been defined as:
Samples Shape: (64, 20000) # xraw.shape
Channels Nr.: 64
Sample rate: 160.00 Hz

So, there was no pre-processing step to the EDF file. Meaning, there’s no differentiation between left and right classes. Neither, channels data have been well structured by default as they are within .MAT files. (ie. as in trials[cl1] and trials[cl2])

Therefore, where can I find data corresponding to Fp1, Fpz and Fp2 within EDF? Where are the channels samples?

ANSW:

print(rawEEG.ch_names[21]) # Fp1
print(rawEEG.ch_names[22]) # Fpz
print(rawEEG.ch_names[23]) # Fp2

Then, my guess is that their corresponding data is within

xraw = rawEEG.get_data()
xraw.shape  # (64, 20000)

print(xraw[21])  # array([-7.1e-05, -8.3e-05, -8.4e-05, ...,  0.0e+00,  0.0e+00,  0.0e+00])
print(xraw[22])  # array([-5.8e-05, -7.1e-05, -7.1e-05, ...,  0.0e+00,  0.0e+00,  0.0e+00])
print(xraw[23])  # array([-6.0e-05, -7.4e-05, -7.1e-05, ...,  0.0e+00,  0.0e+00,  0.0e+00])

are they actually the samples I’m looking for?

… and about the rest of the file structure?

I did even tried to adapt your functions:
(i) psd(trials_filt[cl1])and psd(trials_filt[cl2]),
(ii) logvar(trials) and
(iii) train_lda(train[cl1].T, train[cl2].T),

but again I got stuck in the channel and data samples. They simply don’t match.

So, How I would post that in the discussion forum?
I believe that’s quite a bit our of the scope. rsrs :wink:

Bet wishes,
I

Hello @iuri and welcome to the forum!

I’d suggest not to convert to MAT, but instead using MNE’s built-in EDF reading functionality to load the data, and then run the rest of the processing in the notebook on that imported data. Much less error-prone than trying to manually squeeze things into an arbitrary data format.

Best wishes,
Richard

hmm…
“If the Mountain won’t go to Mohammed, then Mohammed must come to the Mountain ”.
Meaning,
Instead of fitting the data to the algorithm, I must adapt the algorithm to the data.

Thanks Richard!
I’ll be back soon!

1 Like