Home > marsbar > @mardo_99 > apply_filter.m

apply_filter

PURPOSE ^

applies filter in design to data

SYNOPSIS ^

function Y = apply_filter(D, Y, flags)

DESCRIPTION ^

 applies filter in design to data
 FORMAT Y = apply_filter(D, Y, flags)

 D      - design, which includes a filter
 Y      - data to filter (2D matrix or marsy data object)
 flags  - string specifying one option, or cell array specifying more
          than one option, or struct with fields specifying options.
          Values for strings, cell contents or field names are
          'sessions'      - when used as struct field, value for field
                            specifies sessions to apply filter for. The
                            data size must match the length of the
                            included sessions.

 Returns
 Y      - filtered data

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Y = apply_filter(D, Y, flags)
0002 % applies filter in design to data
0003 % FORMAT Y = apply_filter(D, Y, flags)
0004 %
0005 % D      - design, which includes a filter
0006 % Y      - data to filter (2D matrix or marsy data object)
0007 % flags  - string specifying one option, or cell array specifying more
0008 %          than one option, or struct with fields specifying options.
0009 %          Values for strings, cell contents or field names are
0010 %          'sessions'      - when used as struct field, value for field
0011 %                            specifies sessions to apply filter for. The
0012 %                            data size must match the length of the
0013 %                            included sessions.
0014 %
0015 % Returns
0016 % Y      - filtered data
0017 %
0018 % $Id$
0019   
0020 if nargin < 2
0021   error('Need data to filter');
0022 end
0023 if nargin < 3
0024   flags = [];
0025 end
0026 if ~isempty(flags)
0027   if ischar(flags), flags = {flags}; end
0028   if iscell(flags)
0029     flags = cell2struct(repmat({''}, size(flags)), flags, 1);
0030   end
0031 end
0032 if ~is_fmri(D)
0033   return
0034 end
0035 if ~has_filter(D)
0036   error('This FMRI design does not contain a filter');
0037 end
0038 
0039 SPM = des_struct(D);
0040 K = SPM.xX.K;
0041 
0042 % Filtering from subset of sessions
0043 if isfield(flags, 'sessions')
0044   ss = flags.sessions;
0045   if ~isempty(ss)
0046     blk_rows = block_rows(D);
0047     if any(ss < 1 | ss > length(blk_rows))
0048       error('Sessions appear to be out of range');
0049     end
0050     K = K(ss);
0051     K{1}.row = blk_rows{ss} - blk_rows{ss}(1) + 1; 
0052   end
0053 end
0054 
0055 if isa(Y, 'marsy')  % marsy object
0056   rd = region_data(Y);
0057   for r = 1:length(rd)
0058     rd{r} = pr_spm_filter('apply', K, rd{r});
0059   end
0060   Y = region_data(Y, [], rd);
0061 else                % 2D matrix
0062   Y = pr_spm_filter('apply', K, Y);
0063 end

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