Home > marsbar > @mardo_2 > private > pr_fmri_design.m

pr_fmri_design

PURPOSE ^

MarsBaR version of spm_fMRI design - asssembles a design for fMRI studies

SYNOPSIS ^

function [SPM] = pr_fmri_design(SPM)

DESCRIPTION ^

 MarsBaR version of spm_fMRI design - asssembles a design for fMRI studies
 FORMAT [SPM] = pr_fmri_design(SPM)

 This file is a hardly edited version of:
 @(#)spm_fMRI_design.m    2.34 Karl Friston 03/01/30
 See that (SPM2) version for comments etc

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [SPM] = pr_fmri_design(SPM)
0002 % MarsBaR version of spm_fMRI design - asssembles a design for fMRI studies
0003 % FORMAT [SPM] = pr_fmri_design(SPM)
0004 %
0005 % This file is a hardly edited version of:
0006 % @(#)spm_fMRI_design.m    2.34 Karl Friston 03/01/30
0007 % See that (SPM2) version for comments etc
0008 %
0009 % $Id$
0010   
0011 %-GUI setup
0012 %-----------------------------------------------------------------------
0013 SPMid    = spm('SFnBanner',mfilename,marsbar('ver'));
0014 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','fMRI stats model setup',0);
0015 spm_help('!ContextHelp',mfilename)
0016 
0017 % construct Design matrix {X} - cycle over sessions
0018 %=======================================================================
0019 
0020 % global parameters
0021 %-----------------------------------------------------------------------
0022 try
0023     fMRI_T     = SPM.xBF.T;
0024     fMRI_T0    = SPM.xBF.T0;
0025 catch
0026     global defaults
0027     d_fmri = mars_struct('getifthere', defaults, 'stats', 'fmri');
0028     if mars_struct('isthere', d_fmri, 't')
0029       fMRI_T  = d_fmri.t;
0030       fMRI_T0 = d_fmri.t0;
0031     else,
0032       fMRI_T  = 16;
0033       fMRI_T0 = 1;
0034     end;
0035     SPM.xBF.T  = fMRI_T;
0036     SPM.xBF.T0 = fMRI_T0;
0037 end
0038 
0039 
0040 % get nscan and RT if not in SPM
0041 %-----------------------------------------------------------------------
0042 try
0043     SPM.xY.RT;
0044 catch
0045     spm_input('Basic parameters...',1,'d',mfilename)
0046     SPM.xY.RT = spm_input('Interscan interval {secs}','+1','r',[],1);
0047 end
0048 try
0049     SPM.nscan;
0050 catch
0051         SPM.nscan = spm_input(['scans per session e.g. 64 64 64'],'+1');
0052 end
0053 
0054 % time units, dt = time bin {secs}
0055 %-----------------------------------------------------------------------
0056 SPM.xBF.dt = SPM.xY.RT/SPM.xBF.T;
0057 try
0058     SPM.xBF.UNITS;
0059 catch    
0060     str           = 'specify design in';
0061     SPM.xBF.UNITS = spm_input(str,'+1','scans|secs');
0062 end
0063 
0064 % separate specifications for non-relicated sessions
0065 %-----------------------------------------------------------------------
0066 rep     = 0;
0067 if length(SPM.nscan) > 1 & ~any(diff(SPM.nscan)) & ~isfield(SPM,'Sess')
0068     str = 'are sessions replications';
0069     rep = spm_input(str,'+1','yes|no',[1 0]);
0070 end
0071 
0072 % Get basis functions
0073 %-----------------------------------------------------------------------
0074 try
0075     bf      = SPM.xBF.bf;
0076 catch
0077     SPM.xBF = pr_spm_get_bf(SPM.xBF);
0078     bf      = SPM.xBF.bf;
0079 end
0080 
0081 % 1st or 2nd order Volterra expansion?
0082 %-----------------------------------------------------------------------
0083 try
0084     V   = SPM.xBF.Volterra;
0085 catch
0086     str = 'model interactions (Volterra)';
0087     V   = spm_input(str,'+1','y/n',[2 1]);
0088     SPM.xBF.Volterra  = V;
0089 end
0090 
0091 
0092 % get session specific design parameters
0093 %=======================================================================
0094 Xx    = [];
0095 Xb    = [];
0096 Xname = {};
0097 Bname = {};
0098 for s = 1:length(SPM.nscan)
0099 
0100     % number of scans for this session
0101     %---------------------------------------------------------------
0102     k   = SPM.nscan(s);
0103 
0104     if (s == 1) | ~rep
0105 
0106         % create convolved stimulus functions or inputs
0107         %=======================================================
0108 
0109         % Get inputs, neuronal causes or stimulus functions U
0110         %-------------------------------------------------------
0111             U = pr_spm_get_ons(SPM,s);
0112 
0113         % Convolve stimulus functions with basis functions
0114         %-------------------------------------------------------
0115         [X,Xn,Fc] = pr_spm_volterra(U,bf,V);
0116 
0117         % Resample regressors at acquisition times (32 bin offset)
0118         %-------------------------------------------------------
0119         try
0120             X = X([0:(k - 1)]*fMRI_T + fMRI_T0 + 32,:);
0121         end
0122 
0123 
0124         % get user specified regressors
0125         %=======================================================
0126         try 
0127             C     = SPM.Sess(s).C.C;
0128             Cname = SPM.Sess(s).C.name;
0129         catch
0130 
0131             % covariates - C
0132             %-----------------------------------------------
0133             str   = sprintf('Session %d',s);
0134             spm_input('Other regressors',1,'d',str)
0135             C     = [];
0136             c     = spm_input('user specified','+1','w1',0);
0137                   while size(C,2) < c
0138                      str = sprintf('regressor %i',size(C,2) + 1);
0139                       C  = [C spm_input(str,2,'e',[],[k Inf])];
0140             end
0141 
0142             % and their names - Cnames
0143             %-----------------------------------------------
0144             Cname = {};
0145             for i = 1:size(C,2)
0146                 str      = sprintf('regressor %i',i);
0147                 Cname{i} = spm_input('name of','+0','s',str);
0148             end
0149         end
0150 
0151         % append mean-corrected regressors and names
0152         %-------------------------------------------------------
0153         X      = [X spm_detrend(C)];
0154         Xn     = {Xn{:}   Cname{:}};
0155 
0156         % Confounds: Session effects
0157         %=======================================================
0158         B      = ones(k,1);
0159         Bn{1}  = sprintf('constant');
0160 
0161     end
0162 
0163     % Session structure array
0164     %---------------------------------------------------------------
0165     SPM.Sess(s).U      = U;
0166     SPM.Sess(s).C.C    = C;
0167     SPM.Sess(s).C.name = Cname;
0168     SPM.Sess(s).row    = size(Xx,1) + [1:k];
0169     SPM.Sess(s).col    = size(Xx,2) + [1:size(X,2)];
0170     SPM.Sess(s).Fc     = Fc;
0171 
0172     % Append names
0173     %---------------------------------------------------------------
0174     for i = 1:length(Xn) 
0175         Xname{end + 1} = [sprintf('Sn(%i) ',s) Xn{i}];
0176     end
0177     for i = 1:length(Bn) 
0178         Bname{end + 1} = [sprintf('Sn(%i) ',s) Bn{i}];
0179     end
0180 
0181     % append into Xx and Xb
0182     %===============================================================
0183     Xx    = blkdiag(Xx,X);
0184     Xb    = blkdiag(Xb,B);
0185 
0186 end %- for s
0187 
0188 
0189 % finished
0190 %-----------------------------------------------------------------------
0191 SPM.xX.X      = [Xx Xb];
0192 SPM.xX.iH     = [];
0193 SPM.xX.iC     = [1:size(Xx,2)];
0194 SPM.xX.iB     = [1:size(Xb,2)] + size(Xx,2);
0195 SPM.xX.iG     = [];
0196 SPM.xX.name   = {Xname{:} Bname{:}};
0197 
0198 
0199 %-End
0200 %-----------------------------------------------------------------------
0201 spm_input('!DeleteInputObj')
0202 

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