Home > marsbar > @mardo_99 > event_x_fir.m

event_x_fir

PURPOSE ^

method to return FIR design matrix columns for session

SYNOPSIS ^

function Xn = event_x_fir(D, e_spec, bin_length, bin_no, opts)

DESCRIPTION ^

 method to return FIR design matrix columns for session
 FORMAT Xn = event_x_fir(D, e_spec, bin_length, bin_no, opts)
 
 D          - design object
 e_spec     - event specification for single event
                [session no; event no]
 bin_length - bin length in seconds
 bin_no     - number of bins for FIR
 opts       - structure, containing fields with options
                'single' - if field present, gives single FIR 
                 This option removes any duration information, and
                 returns a simple per onset FIR model, where ones in the
                 design matrix corresponds to 1 event at the given
                 offset. See event_fitted_fir.m for more details.
 
 Returns
 Xn         - columns in design matrix for FIR model
 
 Note that we have a problem, in that the assumed start bin is not saved
 in the SPM99 design format, so we have to hope it has not changed from
 the current defaults.

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Xn = event_x_fir(D, e_spec, bin_length, bin_no, opts)
0002 % method to return FIR design matrix columns for session
0003 % FORMAT Xn = event_x_fir(D, e_spec, bin_length, bin_no, opts)
0004 %
0005 % D          - design object
0006 % e_spec     - event specification for single event
0007 %                [session no; event no]
0008 % bin_length - bin length in seconds
0009 % bin_no     - number of bins for FIR
0010 % opts       - structure, containing fields with options
0011 %                'single' - if field present, gives single FIR
0012 %                 This option removes any duration information, and
0013 %                 returns a simple per onset FIR model, where ones in the
0014 %                 design matrix corresponds to 1 event at the given
0015 %                 offset. See event_fitted_fir.m for more details.
0016 %
0017 % Returns
0018 % Xn         - columns in design matrix for FIR model
0019 %
0020 % Note that we have a problem, in that the assumed start bin is not saved
0021 % in the SPM99 design format, so we have to hope it has not changed from
0022 % the current defaults.
0023 %
0024 % $Id$
0025 
0026 % global parameters
0027 global fMRI_T; 
0028 global fMRI_T0; 
0029 if isempty(fMRI_T),  fMRI_T  = 16; end;
0030 if isempty(fMRI_T0), fMRI_T0 = 1;  end;
0031 
0032 if nargin < 2
0033   error('Need event specfication');
0034 end
0035 if nargin < 3
0036   bin_length = [];
0037 end
0038 if nargin < 4
0039   bin_no = [];
0040 end
0041 if nargin < 5
0042   opts = [];
0043 end
0044 
0045 s = e_spec(1);
0046 e = e_spec(2);
0047 if isempty(bin_length)
0048   bin_length = tr(D);
0049 end
0050 if isempty(bin_no)
0051   bin_no = round(25/bin_length);
0052 end
0053 
0054 SPM         = des_struct(D);
0055 Sess        = SPM.Sess{s};
0056 dt          = SPM.xX.dt;
0057 
0058 % Check dt against fMRI_T, warn if it differs
0059 recorded_fMRI_T = round(SPM.xX.RT / dt);
0060 if recorded_fMRI_T ~= fMRI_T & verbose(D)
0061   warning(sprintf([...
0062       'fMRI_T (%d) does not match recorded dt, using recorded dt (%d).\n' ...
0063       'The original fMRI_T0 has not been recorded, assuming %d.'],...
0064           fMRI_T, recorded_fMRI_T, fMRI_T0));
0065 end
0066 T           = recorded_fMRI_T;
0067 bf          = kron(eye(bin_no),ones(round(bin_length/dt),1));
0068 bf          = pr_spm_orth(bf);
0069 
0070 % Reset columns to 1 after orthogonalization
0071 BF{1}       = bf / bf(1);
0072 
0073 k           = length(Sess.row);
0074 
0075 if isfield(opts, 'single')
0076   [onsets durations] = event_onsets(D, e_spec);
0077   ons   = sparse(k*T,1);
0078   for p = 1:length(onsets)
0079     q  = round(onsets(p)*T + 1);
0080     ons(q) = 1;
0081   end
0082   SF{1} = ons(1:(k*T));
0083   if verbose(D) & any(diff(durations))
0084       warning(['Apparently there were different event durations; ' ...
0085            'single FIR model likely to be invalid']);
0086   end
0087 else
0088   SF{1}       = Sess.sf{e}(:,1);
0089 end
0090 
0091 Xn          = pr_spm_volterra(SF,BF,{'FIR'},1);
0092 
0093 % Resample design matrix {X} at acquisition times
0094 %-----------------------------------------------
0095 Xn          = Xn([0:k-1]*T + fMRI_T0,:);

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019