Home > marsbar > @mardo_5 > 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: pr_fmri_design.m 607 2006-03-30 20:54:55Z matthewbrett $

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: pr_fmri_design.m 607 2006-03-30 20:54:55Z matthewbrett $
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         % and orthonalise (within trial type)
0124         %-------------------------------------------------------
0125         for i = 1:length(Fc)
0126           X(:,Fc(i).i) = pr_spm_orth(X(:,Fc(i).i));
0127         end
0128 
0129         % get user specified regressors
0130         %=======================================================
0131         try 
0132             C     = SPM.Sess(s).C.C;
0133             Cname = SPM.Sess(s).C.name;
0134         catch
0135 
0136             % covariates - C
0137             %-----------------------------------------------
0138             str   = sprintf('Session %d',s);
0139             spm_input('Other regressors',1,'d',str)
0140             C     = [];
0141             c     = spm_input('user specified','+1','w1',0);
0142                   while size(C,2) < c
0143                      str = sprintf('regressor %i',size(C,2) + 1);
0144                       C  = [C spm_input(str,2,'e',[],[k Inf])];
0145             end
0146 
0147             % and their names - Cnames
0148             %-----------------------------------------------
0149             Cname = {};
0150             for i = 1:size(C,2)
0151                 str      = sprintf('regressor %i',i);
0152                 Cname{i} = spm_input('name of','+0','s',str);
0153             end
0154         end
0155 
0156         % append mean-corrected regressors and names
0157         %-------------------------------------------------------
0158         X      = [X spm_detrend(C)];
0159         Xn     = {Xn{:}   Cname{:}};
0160 
0161         % Confounds: Session effects
0162         %=======================================================
0163         B      = ones(k,1);
0164         Bn{1}  = sprintf('constant');
0165 
0166     end
0167 
0168     % Session structure array
0169     %---------------------------------------------------------------
0170     SPM.Sess(s).U      = U;
0171     SPM.Sess(s).C.C    = C;
0172     SPM.Sess(s).C.name = Cname;
0173     SPM.Sess(s).row    = size(Xx,1) + [1:k];
0174     SPM.Sess(s).col    = size(Xx,2) + [1:size(X,2)];
0175     SPM.Sess(s).Fc     = Fc;
0176 
0177     % Append names
0178     %---------------------------------------------------------------
0179     for i = 1:length(Xn) 
0180         Xname{end + 1} = [sprintf('Sn(%i) ',s) Xn{i}];
0181     end
0182     for i = 1:length(Bn) 
0183         Bname{end + 1} = [sprintf('Sn(%i) ',s) Bn{i}];
0184     end
0185 
0186     % append into Xx and Xb
0187     %===============================================================
0188     Xx    = blkdiag(Xx,X);
0189     Xb    = blkdiag(Xb,B);
0190 
0191 end %- for s
0192 
0193 
0194 % finished
0195 %-----------------------------------------------------------------------
0196 SPM.xX.X      = [Xx Xb];
0197 SPM.xX.iH     = [];
0198 SPM.xX.iC     = [1:size(Xx,2)];
0199 SPM.xX.iB     = [1:size(Xb,2)] + size(Xx,2);
0200 SPM.xX.iG     = [];
0201 SPM.xX.name   = {Xname{:} Bname{:}};
0202 
0203 
0204 %-End
0205 %-----------------------------------------------------------------------
0206 spm_input('!DeleteInputObj')
0207 

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