Removes low frequency confounds X0 FORMAT [Y] = pr_spm_filter(K,Y) FORMAT [K] = pr_spm_filter(K) K - filter matrix or: K(s) - struct array containing partition-specific specifications K(s).RT - observation interval in seconds K(s).row - row of Y constituting block/partition s K(s).HParam - cut-off period in seconds K(s).X0 - low frequencies to be removed (DCT) Y - data matrix K - filter structure Y - filtered data ___________________________________________________________________________ spm_filter implements high-pass filtering in an efficient way by using the residual forming matrix of X0 - low frequency confounds .spm_filter also configures the filter structure in accord with the specification fields if called with one argument ___________________________________________________________________________ Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0001 function [argout] = pr_spm_filter(K,Y) 0002 % Removes low frequency confounds X0 0003 % FORMAT [Y] = pr_spm_filter(K,Y) 0004 % FORMAT [K] = pr_spm_filter(K) 0005 % 0006 % K - filter matrix or: 0007 % K(s) - struct array containing partition-specific specifications 0008 % 0009 % K(s).RT - observation interval in seconds 0010 % K(s).row - row of Y constituting block/partition s 0011 % K(s).HParam - cut-off period in seconds 0012 % 0013 % K(s).X0 - low frequencies to be removed (DCT) 0014 % 0015 % Y - data matrix 0016 % 0017 % K - filter structure 0018 % Y - filtered data 0019 %___________________________________________________________________________ 0020 % 0021 % spm_filter implements high-pass filtering in an efficient way by 0022 % using the residual forming matrix of X0 - low frequency confounds 0023 %.spm_filter also configures the filter structure in accord with the 0024 % specification fields if called with one argument 0025 %___________________________________________________________________________ 0026 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 0027 0028 % Karl Friston 0029 % $Id: spm_filter.m 184 2005-05-31 13:23:32Z john $ 0030 0031 0032 0033 % set or apply 0034 %--------------------------------------------------------------------------- 0035 if nargin == 1 && isstruct(K) 0036 0037 % set K.X0 0038 %------------------------------------------------------------------- 0039 for s = 1:length(K) 0040 0041 % make high pass filter 0042 %----------------------------------------------------------- 0043 k = length(K(s).row); 0044 n = fix(2*(k*K(s).RT)/K(s).HParam + 1); 0045 X0 = spm_dctmtx(k,n); 0046 K(s).X0 = X0(:,2:end); 0047 end 0048 0049 % return structure 0050 %------------------------------------------------------------------- 0051 argout = K; 0052 0053 else 0054 % apply 0055 %------------------------------------------------------------------- 0056 if isstruct(K) 0057 0058 % ensure requisite feilds are present 0059 %----------------------------------------------------------- 0060 if ~isfield(K(1),'X0') 0061 K = pr_spm_filter(K); 0062 end 0063 0064 for s = 1:length(K) 0065 0066 % select data 0067 %--------------------------------------------------- 0068 y = Y(K(s).row,:); 0069 0070 % apply high pass filter 0071 %--------------------------------------------------- 0072 y = y - K(s).X0*(K(s).X0'*y); 0073 0074 % reset filtered data in Y 0075 %--------------------------------------------------- 0076 Y(K(s).row,:) = y; 0077 0078 end 0079 0080 % K is simply a filter matrix 0081 %------------------------------------------------------------------- 0082 else 0083 Y = K*Y; 0084 end 0085 0086 % return filtered data 0087 %------------------------------------------------------------------- 0088 %if any(~isfinite(Y)), warning('Found non-finite values in Y (could be the data).'); end; 0089 argout = Y; 0090 end 0091