# Convert EDFfile in .mat

**URL:** <https://mne.discourse.group/t/convert-edffile-in-mat/4952>\
**Category:** Support & Discussions\
**Tags:** data-import\
**Created:** [May 26, 2022, 4:21pm UTC](https://mne.discourse.group/t/convert-edffile-in-mat/4952 "2022-05-26T16:21:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iuri](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/iuri/32/1509_2.png) [@iuri](https://mne.discourse.group/u/iuri)\
**Post date:** [May 26, 2022, 4:21pm UTC](https://mne.discourse.group/t/convert-edffile-in-mat/4952/1 "2022-05-26T16:21:04Z")

</div>

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](https://www.bbci.de/competition/iv/#dataset1))

2. EDF Data samples from Physionet [EEG Motor Movement/Imagery Dataset v1.0.0](https://physionet.org/content/eegmmidb/1.0.0/)

The goal is to run a python script, ([neuroscience\_tutorials/3. Imagined movement.ipynb at master · wmvanvliet/neuroscience\_tutorials · GitHub](https://github.com/wmvanvliet/neuroscience_tutorials/blob/master/eeg-bci/3.%20Imagined%20movement.ipynb)) 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:

```python
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

```python
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 😉

Bet wishes,  
I

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [May 27, 2022, 11:21am UTC](https://mne.discourse.group/t/convert-edffile-in-mat/4952/2 "2022-05-27T11:21:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iuri](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/iuri/32/1509_2.png) [@iuri](https://mne.discourse.group/u/iuri)\
**Post date:** [May 27, 2022, 1:59pm UTC](https://mne.discourse.group/t/convert-edffile-in-mat/4952/3 "2022-05-27T13:59:21Z")

</div>

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!
