Home > database > fmri > regressors > fmri_regress_timespan.m

fmri_regress_timespan

PURPOSE ^

limits onsets and durations by timespan ratings

SYNOPSIS ^

function [onsets,durs,resp_params] = fmri_regress_timespan(pinfo,minfo,inons,indurs,inresp)

DESCRIPTION ^

 limits onsets and durations by timespan ratings
 
   [onsets,durs,resp_params] = fmri_regress_timespan(pinfo,minfo,inons,indurs,inresp)
 
 takes presentation data, model information, and event onsets, finds
 and calculates timespan ratings, and then adjusts the onsets, durs, and
 resp_params to only reflect the timespan that was rated for the given
 response. those onsets and durations that are not adjusted by this
 function are not returned. See also: fmri_regress_stim.m

 REQUIRES
   pinfo - presentation data
   minfo - model info
   inons - onset times, in ms
   indurs - event durations, in s
   inresp - resp_params, or a parametric weighting of each event

 RETURNS
   onsets - onsets, adjusted for each timespan rating, in ms
   durs - durations, adjusted for each timespan rating, in s
   resp_params - parametric weighting of each event being returned

 FB 2010.01.27

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [onsets,durs,resp_params] = fmri_regress_timespan(pinfo,minfo,inons,indurs,inresp)
0002 
0003 % limits onsets and durations by timespan ratings
0004 %
0005 %   [onsets,durs,resp_params] = fmri_regress_timespan(pinfo,minfo,inons,indurs,inresp)
0006 %
0007 % takes presentation data, model information, and event onsets, finds
0008 % and calculates timespan ratings, and then adjusts the onsets, durs, and
0009 % resp_params to only reflect the timespan that was rated for the given
0010 % response. those onsets and durations that are not adjusted by this
0011 % function are not returned. See also: fmri_regress_stim.m
0012 %
0013 % REQUIRES
0014 %   pinfo - presentation data
0015 %   minfo - model info
0016 %   inons - onset times, in ms
0017 %   indurs - event durations, in s
0018 %   inresp - resp_params, or a parametric weighting of each event
0019 %
0020 % RETURNS
0021 %   onsets - onsets, adjusted for each timespan rating, in ms
0022 %   durs - durations, adjusted for each timespan rating, in s
0023 %   resp_params - parametric weighting of each event being returned
0024 %
0025 % FB 2010.01.27
0026 
0027 onsets = [];
0028 durs = [];
0029 resp_params = [];
0030 
0031 if isfield(minfo,'timespan_defs')
0032     tsd = minfo.timespan_defs;
0033 else
0034     error('no timspan defs found');
0035 end
0036 
0037 if ~all([length(inons) length(indurs)] == length(inresp))
0038     error('onsets, durations, and response parameters unequal in length');
0039 end
0040 
0041 pc = set_var_col_const(pinfo.vars);
0042 
0043 % calculate timespan ratings from presentation data
0044 tsfind = strfind(pinfo.data{pc.EVENT_CODE},'timespan_cue');
0045 tsidxs = find(~cellfun(@isempty,tsfind));
0046 
0047 for j=1:length(tsidxs);
0048     codes = pinfo.data{pc.RESP_CODE}{tsidxs(j)};
0049     pos = tsd.start; lvl = 0; start = 1; stop = tsd.nbins;
0050     for k=1:length(codes)
0051       code = str2num(codes{k});
0052       switch code
0053         case tsd.resp.enter
0054           if lvl == 0
0055             if pos == tsd.nbins
0056               pos = tsd.nbins - 1;
0057             end
0058             start = pos;
0059             pos = pos + 1;
0060             lvl = lvl+1;
0061           elseif lvl == 1
0062             stop = pos;
0063             lvl = lvl+1;
0064           end % if lvl == 0
0065         case {tsd.resp.left,tsd.resp.right}
0066           if lvl == 2
0067             if code == tsd.resp.left
0068               pos = tsd.start;
0069               start = 1;
0070               stop = tsd.nbins;
0071               lvl = 0;
0072             elseif code == tsd.resp.right
0073               lvl = lvl + 1;
0074               break
0075             end
0076           elseif lvl < 2
0077             if code == tsd.resp.left
0078               pos = max(pos - 1,start);
0079             elseif code == tsd.resp.right
0080               pos = min(pos + 1,tsd.nbins);
0081             end
0082           end % if lvl == 2
0083       end % switch code
0084     end % for k=1:length(codes
0085     start = start/tsd.nbins;
0086     stop = stop/tsd.nbins;
0087     
0088     % link this timespan judgment with a stimulus
0089     time = pinfo.data{pc.RUN_REL_TIME}(tsidxs(j))/1000;
0090     oidx = find(inons < time,1,'last');
0091     
0092     % modify the onset/dur, add the resp_param, for this stimulus
0093     onsets(end+1) = inons(oidx)+indurs(oidx)*start;
0094     durs(end+1) = indurs(oidx)*(stop-start);
0095     resp_params(end+1) = inresp(oidx);
0096 end % for j=1:length(tsidxs
0097

Generated on Thu 09-Dec-2010 04:01:40 by m2html © 2003