returns input [designed effects] structures FORMAT [U] = spm_get_ons(SPM,s) s - session number (used by batch system) U - (1 x n) struct array of (n) trial-specific structures U(i).name - cell of names for each input or cause U(i).u - inputs or stimulus function matrix U(i).dt - time bin (seconds) U(i).ons - onsets (in SPM.xBF.UNITS) U(i).dur - durations (in SPM.xBF.UNITS) U(i).P - parameter struct. U(i).P(p).name - parameter name U(i).P(p).P - parameter vector U(i).P(p).h - order of polynomial expansion U(i).P(p).i - sub-indices of u pertaining to P _______________________________________________________________________ SLICE TIMIING With longs TRs you may want to shift the regressors so that they are aligned to a particular slice. This is effected by resetting the values of defaults.stats.fmri.t and defaults.stats.fmri.t0 in spm_defaults. defaults.stats.fmri.t is the number of time-bins per scan used when building regressors. Onsets are defined in temporal units of scans starting at 0. defaults.stats.fmri.t0 is the first time-bin at which the regressors are resampled to coincide with data acquisition. If defaults.stats.fmri.t0 = 1 then the regressors will be appropriate for the first slice. If you want to temporally realign the regressors so that they match responses in the middle slice then make defaults.stats.fmri.t0 = defaults.stats.fmri.t/2 (assuming there is a negligible gap between volume acquisitions. Default values are defaults.stats.fmri.t = 16 and defaults.stats.fmri.t0 = 1. _______________________________________________________________________ @(#)spm_get_ons.m 2.40 Karl Friston 03/07/03
0001 function [U] = pr_spm_get_ons(SPM,s) 0002 % returns input [designed effects] structures 0003 % FORMAT [U] = spm_get_ons(SPM,s) 0004 % 0005 % s - session number (used by batch system) 0006 % 0007 % U - (1 x n) struct array of (n) trial-specific structures 0008 % 0009 % U(i).name - cell of names for each input or cause 0010 % U(i).u - inputs or stimulus function matrix 0011 % U(i).dt - time bin (seconds) 0012 % U(i).ons - onsets (in SPM.xBF.UNITS) 0013 % U(i).dur - durations (in SPM.xBF.UNITS) 0014 % U(i).P - parameter struct. 0015 % 0016 % U(i).P(p).name - parameter name 0017 % U(i).P(p).P - parameter vector 0018 % U(i).P(p).h - order of polynomial expansion 0019 % U(i).P(p).i - sub-indices of u pertaining to P 0020 %_______________________________________________________________________ 0021 % 0022 % 0023 % SLICE TIMIING 0024 % 0025 % With longs TRs you may want to shift the regressors so that they are 0026 % aligned to a particular slice. This is effected by resetting the 0027 % values of defaults.stats.fmri.t and defaults.stats.fmri.t0 in 0028 % spm_defaults. defaults.stats.fmri.t is the number of time-bins per 0029 % scan used when building regressors. Onsets are defined 0030 % in temporal units of scans starting at 0. defaults.stats.fmri.t0 is 0031 % the first time-bin at which the regressors are resampled to coincide 0032 % with data acquisition. If defaults.stats.fmri.t0 = 1 then the 0033 % regressors will be appropriate for the first slice. If you want to 0034 % temporally realign the regressors so that they match responses in the 0035 % middle slice then make defaults.stats.fmri.t0 = 0036 % defaults.stats.fmri.t/2 (assuming there is a negligible gap between 0037 % volume acquisitions. Default values are defaults.stats.fmri.t = 16 0038 % and defaults.stats.fmri.t0 = 1. 0039 % 0040 % 0041 %_______________________________________________________________________ 0042 % @(#)spm_get_ons.m 2.40 Karl Friston 03/07/03 0043 0044 %-GUI setup 0045 %----------------------------------------------------------------------- 0046 spm_help('!ContextHelp',mfilename) 0047 0048 % time units 0049 %----------------------------------------------------------------------- 0050 k = SPM.nscan(s); 0051 T = SPM.xBF.T; 0052 dt = SPM.xBF.dt; 0053 try 0054 UNITS = SPM.xBF.UNITS; 0055 catch 0056 UNITS = 'scans'; 0057 end 0058 switch UNITS 0059 0060 case 'scans' 0061 %---------------------------------------------------------------- 0062 TR = T*dt; 0063 0064 case 'secs' 0065 %---------------------------------------------------------------- 0066 TR = 1; 0067 end 0068 0069 % get inputs and names (try SPM.Sess(s).U first) 0070 %======================================================================= 0071 try 0072 U = SPM.Sess(s).U; 0073 v = length(U); 0074 catch 0075 0076 %-prompt string 0077 %--------------------------------------------------------------- 0078 str = sprintf('Session %d: trial specification in %s',s,UNITS); 0079 spm_input(str,1,'d') 0080 0081 U = {}; 0082 v = spm_input('number of conditions/trials',2,'w1'); 0083 end 0084 0085 % get trials 0086 %----------------------------------------------------------------------- 0087 for i = 1:v 0088 0089 % get names 0090 %--------------------------------------------------------------- 0091 try 0092 Uname = U(i).name(1); 0093 catch 0094 str = sprintf('name for condition/trial %d ?',i); 0095 Uname = {spm_input(str,3,'s',sprintf('trial %d',i))}; 0096 U(i).name = Uname; 0097 end 0098 0099 % get main [trial] effects 0100 %================================================================ 0101 0102 % onsets 0103 %--------------------------------------------------------------- 0104 try 0105 ons = U(i).ons; 0106 ons = ons(:); 0107 catch 0108 ons = []; 0109 end 0110 if ~length(ons) 0111 str = ['vector of onsets - ' Uname{1}]; 0112 ons = spm_input(str,4,'r',' ',[Inf 1]); 0113 U(i).ons = ons(:); 0114 0115 end 0116 0117 % durations 0118 %--------------------------------------------------------------- 0119 try 0120 dur = U(i).dur; 0121 dur = dur(:); 0122 catch 0123 dur = []; 0124 end 0125 if ~length(dur) 0126 str = 'duration[s] (events = 0)'; 0127 while 1 0128 dur = spm_input(str,5,'r',' ',[Inf 1]); 0129 if length(dur) == 1 0130 dur = dur*ones(size(ons)); 0131 end 0132 if length(dur) == length(ons), break, end 0133 str = sprintf('enter a scalar or [%d] vector',... 0134 length(ons)); 0135 end 0136 U(i).dur = dur; 0137 end 0138 0139 % peri-stimulus times {seconds} 0140 %--------------------------------------------------------------- 0141 pst = [1:k]*T*dt - ons(1)*TR; 0142 for j = 1:length(ons) 0143 w = [1:k]*T*dt - ons(j)*TR; 0144 v = find(w >= -1); 0145 pst(v) = w(v); 0146 end 0147 0148 0149 % add parameters x trial interactions 0150 %================================================================ 0151 0152 % get parameter stucture xP 0153 %---------------------------------------------------------------- 0154 try 0155 xP = U(i).P; 0156 Pname = xP(1).name; 0157 0158 switch Pname 0159 0160 case 'none' 0161 %------------------------------------------------ 0162 xP.name = 'time'; 0163 xP.h = 0; 0164 0165 end 0166 0167 catch 0168 0169 Pname = {'none','time','other'}; 0170 Pname = spm_input('parametric modulation',6,'b',Pname); 0171 0172 switch Pname 0173 0174 case 'none' 0175 %-------------------------------------------------------- 0176 xP(1).name = 'none'; 0177 xP(1).P = ons*TR; 0178 xP(1).h = 0; 0179 0180 case 'time' 0181 %-------------------------------------------------------- 0182 xP(1).name = 'time'; 0183 xP(1).P = ons*TR; 0184 xP(1).h = spm_input('polynomial order',8,'n1',1); 0185 0186 case 'other' 0187 %-------------------------------------------------------- 0188 str = ['# parameters (' Uname{1} ')']; 0189 for q = 1:spm_input(str,7,'n1',1); 0190 0191 % get names and parametric variates 0192 %------------------------------------------------ 0193 str = sprintf('parameter %d name',q); 0194 Pname = spm_input(str,7,'s'); 0195 P = spm_input(Pname,7,'r',[],[length(ons),1]); 0196 0197 % order of polynomial expansion h 0198 %------------------------------------------------ 0199 h = spm_input('polynomial order',8,'n1',1); 0200 0201 % sub-indices and inputs 0202 %------------------------------------------------ 0203 xP(q).name = Pname; 0204 xP(q).P = P(:); 0205 xP(q).h = h; 0206 0207 end 0208 end % switch 0209 0210 end % try 0211 0212 % interaction with causes (u) - 1st = main effects 0213 %---------------------------------------------------------------- 0214 u = ons.^0; 0215 for q = 1:length(xP) 0216 xP(q).i = [1, ([1:xP(q).h] + size(u,2))]; 0217 for j = 1:xP(q).h 0218 P = spm_en(xP(q).P); 0219 u = [u P.^j]; 0220 str = sprintf('%sx%s^%d',Uname{1},xP.name,j); 0221 Uname{end + 1} = str; 0222 end 0223 end 0224 0225 % orthogonalize inputs 0226 %--------------------------------------------------------------- 0227 u = pr_spm_orth(u); 0228 0229 % and scale so sum(u*dt) = number of events, if event-related 0230 %--------------------------------------------------------------- 0231 if ~any(dur) 0232 u = u/dt; 0233 end 0234 0235 % create stimulus functions (32 bin offset) 0236 %=============================================================== 0237 ton = round(ons*TR/dt) + 32; % onsets 0238 tof = round(dur*TR/dt) + ton + 1; % offset 0239 sf = sparse((k*T + 128),size(u,2)); 0240 for j = 1:length(ton) 0241 sf(ton(j),:) = sf(ton(j),:) + u(j,:); 0242 sf(tof(j),:) = sf(tof(j),:) - u(j,:); 0243 end 0244 sf = cumsum(sf); % integrate 0245 sf = sf(1:(k*T + 32),:); % stimulus 0246 0247 % place in ouputs structure 0248 %--------------------------------------------------------------- 0249 U(i).name = Uname; % - input names 0250 U(i).dt = dt; % - time bin {seconds} 0251 U(i).u = sf; % - stimulus function matrix 0252 U(i).pst = pst; % - pst (seconds) 0253 U(i).P = xP; % - parameter struct 0254 0255 end % (v)