fills in basis function structure FORMAT [xBF] = spm_get_bf(xBF); xBF.dt - time bin length {seconds} xBF.name - description of basis functions specified xBF.length - window length (secs) xBF.order - order xBF.bf - Matrix of basis functions xBF.name 'hrf' 'hrf (with time derivative)' 'hrf (with time and dispersion derivatives)' 'Fourier set' 'Fourier set (Hanning)' 'Gamma functions' 'Finite Impulse Response'}; (any other specifiaction will default to hrf) _______________________________________________________________________ spm_get_bf prompts for basis functions to model event or epoch-related responses. The basis functions returned are unitary and orthonormal when defined as a function of peri-stimulus time in time-bins. It is at this point that the distinction between event and epoch-related responses enters. _______________________________________________________________________ @(#)spm_get_bf.m 2.22 Karl Friston 02/04/19
0001 function [xBF] = pr_spm_get_bf(xBF) 0002 % fills in basis function structure 0003 % FORMAT [xBF] = spm_get_bf(xBF); 0004 % 0005 % xBF.dt - time bin length {seconds} 0006 % xBF.name - description of basis functions specified 0007 % xBF.length - window length (secs) 0008 % xBF.order - order 0009 % xBF.bf - Matrix of basis functions 0010 % 0011 % xBF.name 'hrf' 0012 % 'hrf (with time derivative)' 0013 % 'hrf (with time and dispersion derivatives)' 0014 % 'Fourier set' 0015 % 'Fourier set (Hanning)' 0016 % 'Gamma functions' 0017 % 'Finite Impulse Response'}; 0018 % 0019 % (any other specifiaction will default to hrf) 0020 %_______________________________________________________________________ 0021 % 0022 % spm_get_bf prompts for basis functions to model event or epoch-related 0023 % responses. The basis functions returned are unitary and orthonormal 0024 % when defined as a function of peri-stimulus time in time-bins. 0025 % It is at this point that the distinction between event and epoch-related 0026 % responses enters. 0027 %_______________________________________________________________________ 0028 % @(#)spm_get_bf.m 2.22 Karl Friston 02/04/19 0029 0030 %-GUI setup 0031 %----------------------------------------------------------------------- 0032 spm_help('!ContextHelp',mfilename) 0033 0034 % length of time bin 0035 %----------------------------------------------------------------------- 0036 if ~nargin 0037 str = 'time bin for basis functions {secs}'; 0038 xBF.dt = spm_input(str,'+1','r',1/16,1); 0039 end 0040 dt = xBF.dt; 0041 0042 0043 % assemble basis functions 0044 %======================================================================= 0045 0046 % model event-related responses 0047 %----------------------------------------------------------------------- 0048 if ~isfield(xBF,'name') 0049 spm_input('Hemodynamic Basis functions...',1,'d') 0050 Ctype = { 0051 'hrf',... 0052 'hrf (with time derivative)',... 0053 'hrf (with time and dispersion derivatives)',... 0054 'Fourier set',... 0055 'Fourier set (Hanning)',... 0056 'Gamma functions',... 0057 'Finite Impulse Response'}; 0058 str = 'Select basis set'; 0059 Sel = spm_input(str,2,'m',Ctype); 0060 xBF.name = Ctype{Sel}; 0061 end 0062 0063 % get order and length parameters 0064 %----------------------------------------------------------------------- 0065 switch xBF.name 0066 0067 case { 'Fourier set','Fourier set (Hanning)',... 0068 'Gamma functions','Finite Impulse Response'} 0069 %--------------------------------------------------------------- 0070 try, l = xBF.length; 0071 catch, l = spm_input('window length {secs}',3,'e',32); 0072 xBF.length = l; 0073 end 0074 try, h = xBF.order; 0075 catch, h = spm_input('order',4,'e',4); 0076 xBF.order = h; 0077 end 0078 end 0079 0080 0081 0082 % create basis functions 0083 %----------------------------------------------------------------------- 0084 switch xBF.name 0085 0086 case {'Fourier set','Fourier set (Hanning)'} 0087 %--------------------------------------------------------------- 0088 pst = [0:dt:l]'; 0089 pst = pst/max(pst); 0090 0091 % hanning window 0092 %--------------------------------------------------------------- 0093 if strcmp(xBF.name,'Fourier set (Hanning)') 0094 g = (1 - cos(2*pi*pst))/2; 0095 else 0096 g = ones(size(pst)); 0097 end 0098 0099 % zeroth and higher Fourier terms 0100 %--------------------------------------------------------------- 0101 bf = g; 0102 for i = 1:h 0103 bf = [bf g.*sin(i*2*pi*pst)]; 0104 bf = [bf g.*cos(i*2*pi*pst)]; 0105 end 0106 0107 case {'Gamma functions'} 0108 %--------------------------------------------------------------- 0109 pst = [0:dt:l]'; 0110 bf = spm_gamma_bf(pst,h); 0111 0112 case {'Finite Impulse Response'} 0113 %--------------------------------------------------------------- 0114 bin = l/h; 0115 bf = kron(eye(h),ones(round(bin/dt),1)); 0116 0117 case {'NONE'} % innovation from SPM5 0118 %--------------------------------------------------------------- 0119 bf = 1; 0120 0121 otherwise 0122 0123 % canonical hemodynaic response function 0124 %--------------------------------------------------------------- 0125 [bf p] = pr_spm_hrf(dt); 0126 0127 % add time derivative 0128 %--------------------------------------------------------------- 0129 if findstr(xBF.name,'time') 0130 0131 dp = 1; 0132 p(6) = p(6) + dp; 0133 D = (bf(:,1) - pr_spm_hrf(dt,p))/dp; 0134 bf = [bf D(:)]; 0135 p(6) = p(6) - dp; 0136 0137 % add dispersion derivative 0138 %-------------------------------------------------------- 0139 if findstr(xBF.name,'dispersion') 0140 0141 dp = 0.01; 0142 p(3) = p(3) + dp; 0143 D = (bf(:,1) - pr_spm_hrf(dt,p))/dp; 0144 bf = [bf D(:)]; 0145 end 0146 end 0147 0148 % length and order 0149 %--------------------------------------------------------------- 0150 xBF.length = size(bf,1)*dt; 0151 xBF.order = size(bf,2); 0152 0153 end 0154 0155 0156 % Orthogonalize and fill in basis function structure 0157 %------------------------------------------------------------------------ 0158 xBF.bf = pr_spm_orth(bf); 0159 0160 0161 %======================================================================= 0162 %- S U B - F U N C T I O N S 0163 %======================================================================= 0164 0165 % compute Gamma functions functions 0166 %----------------------------------------------------------------------- 0167 function bf = spm_gamma_bf(u,h) 0168 % returns basis functions used for Volterra expansion 0169 % FORMAT bf = spm_gamma_bf(u,h); 0170 % u - times {seconds} 0171 % h - order 0172 % bf - basis functions (mixture of Gammas) 0173 %_______________________________________________________________________ 0174 u = u(:); 0175 bf = []; 0176 for i = 2:(1 + h) 0177 m = 2^i; 0178 s = sqrt(m); 0179 bf = [bf pr_spm_gpdf(u,(m/s)^2,m/s^2)]; 0180 end