0001 function D = autocorr(D, autocorr_type, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if nargin < 2
0023 error('Need autocorr type');
0024 end
0025
0026 if ~is_fmri(D)
0027 warning('Can only set autocorrelation for FMRI design types');
0028 return
0029 end
0030
0031
0032 v_f = verbose(D);
0033 SPM = des_struct(D);
0034 nscan = SPM.nscan;
0035
0036 SPM.xVi.cov_calc = 'summary';
0037
0038 switch lower(autocorr_type)
0039 case 'fmristat'
0040
0041 if nargin < 3, varargin{1} = 1; end
0042 cVi = varargin{1};
0043 if prod(size(cVi)) > 1
0044 error('Expecting scalar for fmristat order');
0045 end
0046 SPM.xVi.Vi = struct('type', 'fmristat', 'order', cVi);
0047 cVi = sprintf('fmristat AR(%d)',cVi);
0048 f2cl = 'V';
0049
0050 case 'spm'
0051
0052 if nargin < 3, varargin{1} = 0.2; end
0053 if nargin < 4, varargin{2} = 1; end
0054 cVi = varargin{1};
0055 if any(cVi > 1 | cVi < 0)
0056 error('Rho estimates should be > 0 and < 1');
0057 end
0058 SPM.xVi.Vi = pr_spm_ce(nscan, cVi);
0059 cVi = sprintf('AR(%0.1f)',cVi(1));
0060 f2cl = 'V';
0061 if varargin{2}
0062 SPM.xVi.cov_calc = 'vox';
0063 end
0064
0065 case 'none'
0066
0067
0068 SPM.xVi.V = speye(sum(nscan));
0069 cVi = 'i.i.d';
0070 f2cl = 'Vi';
0071
0072 otherwise
0073 error(['Eccentric autocorr type ' autocorr_type]);
0074 end
0075
0076
0077
0078
0079
0080 if isfield(SPM.xVi, f2cl)
0081 SPM.xVi = rmfield(SPM.xVi, f2cl);
0082 if v_f, fprintf('Clearing previous %s matrix\n', f2cl); end
0083 end
0084
0085
0086
0087 if isfield(SPM.xX, 'W')
0088 SPM.xX = rmfield(SPM.xX, 'W');
0089 if v_f, fprintf('Clearing previous W matrix\n'); end
0090 end
0091
0092
0093 SPM.xVi.form = cVi;
0094 xsDes = struct('Serial_correlations', SPM.xVi.form);
0095 SPM.xsDes = mars_struct('ffillmerge', SPM.xsDes, xsDes);
0096
0097
0098 D = des_struct(D,SPM);