ucdavis / erplab

ERPLAB Toolbox is a free, open-source Matlab package for analyzing ERP data. It is tightly integrated with EEGLAB Toolbox, extending EEGLAB’s capabilities to provide robust, industrial-strength tools for ERP processing, visualization, and analysis. A graphical user interface makes it easy for beginners to learn, and Matlab scripting provides enormous power for intermediate and advanced users.
http://erpinfo.org/erplab
261 stars 74 forks source link

creaeventinfo() wrongly assumes that EEG.event.duration represents duration in samples #144

Open Bysmuth opened 3 years ago

Bysmuth commented 3 years ago

Description

creaeventinfo() sets event duration (dura) equal to (EEG.event.duration/EEG.srate)*1000, presumably to convert from samples to time. However, as documented here, the unit of EEG.event.duration is already time (not samples). I believe that this leads to a conversion error.


Steps to Reproduce

  1. Import a file recorded at any sampling rate other than 1000 Hz using Net Station (extension .mff) containing 1+ events with non-default durations. In my case, the file was recorded at 500 Hz and the very first event was a user-added 'bad segment' event (code == 'bads') with duration == 1086000 (1086 ms). After importing this into EEGLAB, EEG.srate == 500 and EEG.event(1).duration == 1086000.

  2. Run pop_editeventlist() to create an EEG.EVENTLIST structure. After doing this for my file, EEG.EVENTLIST.eventinfo(1).dura == 2172000. (And because my function call to pop_editeventlist() updated my EEG.event structure, EEG.event(1).duration == 2172000.)

  3. When I called pop_editeventlist() again later (after calling pop_erplabShiftEventCodes(), which removed EEG.EVENTLIST), it compounded the error further, setting EEG.event(1).duration and EEG.EVENTLIST.eventinfo(1).dura to 4344000. And so on.


Versions

OS version MacOS 10.13.6
Matlab version R2018b
EEGLAB version 2019.1
ERPLAB version 7.0
Bysmuth commented 3 years ago

On second thought: I just re-read the EEGLAB page to which I linked, and I now interpret the sentence about how duration information is stored differently than I did previously. If duration information is indeed stored internally in samples, then (1) perhaps there is a bug in the MFFMatlabIO plugin (which I used to import .mff files into EEGLAB), as it may not be converting duration information correctly; but also (2) it seems potentially problematic for creaeventinfo() to convert duration information from samples to time and then transfer that information back to the EEG.event structure.