Home > marsbar > @mardo_99 > event_onsets.m

event_onsets

PURPOSE ^

method gets (estimated) onsets and durations for event/session

SYNOPSIS ^

function [onsets, durations] = event_onsets(D, e_spec)

DESCRIPTION ^

 method gets (estimated) onsets and durations for event/session
 FORMAT [onsets durations] = event_onsets(D, e_spec)

 D          - design object
 e_spec     - event specification (see event_fitted for details)
 
 Returns
 onsets     - onset times in TRs
 durations  - duration of events in TRs

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [onsets, durations] = event_onsets(D, e_spec)
0002 % method gets (estimated) onsets and durations for event/session
0003 % FORMAT [onsets durations] = event_onsets(D, e_spec)
0004 %
0005 % D          - design object
0006 % e_spec     - event specification (see event_fitted for details)
0007 %
0008 % Returns
0009 % onsets     - onset times in TRs
0010 % durations  - duration of events in TRs
0011 %
0012 % $Id$
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 % In fact, the above is durations, as entered by the users.  The durations
0060 % as expressed in the design matrix are given by (durations) * sc

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019