0001 function [SPM] = pr_fmri_design(SPM)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 SPMid = spm('SFnBanner',mfilename,marsbar('ver'));
0014 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','fMRI stats model setup',0);
0015 spm_help('!ContextHelp',mfilename)
0016
0017
0018
0019
0020
0021
0022 STOC = 0;
0023
0024
0025
0026 global fMRI_T;
0027 global fMRI_T0;
0028 if isempty(fMRI_T), fMRI_T = 16; end;
0029 if isempty(fMRI_T0), fMRI_T0 = 1; end;
0030
0031
0032
0033 spm_input('Basic parameters...',1,'d',mfilename)
0034 RT = spm_input('Interscan interval {secs}','+1','r',[],1);
0035 nscan = spm_input(['scans per session e.g. 64 64 64'],'+1');
0036 STOC = 1;
0037 nsess = length(nscan);
0038 dt = RT/fMRI_T;
0039
0040
0041
0042 rep = 0;
0043 tim = 0;
0044 if nsess > 1
0045 str = 'are conditions replicated';
0046 rep = spm_input(str,'+1','yes|no',[1 0])
0047 if rep & ~any(nscan - nscan(1))
0048 str = ['are timing/parameters the same'];
0049 tim = spm_input(str,'+1','yes|no',[1 0]);
0050 end
0051 end
0052 Xx = [];
0053 Xb = [];
0054 Xname = {};
0055 Bname = {};
0056 Sess = {};
0057 for s = 1:nsess
0058
0059
0060
0061 if tim
0062 Fstr = 'All sessions';
0063 else
0064 Fstr = sprintf('Session %d/%d',s,nsess);
0065 end
0066
0067
0068
0069 k = nscan(s);
0070
0071
0072
0073 if (s == 1) | ~rep
0074
0075 [SF,Cname,Pv,Pname,DSstr] = ...
0076 pr_spm_get_ons(k,fMRI_T,dt,STOC,Fstr,[],[],s);
0077 ntrial = size(SF,2);
0078
0079 elseif ~tim
0080
0081 [SF,Cname,Pv,Pname,DSstr] = ...
0082 pr_spm_get_ons(k,fMRI_T,dt,STOC,Fstr,ntrial,Cname,s);
0083 end
0084
0085
0086
0087 if (s == 1) | ~rep
0088
0089
0090
0091 [BF BFstr] = pr_spm_get_bf(Cname,fMRI_T,dt,Fstr,s);
0092 end
0093
0094
0095
0096
0097
0098
0099 if (s == 1) | ~tim
0100
0101
0102
0103
0104 spm_help('!ContextHelp',mfilename)
0105 spm_input('Design matrix options...',1,'d',mfilename)
0106
0107 if ~ntrial
0108
0109
0110
0111 ONS = {};
0112 PST = {};
0113 X = [];
0114 Xn = {};
0115 IND = {};
0116 name = {};
0117
0118 else
0119
0120
0121
0122 for i = 1:ntrial
0123 on = find(SF{i}(:,1))*dt;
0124 pst = [1:k]*RT - on(1);
0125 for j = 1:length(on)
0126 u = [1:k]*RT - on(j);
0127 v = find(u >= -1);
0128 pst(v) = u(v);
0129 end
0130 ONS{i} = on;
0131 PST{i} = pst;
0132 end
0133
0134
0135
0136
0137 str = 'interactions among trials (Volterra)';
0138 if spm_input(str,'+1','y/n',[1 0])
0139
0140 [X Xn IND BF name] = pr_spm_volterra(SF,BF,Cname,2);
0141
0142 else
0143 [X Xn IND BF name] = pr_spm_volterra(SF,BF,Cname,1);
0144 end
0145
0146
0147
0148
0149 X = X([0:k-1]*fMRI_T + fMRI_T0,:);
0150 end
0151
0152
0153
0154
0155 spm_input('Other regressors',1,'d',Fstr)
0156 D = [];
0157 c = spm_input('user specified regressors','+1','w1',0);
0158 while size(D,2) < c
0159 str = sprintf('regressor %i',size(D,2) + 1);
0160 D = [D spm_input(str,2,'e',[],[k Inf])];
0161 end
0162 if c & length(DSstr)
0163 DSstr = [DSstr '& user specified covariates '];
0164 elseif c
0165 DSstr = 'User specified covariates ';
0166 end
0167
0168
0169
0170 for i = 1:size(D,2)
0171 X = [X D(:,i)];
0172 str = sprintf('regressor: %i',i);
0173 Xn{end + 1} = spm_input(['name of ' str],'+0','s',str);
0174 end
0175
0176
0177
0178
0179
0180 B = ones(k,1);
0181 Bn{1} = sprintf('constant');
0182
0183 end
0184
0185
0186
0187 Sess{s}.BFstr = BFstr;
0188 Sess{s}.DSstr = DSstr;
0189 Sess{s}.rep = tim;
0190 Sess{s}.row = size(Xx,1) + [1:k];
0191 Sess{s}.col = size(Xx,2) + [1:size(X,2)];
0192 Sess{s}.name = name;
0193 Sess{s}.ind = IND;
0194 Sess{s}.bf = BF;
0195 Sess{s}.sf = SF;
0196 Sess{s}.pst = PST;
0197 Sess{s}.ons = ONS;
0198 Sess{s}.Pv = Pv;
0199 Sess{s}.Pname = Pname;
0200
0201
0202
0203 q = length(Xname);
0204 for i = 1:length(Xn)
0205 Xname{q + i} = [sprintf('Sn(%i) ',s) Xn{i}];
0206 end
0207 q = length(Bname);
0208 for i = 1:length(Bn)
0209 Bname{q + i} = [sprintf('Sn(%i) ',s) Bn{i}];
0210 end
0211
0212
0213
0214 [x y] = size(Xx);
0215 [i j] = size(X);
0216 Xx(([1:i] + x),([1:j] + y)) = spm_detrend(X);
0217 [x y] = size(Xb);
0218 [i j] = size(B);
0219 Xb(([1:i] + x),([1:j] + y)) = B;
0220
0221 end
0222
0223
0224
0225 xX = struct( 'X', [Xx Xb],...
0226 'dt', dt,...
0227 'RT', RT,...
0228 'iH', [],...
0229 'iC', [1:size(Xx,2)],...
0230 'iB', [1:size(Xb,2)] + size(Xx,2),...
0231 'iG', [],...
0232 'Xnames', {[Xname Bname]});
0233
0234
0235
0236
0237 fprintf('\t%-32s: ','Saving fMRI design')
0238 SPM = struct('SPMid', SPMid, ...
0239 'xX', xX,...
0240 'Sess', {Sess});
0241 fprintf('%30s\n\n','...saved')
0242 spm_input('!DeleteInputObj')
0243