convolves regressors with SPM canonical HRF rvals = frmi_convolve_regress(ons,dur,amp,TR,dt,k) The core of this code is copied from spm_get_ons.m in the SPM5 distribution Assumes onsets and durations are given in seconds dt=1/16 s by default 2009.11.05 FB - adapted from fmri_spm_generate_regress, w/c was adapted from code written by PJ for autobio, which was adapted from spm_get_ons.m
0001 function rvals = fmri_convolve_regress(ons, dur, amp, TR, dt, k) 0002 0003 % convolves regressors with SPM canonical HRF 0004 % 0005 % rvals = frmi_convolve_regress(ons,dur,amp,TR,dt,k) 0006 % 0007 % The core of this code is copied from 0008 % spm_get_ons.m in the SPM5 distribution 0009 % Assumes onsets and durations are given in seconds 0010 % dt=1/16 s by default 0011 % 0012 % 2009.11.05 FB - adapted from fmri_spm_generate_regress, w/c was adapted 0013 % from code written by PJ for autobio, which was adapted from spm_get_ons.m 0014 0015 TR = 1/TR; % TR - this needs to be pulled from the protocol info 0016 dt = 1/dt; % This needs to be pulled from the fMRI specs 0017 T = 1/dt; 0018 0019 % create stimulus functions (32 bin offset) 0020 %=============================================================== 0021 ton = round(ons*TR/dt) + 32; % onsets 0022 tof = round(dur*TR/dt) + ton + 1; % offset 0023 sf = sparse((k*T + 128),1); 0024 ton = max(ton,1); 0025 tof = max(tof,1); 0026 for j = 1:length(ton) 0027 if numel(sf)>ton(j), 0028 sf(ton(j),:) = sf(ton(j),:) + amp(j); 0029 end; 0030 if numel(sf)>tof(j), 0031 sf(tof(j),:) = sf(tof(j),:) - amp(j); 0032 end; 0033 end 0034 sf = cumsum(sf); % integrate 0035 sf = sf(1:(k*T + 32),:); % stimulus 0036 0037 % Convolve with the desired basis function 0038 rvals = conv(full(sf), spm_hrf(dt/TR)); 0039 0040 % Resample onto timescale of scans 0041 rvals = rvals([0:(k-1)]*T+1+32);