Home > marsbar > @mardo_2 > 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  [TR]
 bin_no     - number of bins for FIR [25 seconds / bin_length]
 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

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

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  [TR]
0009 % bin_no     - number of bins for FIR [25 seconds / bin_length]
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 % $Id$
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 % If all the durations are zero, the model is already single.  The stick
0056 % function values have been set to 1/dt though, which is confusing, so
0057 % we'll reset the stick functions to have 1s
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 % Return onsets with only 1s in start time bin for each event
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

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