Back to the main page.

Bug 2262 - ft_specest_hilbert has a problem with padding

Status CLOSED FIXED
Reported 2013-08-22 23:17:00 +0200
Modified 2013-09-23 15:32:48 +0200
Product: FieldTrip
Component: specest
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P3 normal
Assigned to: Roemer van der Meij
URL:
Tags:
Depends on:
Blocks:
See also:

Diego Lozano Soldevilla - 2013-08-22 23:17:33 +0200

Created attachment 508 data toy example ft_specest_hilbert has a different padding implementation in comparison with the rest of the ft_specest* functions (data attached to reproduce bug): cfg = []; cfg.channel = 'all'; cfg.method = 'hilbert'; cfg.output = 'fourier'; cfg.toi = -2:0.05:4; cfg.foi = 8:12; cfg.filttype = 'firls'; cfg.filtorder = 4; cfg.filtdir = 'twopass'; cfg.width = 1; cfg.keeptrials= 'yes'; filt = ft_freqanalysis(cfg,meg); the input is raw data with 1 channels and 4 trials Warning: method = hilbert requires user action to deal with filtering-artifacts > In ft_freqanalysis at 286 processing trials Subscript indices must either be real positive integers or logicals. Error in ft_specest_hilbert (line 153) spectrum(:,ifreqoi,:) = dum(:,timeboi+padlength); Error in ft_freqanalysis (line 535) [spectrum,foi,toi] = ft_specest_hilbert(dat, time, 'timeoi', cfg.toi, 'filttype', cfg.filttype, 'filtorder', cfg.filtorder, 'filtdir', cfg.filtdir, 'width', cfg.width, options{:}, 'feedback', f (pad-dattime) output gives a very small negative number that floor makes it -1 and here the problem on looping through spectrum variable. Changing the cfg.pad (8secs in this case) doesn't solve the problem with the padlength variable: the input is raw data with 1 channels and 4 trials Warning: method = hilbert requires user action to deal with filtering-artifacts > In ft_freqanalysis at 286 processing trials trial 3, frequency 3 (10.00 Hz) Warning: Size vector should be a row vector with integer elements. > In ft_preproc_padding at 107 In ft_specest_hilbert at 152 In ft_freqanalysis at 535 Warning: Size vector should be a row vector with integer elements. > In ft_preproc_padding at 107 In ft_specest_hilbert at 152 In ft_freqanalysis at 535 Subscript indices must either be real positive integers or logicals. Error in ft_specest_hilbert (line 153) spectrum(:,ifreqoi,:) = dum(:,timeboi+padlength); Error in ft_freqanalysis (line 535) [spectrum,foi,toi] = ft_specest_hilbert(dat, time, 'timeoi', cfg.toi, 'filttype', cfg.filttype, 'filtorder', cfg.filtorder, 'filtdir', cfg.filtdir, 'width', cfg.width, options{:}, 'feedback', f SUGGESTION: I propose to implement all the padding as in all other ft_specest* functions would solve the problem (Indeed I don't know why ft_specest_hilbert is different...) % Zero padding if round(pad * fsample) < ndatsample error('the padding that you specified is shorter than the data'); end if isempty(pad) % if no padding is specified padding is equal to current data length pad = dattime; end postpad = round((pad - dattime) * fsample); endnsample = round(pad * fsample); % total number of samples of padded data endtime = pad; % total time in seconds of padded data instead of the current implementation: % Zero padding if round(pad * fsample) < ndatsample error('the padding that you specified is shorter than the data'); end if isempty(pad) % if no padding is specified padding is equal to current data length pad = dattime; end padlength = floor((pad-dattime)* fsample)./2;


Roemer van der Meij - 2013-09-23 14:20:10 +0200

Hi Deigo, Sorry for the long delay, I've changed the way padding is calculated now: prepad = floor(((pad - dattime) * fsample) ./ 2); postpad = ceil(((pad - dattime) * fsample) ./ 2); This should prevent any roundoff issues with sample numbers. Could you check and see if your example works?


Diego Lozano Soldevilla - 2013-09-23 15:05:05 +0200

solved! Thanks