0001 function [X, dt] = event_regressor(D, e_spec, dur)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if nargin < 2
0017 error('Need design and event spec');
0018 end
0019 if nargin < 3
0020 dur = 0;
0021 end
0022 if ~is_fmri(D)
0023 error('Needs FMRI design');
0024 end
0025
0026 if size(e_spec, 1) == 1, e_spec = e_spec'; end
0027
0028 SPM = des_struct(D);
0029 Sess = SPM.Sess;
0030 xX = SPM.xX;
0031 dt = xX.dt;
0032 ss = e_spec(1);
0033 en = e_spec(2);
0034 bf = full(Sess{ss}.bf{en});
0035
0036 if ~dur
0037
0038 sf = 1;
0039 else
0040 sf = ones(round(dur/dt), 1);
0041 end
0042 X = [];
0043
0044 for b = 1:size(bf,2)
0045 X = [X conv(sf, bf(:,b))];
0046 end
0047
0048 return
0049
0050
0051 K{1} = struct('HChoice', 'none',...
0052 'HParam', [],...
0053 'LChoice', xX.K{ss}.LChoice,...
0054 'LParam', xX.K{ss}.LParam,...
0055 'row', 1:size(X,1),...
0056 'RT', dt);
0057 X = pr_spm_filter('apply',K,X);