mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.73k stars 1.32k forks source link

pb EDF reading #1660

Closed agramfort closed 9 years ago

agramfort commented 10 years ago

code below on this data:

https://partage.mines-telecom.fr/public.php?service=files&t=63240f5c7263fa0ad17ad61b67b0e970

does not produce results as EEGLAB. Basically the data with MNE seem to have been low passed. EEGLAB seems to upsample by duplicating samples.

import mne
import pylab as pl

pth = '050903120.05.09.14.16.52.17.Signals.edf'
raw = mne.io.read_raw_edf(pth, n_eeg=20, stim_channel=None, preload=True)
data, times = raw[:, :]
czdat = data[7, :]

NFFT, NOVR = 1024, 512
psd, freqs, tim, plot_ = pl.specgram(czdat, NFFT=NFFT, noverlap=NOVR, Fs=raw.info['sfreq'],
                                     detrend=pl.detrend_none, window=pl.window_hanning)

pl.show()
agramfort commented 10 years ago

if @t3on or any other can have a look it would be great.

larsoner commented 10 years ago

I get a blank page when I open that URL.

teonbrooks commented 10 years ago

it looks like 'SystemTimestamp' is sampled at 1024 and the eeg channels are sampled at 256.

we are currently using mne.filter.resample to deal with this case. https://github.com/mne-tools/mne-python/blame/master/mne/io/edf/edf.py#L287

larsoner commented 10 years ago

Is the system timestamp just a clock? It seems like it would be better not to resample the data channels if it could be avoided. Plus a clock you can just directly subsample (or even linearly interpolate) instead of needing to do anything fancy.

teonbrooks commented 10 years ago

yeah, well, currently the code resamples to the highest sampling rate. it was for the use case where emg (or other sensor) was sampled lower then the eeg and we needed to rectify the data shape irregularity. what would be the best way to proceed? i can only think of adding an arg but that is the most elegant way.

larsoner commented 10 years ago

I see three options:

  1. Upsample everything to the highest sampling rate in the data.
  2. Upsample everything to the highest sampling rate in the data, except for SystemTimeStamp (assuming it is just a clock). If it's just a clock, downsampling it shouldn't really matter.
  3. Resample everything to the EEG sample rate.

It sounds like we currently do 1. My vote would be for 2 or 3. Upsampling isn't the worst thing in the world, but with any kind of resampling technique will produce some amount of artifacts (esp. at the edges), which is why it would be better to avoid it if possible.

teonbrooks commented 10 years ago

I'm in favor of the option 3.

-teon

Teon Brooks, Pre-hD NSF Fellow, Chateaubriand Fellow PhD Candidate Department of Psychology New York University

On Tue, Nov 18, 2014 at 6:28 PM, Eric Larson notifications@github.com wrote:

I see three options:

1.

Upsample everything to the highest sampling rate in the data. 2.

Upsample everything to the highest sampling rate in the data, except for SystemTimeStamp (assuming it is just a clock). If it's just a clock, downsampling it shouldn't really matter. 3.

Resample everything to the EEG sample rate.

It sounds like we currently do 1. My vote would be for 2 or 3. Upsampling isn't the worst thing in the world, but with any kind of resampling technique will produce some amount of artifacts (esp. at the edges), which is why it would be better to avoid it if possible.

— Reply to this email directly or view it on GitHub https://github.com/mne-tools/mne-python/issues/1660#issuecomment-63509919 .

larsoner commented 10 years ago

@agramfort it seems like this would produce the same results as EEG lab, right?

agramfort commented 10 years ago

we need to look at the sampling rate EEGLAB returns. We could offer a parameter to upsample or not if both are useful. But I agree that the clock should not motivate upsampling the data for your artifact issue you mentioned.

larsoner commented 10 years ago

@t3on you up for tackling this?

teonbrooks commented 10 years ago

got it. closing for #1661

agramfort commented 9 years ago

The current code now is:

import mne
import pylab as pl

pth = '050903120.05.09.14.16.52.17.Signals.edf'
misc = ['ECG', 'AUX1', 'AUX2', 'AUX3', 'ESUTimestamp', 'SystemTimestamp',
        'Tilt X', 'Tilt Y', 'Tilt Z', 'EDF Annotations']
raw = mne.io.read_raw_edf(pth, misc=misc, stim_channel=None, preload=True)
data, times = raw[:, :]
czdat = data[7, :]

NFFT, NOVR = 1024, 512
psd, freqs, tim, plot_ = pl.specgram(czdat, NFFT=NFFT, noverlap=NOVR, Fs=raw.info['sfreq'],
                                     detrend=pl.detrend_none, window=pl.window_hanning)

pl.show()

raw.plot_psds()

btw we broke the API silently :-/

agramfort commented 9 years ago

However I think there is still a problem with sfreq. I get 1024 but it should be 256

teonbrooks commented 9 years ago

resolved with pr #1681