help > How is the band-pass filter is done in SPM and how can I use the spm_filter module for doing this?
Oct 11, 2018  07:10 PM | hmar
How is the band-pass filter is done in SPM and how can I use the spm_filter module for doing this?
Hello,

I would like to know how the band-pass filter is done in packages like SPM and if I could use that module/script independently?  

I have been reading over the internet, that one can use spm_filter, but then when I looked at its script in MATLAB (edit spm_filter), I figured this filter is a high-pass filter and removes the low frequency components.

Here is what I see:  
function varargout = spm_filter(K,Y)
% Removes low frequency confounds X0
% FORMAT [Y] = spm_filter(K,Y)
% FORMAT [K] = 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) 1999-2015 Wellcome Trust Centre for Neuroimaging
% Karl Friston
% $Id: spm_filter.m 6416 2015-04-21 15:34:10Z guillaume $
%-Configure filter
%==========================================================================
if nargin == 1 && isstruct(K)
% set K.X0
%----------------------------------------------------------------------
for s = 1:length(K)
% make high pass filter
%------------------------------------------------------------------
k = length(K(s).row);
n = fix(2*(k*K(s).RT)/K(s).HParam + 1);
X0 = spm_dctmtx(k,n);
K(s).X0 = X0(:,2:end);
end
% return filter structure
%----------------------------------------------------------------------
varargout = { K };
%-Apply filter
%==========================================================================
else
% K is a filter structure
%----------------------------------------------------------------------
if isstruct(K)
% ensure requisite fields are present
%------------------------------------------------------------------
if ~isfield(K(1),'X0')
K = spm_filter(K);
end
if numel(K) == 1 && length(K.row) == size(Y,1)
% apply high pass filter
%--------------------------------------------------------------
Y = Y - K.X0*(K.X0'*Y);
else
for s = 1:length(K)
% select data
%----------------------------------------------------------
y = Y(K(s).row,:);
% apply high pass filter
%----------------------------------------------------------
y = y - K(s).X0*(K(s).X0'*y);
% reset filtered data in Y
%----------------------------------------------------------
Y(K(s).row,:) = y;
end
end
% K is simply a filter matrix
%----------------------------------------------------------------------
else
Y = K * Y;
end
% return filtered data
%----------------------------------------------------------------------
varargout = { Y };
end

I would like to know how the band-pass filtering is typically done in MATLAB using SPM for resting state fMRI.  I would be grateful if you could assist me figuring this out.

I further would like to know what is I have time series from, say, 4 ROIs and want to band-pass these signals.  How could I implement this script to do that.  

Thanks a lot