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. _______________________________________________________________________ Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
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 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 0043 0044 % Karl Friston 0045 % $Id: spm_get_ons.m 444 2006-02-17 19:43:17Z klaas $ 0046 0047 0048 %-GUI setup 0049 %----------------------------------------------------------------------- 0050 spm_help('!ContextHelp',mfilename) 0051 0052 % time units 0053 %----------------------------------------------------------------------- 0054 k = SPM.nscan(s); 0055 T = SPM.xBF.T; 0056 dt = SPM.xBF.dt; 0057 try 0058 UNITS = SPM.xBF.UNITS; 0059 catch 0060 UNITS = 'scans'; 0061 end 0062 switch UNITS 0063 0064 case 'scans' 0065 %---------------------------------------------------------------- 0066 TR = T*dt; 0067 0068 case 'secs' 0069 %---------------------------------------------------------------- 0070 TR = 1; 0071 end 0072 0073 % get inputs and names (try SPM.Sess(s).U first) 0074 %======================================================================= 0075 try 0076 U = SPM.Sess(s).U; 0077 v = length(U); 0078 catch 0079 0080 %-prompt string 0081 %--------------------------------------------------------------- 0082 str = sprintf('Session %d: trial specification in %s',s,UNITS); 0083 spm_input(str,1,'d') 0084 0085 U = {}; 0086 v = spm_input('number of conditions/trials',2,'w1'); 0087 end 0088 0089 % get trials 0090 %----------------------------------------------------------------------- 0091 for i = 1:v 0092 0093 % get names 0094 %--------------------------------------------------------------- 0095 try 0096 Uname = U(i).name(1); 0097 catch 0098 str = sprintf('name for condition/trial %d ?',i); 0099 Uname = {spm_input(str,3,'s',sprintf('trial %d',i))}; 0100 U(i).name = Uname; 0101 end 0102 0103 % get main [trial] effects 0104 %================================================================ 0105 0106 % onsets 0107 %--------------------------------------------------------------- 0108 try 0109 ons = U(i).ons; 0110 ons = ons(:); 0111 catch 0112 ons = []; 0113 end 0114 if ~length(ons) 0115 str = ['vector of onsets - ' Uname{1}]; 0116 ons = spm_input(str,4,'r',' ',[Inf 1]); 0117 U(i).ons = ons(:); 0118 0119 end 0120 0121 % durations 0122 %--------------------------------------------------------------- 0123 try 0124 dur = U(i).dur; 0125 dur = dur(:); 0126 catch 0127 dur = []; 0128 end 0129 if ~length(dur) 0130 str = 'duration[s] (events = 0)'; 0131 while 1 0132 dur = spm_input(str,5,'r',' ',[Inf 1]); 0133 if length(dur) == 1 0134 dur = dur*ones(size(ons)); 0135 end 0136 if length(dur) == length(ons), break, end 0137 str = sprintf('enter a scalar or [%d] vector',... 0138 length(ons)); 0139 end 0140 U(i).dur = dur; 0141 end 0142 0143 % peri-stimulus times {seconds} 0144 %--------------------------------------------------------------- 0145 pst = [1:k]*T*dt - ons(1)*TR; 0146 for j = 1:length(ons) 0147 w = [1:k]*T*dt - ons(j)*TR; 0148 v = find(w >= -1); 0149 pst(v) = w(v); 0150 end 0151 0152 0153 % add parameters x trial interactions 0154 %================================================================ 0155 0156 % get parameter stucture xP 0157 %---------------------------------------------------------------- 0158 try 0159 xP = U(i).P; 0160 Pname = xP(1).name; 0161 0162 switch Pname 0163 0164 case 'none' 0165 %------------------------------------------------ 0166 xP.name = 'none'; 0167 xP.h = 0; 0168 0169 end 0170 0171 catch 0172 0173 Pname = {'none','time','other'}; 0174 Pname = spm_input('parametric modulation',6,'b',Pname); 0175 0176 switch Pname 0177 0178 case 'none' 0179 %-------------------------------------------------------- 0180 xP(1).name = 'none'; 0181 xP(1).h = 0; 0182 0183 case 'time' 0184 %-------------------------------------------------------- 0185 xP(1).name = 'time'; 0186 xP(1).P = ons*TR; 0187 xP(1).h = spm_input('polynomial order',8,'n1',1); 0188 0189 case 'other' 0190 %-------------------------------------------------------- 0191 str = ['# parameters (' Uname{1} ')']; 0192 for q = 1:spm_input(str,7,'n1',1); 0193 0194 % get names and parametric variates 0195 %------------------------------------------------ 0196 str = sprintf('parameter %d name',q); 0197 Pname = spm_input(str,7,'s'); 0198 P = spm_input(Pname,7,'r',[],[length(ons),1]); 0199 0200 % order of polynomial expansion h 0201 %------------------------------------------------ 0202 h = spm_input('polynomial order',8,'n1',1); 0203 0204 % sub-indices and inputs 0205 %------------------------------------------------ 0206 xP(q).name = Pname; 0207 xP(q).P = P(:); 0208 xP(q).h = h; 0209 0210 end 0211 end % switch 0212 0213 end % try 0214 0215 % interaction with causes (u) - 1st = main effects 0216 %---------------------------------------------------------------- 0217 u = ons.^0; 0218 for q = 1:length(xP) 0219 xP(q).i = [1, ([1:xP(q).h] + size(u,2))]; 0220 for j = 1:xP(q).h 0221 u = [u xP(q).P.^j]; 0222 str = sprintf('%sx%s^%d',Uname{1},xP(q).name,j); 0223 Uname{end + 1} = str; 0224 end 0225 end 0226 0227 % orthogonalize inputs 0228 %--------------------------------------------------------------- 0229 u = pr_spm_orth(u); 0230 0231 % and scale so sum(u*dt) = number of events, if event-related 0232 %--------------------------------------------------------------- 0233 if ~any(dur) 0234 u = u/dt; 0235 end 0236 0237 % create stimulus functions (32 bin offset) 0238 %=============================================================== 0239 ton = round(ons*TR/dt) + 32; % onsets 0240 tof = round(dur*TR/dt) + ton + 1; % offset 0241 sf = sparse((k*T + 128),size(u,2)); 0242 ton = max(ton,1); 0243 tof = max(tof,1); 0244 for j = 1:length(ton) 0245 if numel(sf)>ton(j), 0246 sf(ton(j),:) = sf(ton(j),:) + u(j,:); 0247 end; 0248 if numel(sf)>tof(j), 0249 sf(tof(j),:) = sf(tof(j),:) - u(j,:); 0250 end; 0251 end 0252 sf = cumsum(sf); % integrate 0253 sf = sf(1:(k*T + 32),:); % stimulus 0254 0255 % place in ouputs structure 0256 %--------------------------------------------------------------- 0257 U(i).name = Uname; % - input names 0258 U(i).dt = dt; % - time bin {seconds} 0259 U(i).u = sf; % - stimulus function matrix 0260 U(i).pst = pst; % - pst (seconds) 0261 U(i).P = xP; % - parameter struct 0262 0263 end % (v)