Home > marsbar > @mardo_5 > private > pr_spm_volterra.m

pr_spm_volterra

PURPOSE ^

generalized convolution of inputs (U) with basis set (bf)

SYNOPSIS ^

function [X,Xname,Fc] = pr_spm_volterra(U,bf,V)

DESCRIPTION ^

 generalized convolution of inputs (U) with basis set (bf)
 FORMAT [X,Xname,Fc] = pr_spm_volterra(U,bf,V);
 U          -  input structure array
 bf         -  Basis functions
 V          -  [1 or 2] order of Volterra expansion [default = 1]

 X          -  Design Matrix
 Xname      -  names of regressors [columns] in X
 Fc(j).i    -  indices pertaining to input i (and interactions)
 Fc(j).name -  names pertaining to input i   (and interactions)
___________________________________________________________________________

 For first order expansions spm_Volterra simply convolves the causes
 (e.g. stick functions) in U.u by the basis functions in bf to create
 a design matrix X.  For second order expansions new entries appear
 in ind, bf and name that correspond to the interaction among the
 orginal causes. The basis functions for these efects are two dimensional
 and are used to assemble the second order kernel in spm_graph.m.
 Second order effects are computed for only the first column of U.u.
___________________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [X,Xname,Fc] = pr_spm_volterra(U,bf,V)
0002 % generalized convolution of inputs (U) with basis set (bf)
0003 % FORMAT [X,Xname,Fc] = pr_spm_volterra(U,bf,V);
0004 % U          -  input structure array
0005 % bf         -  Basis functions
0006 % V          -  [1 or 2] order of Volterra expansion [default = 1]
0007 %
0008 % X          -  Design Matrix
0009 % Xname      -  names of regressors [columns] in X
0010 % Fc(j).i    -  indices pertaining to input i (and interactions)
0011 % Fc(j).name -  names pertaining to input i   (and interactions)
0012 %___________________________________________________________________________
0013 %
0014 % For first order expansions spm_Volterra simply convolves the causes
0015 % (e.g. stick functions) in U.u by the basis functions in bf to create
0016 % a design matrix X.  For second order expansions new entries appear
0017 % in ind, bf and name that correspond to the interaction among the
0018 % orginal causes. The basis functions for these efects are two dimensional
0019 % and are used to assemble the second order kernel in spm_graph.m.
0020 % Second order effects are computed for only the first column of U.u.
0021 %___________________________________________________________________________
0022 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0023 
0024 % Karl Friston
0025 % $Id: spm_Volterra.m 112 2005-05-04 18:20:52Z john $
0026 
0027 
0028 
0029 % 1st order terms
0030 %---------------------------------------------------------------------------
0031 if nargin == 2, V = 1; end
0032 
0033 % Construct X
0034 %===========================================================================
0035 
0036 % 1st order terms
0037 %---------------------------------------------------------------------------
0038 X     = [];
0039 Xname = {};
0040 ind   = {};
0041 Uname = {};
0042 Fc    = {};
0043 for i = 1:length(U)
0044     ind   = [];
0045     for k = 1:size(U(i).u,2)
0046     for p = 1:size(bf,2)
0047         x      = U(i).u(:,k);
0048         d      = 1:length(x);
0049         x      = conv(full(x),bf(:,p));
0050         x      = x(d);
0051         X      = [X x];
0052 
0053         % indices and regressor names
0054         %-----------------------------------------------------------
0055         str            = sprintf('%s*bf(%i)',U(i).name{k},p);
0056         Xname{end + 1} = str;
0057         ind(end + 1)   = size(X,2);
0058     end
0059     end
0060     Fc(end + 1).i = ind;
0061     Fc(end).name  = U(i).name{1};
0062 end
0063 
0064 % return if first order
0065 %---------------------------------------------------------------------------
0066 if V == 1, return, end
0067 
0068 % 2nd order terms
0069 %---------------------------------------------------------------------------
0070 for i = 1:length(U) 
0071 for j = i:length(U)
0072     ind   = [];
0073     for p = 1:size(bf,2)
0074     for q = 1:size(bf,2)
0075         x      = U(i).u(:,1);
0076         y      = U(j).u(:,1);
0077         x      = conv(full(x),bf(:,p));
0078         y      = conv(full(y),bf(:,q));
0079         x      = x(d);
0080         y      = y(d);
0081         X      = [X x.*y];
0082 
0083         % indices and regressor names
0084         %-----------------------------------------------------------
0085         str            = sprintf('%s*bf(%i)x%s*bf(%i)',...
0086                           U(i).name{1},p,...
0087                           U(j).name{1},q);
0088         Xname{end + 1} = str;
0089         ind(end + 1)   = size(X,2);
0090     end
0091     end
0092     Fc(end + 1).i = ind;
0093     Fc(end).name  = [U(i).name{1} 'x' U(j).name{1}];
0094 end
0095 end

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