writting raw fif files with mne_ex_read_write_raw

Hello MNE users,

I am trying to use the function in the example mne_ex_read_write_raw.m

It works, quite well if for infile and outfile I am using the same data

My point is that with the option line 74/75
quantum_sec=10
quantum = ceil(quantum_sec*raw.info.sfreq)

the data matrix does not have the same number of data point compared to the original and I am struggling to understand what the conversion is

I would like to read the raw data in one set and
I tried to use the line 79 instead
quantum = to - from +1

And for this option the data is written but if I try to open the fif file with mne_browse_raw
it crashed with the following error message

*** glibc detected *** free():invalid pointer: 0x006a4860***
Abort

I also try to change line 74/75 by
quantum_sec=1000
quantum = ceil(quantum_sec*raw.info.sfreq)

and it crashed mne_browse_raw in the same way as previous

Any suggestions are highly appreciated.

Thanks and best wishes,

Elisabeth

Hi,

mne_ex_read_write_raw.m write data in blocks, block size of 1000 sec seems
to be preety large,

I have made raw fif files before but always in blocks of 10 secs.

Sheraz

Hi Elisabeth,

may I ask what you want to do at the end? crop your data?

Alex

Hello again

The idea is to read first the raw original fif file with the structure
Then change the data matrix (output of the reading) and replace it by raw data that have been ICA (removal of blink with SPM) and in the end write back the data. The ICA data are decomposed in 3 different sensors that we have to recombined into the appropriate matrix, this matrix should have the same size has the reading data..
All that could be done smoothly if I can have all the data point (i.e use the option quantum = to - from +1) which seems not to work for the moment.
Or may be am I using it incorrectly?

Thanks for your answer

Elisabeth

Hi Elisabeth,

data are stored in buffers in fif files, so to do what you want to do
I would read
the entire raw data by chunks and store the chunks in one big matlab matrix.
Then apply your artifact rejection method before writing again the
data by chunks.
It requires a bit of coding though.

Regarding the ICA, beware that magnetometers and gradiometers have
different scales and if you don't pay attention your ICA will be dominated
by the signals with the highest variance ie. the magnetometers.

Alex

Hi Elisabeth,

If you want you can do eog or ecg clean in mne automatically using PCA, I
have matlab functions to do it.

Let me know if this is something intresting to you.

Sheraz

Hi Alex, & Sheraz and the list

Thank you for your help
I managed to sort out my problem with working on the buffer size and everything looks ok.

Regarding the comments from Alex about ICA:
We used ICA separately for each sensors (Mag, Grad, and EEG) and remove the blink component separately.
Then we recombined all the sensors together..
Do you think it will be appropriate like that or will you recommend another way to do so?

Best wishes and happy bank holiday (in UK at least)

Elisabeth

Dear Elisabeth,

Well, that is the method laid out in these two papers:

http://www.ncbi.nlm.nih.gov/pubmed/21256967
http://www.ncbi.nlm.nih.gov/pubmed/20123024

So, I would think it was appropriate, though there are certainly other approaches that may be preferred.

Best Wishes,
Avniel

Dear Elisabeth,

Sorry, I did just realize that in both of the papers I mentioned they (and we) were using a CTF machine, so only had gradiometers, so I don't have experience with using a separate ICA for each sensor type.

Best Wishes,
Avniel

Dear All,

In continuation of this current thread I have a question, when we do PCA
we apply projection vector on the leadfield also.

ICA is also spatial filtering, should not ICA spatial vector should also
be applied to the Lead field.

Kind Regards

Sheraz

Hi,

If the noise covariance is derived from the ICA-processed data, whitening automatically accounts for the dimension reduction caused by the ICA.

- Matti

Hi Elisabeth,

Thank you for your help
I managed to sort out my problem with working on the buffer size and everything looks ok.

great.

Regarding the comments from Alex about ICA:
We used ICA separately for each sensors (Mag, Grad, and EEG) and remove the blink component separately.
Then we recombined all the sensors together..

ok that works.

Do you think it will be appropriate like that or will you recommend another way to do so?

you could also scale the different group of sensors to make them comparable
in terms of variance to run the ICA jointly.

Alex

Hi Matti,

Good point. What would you suggest if we are using empty room noise to build the noise covariance matrix?

Best Wishes,
Avniel

Dear all,

Just to add to this discussion on artifact removal (especially the
DC-level jumps which are common to several channels), here is a quick and
dirty approach that has worked for me.

For each channel
1. Differentiate the signal so that the DC jumps show up as large spikes
2. Replace the large spikes by the median of its neighborhood (median filter)
3. Re-integrate the signal

In general it seems to be more robust than ICA to remove DC-level jumps.

Best,
Pavan

Hi Avniel,
  Though derived using the temporal structure in the signals, ICA is
ultimately a static (i.e purely spatial) transformation. So how about
saving the ICA weights from the brain data and applying the same spatial
transformation to the empty room recordings?

Regards,
Hari

Hi,