0001 function Xn = event_x_fir(D, e_spec, bin_length, bin_no, opts)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 2
0023 error('Need event specfication');
0024 end
0025 if nargin < 3
0026 bin_length = [];
0027 end
0028 if nargin < 4
0029 bin_no = [];
0030 end
0031 if nargin < 5
0032 opts = [];
0033 end
0034
0035 s = e_spec(1);
0036 e = e_spec(2);
0037 if isempty(bin_length)
0038 bin_length = tr(D);
0039 end
0040 if isempty(bin_no)
0041 bin_no = round(25/bin_length);
0042 end
0043
0044 SPM = des_struct(D);
0045
0046 xBF = SPM.xBF;
0047 xBF.name = 'Finite Impulse Response';
0048 xBF.order = bin_no;
0049 xBF.length = xBF.order*bin_length;
0050 xBF = pr_spm_get_bf(xBF);
0051
0052 U = SPM.Sess(s).U(e);
0053 k = SPM.nscan(s);
0054
0055
0056
0057
0058 if ~any(U.dur), opts.single = 1; end
0059
0060 if isfield(opts, 'single')
0061 U.u = sf_ones_ons(U, xBF, k);
0062 if verbose(D)
0063 if any(diff(U.dur))
0064 warning(['Different event durations; ' ...
0065 'single FIR model likely to be invalid']);
0066 end
0067 end
0068 else
0069 U.u = U.u(:,1);
0070 end
0071
0072 Xn = pr_spm_volterra(U,xBF.bf,1);
0073 Xn = Xn([0:(k - 1)]* xBF.T + xBF.T0 + 32,:);
0074
0075 return
0076
0077 function sf = sf_ones_ons(U, xBF, k)
0078
0079
0080 ons = U.ons;
0081 T = xBF.T;
0082 dt = xBF.dt;
0083 switch xBF.UNITS
0084 case 'scans'
0085 TR = T*dt;
0086 case 'secs'
0087 TR = 1;
0088 end
0089
0090 ton = round(ons*TR/dt) + 32;
0091 sf = sparse((k*T + 128),1);
0092 for j = 1:length(ton)
0093 sf(ton(j),:) = sf(ton(j),:) + 1;
0094 end
0095
0096 return