0001 function [onsets, durations] = event_onsets(D, e_spec)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin < 2
0015 error('Need design and event spec');
0016 end
0017 if ~is_fmri(D)
0018 error('Needs FMRI design');
0019 end
0020 if prod(size(e_spec)) > 2
0021 error('Can only deal with one event at a time');
0022 end
0023 dt = bf_dt(D);
0024 TR = tr(D);
0025
0026 s={'SPM99 design: attempting dodgy reconstruction of onsets/durations', ...
0027 'Reconstruction assumes that:',...
0028 'Events of this trial type never overlap in time (before convolution)', ...
0029 '(if they do, your SPM99 model will be badly messed up in any case)',...
0030 'and:', ...
0031 'The gap between the end of one event and beginning of the next ', ...
0032 sprintf('is always more than %3.2f seconds', dt)};
0033 if verbose(D), warning(sprintf('%s\n', s{:})); end
0034
0035 s = e_spec(1);
0036 e = e_spec(2);
0037 SPM = des_struct(D);
0038 sf = SPM.Sess{s}.sf{e}(:,1);
0039
0040 sfi = find(sf);
0041 dsfi = [1; diff(sfi) > 1];
0042 onsets = sfi(logical(dsfi));
0043 durations = zeros(size(onsets));
0044
0045 for oi = 1:length(onsets)
0046 pos = onsets(oi);
0047 durations(oi) = 0;
0048 while(sf(pos))
0049 durations(oi) = durations(oi) + 1;
0050 pos = pos + 1;
0051 if pos > length(sf), break, end
0052 end
0053 end
0054
0055 sc = dt / TR;
0056 onsets = (onsets - 1) * sc;
0057 durations = (durations - 1) * sc;
0058
0059
0060