Back to the main page.

Bug 3207 - support reading annotations from an EDF+ file

Status CLOSED FIXED
Reported 2016-11-15 14:23:00 +0100
Modified 2017-01-17 11:29:47 +0100
Product: FieldTrip
Component: fileio
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P5 normal
Assigned to: Robert Oostenveld
URL:
Tags:
Depends on:
Blocks:
See also:

Robert Oostenveld - 2016-11-15 14:23:01 +0100

The file contains ECoG data from Maastricht. The annotation channel is of a different sampling rate.


Robert Oostenveld - 2016-11-15 16:09:15 +0100

I made a branch "bug3207-edf" and started testing with the provided dataset. With test3_2048Hz.EDF I already detected an error, since the annotation channel was not (as expected in the code) the last one in the file. I fixed that. commit 378418254396ac0966deadc0b823dd7f6e7b88ad FIX - don't assume the annotation channel is always the last, it can be another one as well. See http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3207 commit fde31b5bd546ff86aade208c8cd0d5e0619959e4 ENH - use emptymeaningfull=true for detectflank, otherwise EDF annotation cannot be read. See http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3207


Robert Oostenveld - 2016-11-16 10:38:12 +0100

commit b765f9182aa4bd4f9473bcb49e2b2b602bfc1e23 ENH - added more elaborate section to test sscript, some cleanups to the read_edf function (no functional changes). See http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3207 commit 71d360d4d60e9a3ff6b556fdb3720cd8f16197d8 ENH - added test script, see bug #3207


Robert Oostenveld - 2016-11-16 10:43:40 +0100

I created a PR and merged it into the release. https://github.com/fieldtrip/fieldtrip/pull/261


Robert Oostenveld - 2016-11-16 10:46:44 +0100

@Mark, can you get the latest version of fieldtrip and have a look at the last section of the test script at https://github.com/fieldtrip/fieldtrip/blob/master/test/test_bug3207.m it makes use of the following trial function ---- function [trl, event] = trialfun_edf(cfg) % read the header hdr = ft_read_header(cfg.dataset); % read the events, don't detect flanks in a trigger channel but read annotations event = ft_read_event(cfg.dataset, 'detectflank', []); % make a selection sel = ismember({event.value}, {''}); % determine the sample numbers of events smp = [event(sel).sample]; begsample = smp-round(0.250*hdr.Fs); endsample = smp+round(0.750*hdr.Fs); offset = -ones(size(begsample))*round(0.250*hdr.Fs); trl = [begsample(:) endsample(:) offset(:)]; sel = trl(:,1)>1; trl = trl(sel,:); sel = trl(:,2)<hdr.nSamples; trl = trl(sel,:); ----- The option 'detectflank'=[] is important, since otherwise it will try to read a sampled TTL trigger channel and detect up- or downing flanks in that channel. If [] it will read and parse the ascii content of the annotation channel.


Robert Oostenveld - 2016-11-16 10:59:08 +0100

I have added some documentation to http://www.fieldtriptoolbox.org/getting_started/edf


Mark Roberts - 2016-11-16 22:17:48 +0100

I downloaded version fieldtrip-20161115. On my home PC running 32 bit matlab 2009 I don' t get the events. I will try on a a different PC tomorrow.


Mark Roberts - 2016-11-17 00:04:15 +0100

with 64bit matlab version I get events in the larger edf file, with the smaller I get an error from read_16bit. In the larger file that does give events I only get 'annotation' for each event not what was written. I set detectflank to [] when calling ft_read_event but it gets set to 'up' at around line 145 of ft_read_event. I only get events if I set detectflank to [] in ft_read_event Will try again with a different PC


Robert Oostenveld - 2016-11-17 09:55:32 +0100

(In reply to Mark Roberts from comment #7) the edits that I made on 2016-11-16 will not be in version 20161115. You can also get the latest version directly from github as a zip file (or using git).


Mark Roberts - 2016-11-17 19:18:20 +0100

got it, it is working great


Robert Oostenveld - 2016-11-17 20:56:46 +0100

(In reply to Mark Roberts from comment #9) Thanks for the feedback. Please pass it on to Pieter.


Robert Oostenveld - 2017-01-17 11:29:47 +0100

closed multiple bugs that were resolved some time ago