FILTFILT overrides the filtfilt function for analysis objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: FILTFILT overrides the filtfilt function for analysis objects. Applies the input digital IIR filter to the input analysis object forwards and backwards. If the input analysis object contains a time-series (tsdata) then the filter is applied using the normal recursion algorithm. The output analysis object contains a tsdata object. If the input analysis object contains a frequency-series (fsdata) then the response of the filter is computed and then multiplied with the input frequency series. The output analysis object contains a frequency series. CALL: >> [b, filt] = filtfilt(a,pl) >> b = filtfilt(a,pl) INPUTS: pl - a parameter list a - input analysis object OUTPUTS: filt - a copy of the input filter object with the history values filled in. b - output analysis object containing the filtered data. PARAMETERS: filter - the filter object to use to filter the data M-FILE INFO: Get information about this methods by calling >> ao.getInfo('filtfilt') Get information about a specified set-plist by calling: >> ao.getInfo('filtfilt', 'None') VERSION: $Id: filtfilt.m,v 1.27 2008/09/05 11:05:29 ingo Exp $ HISTORY: 11-02-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % FILTFILT overrides the filtfilt function for analysis objects. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: FILTFILT overrides the filtfilt function for analysis objects. 0005 % Applies the input digital IIR filter to the input analysis object 0006 % forwards and backwards. If the input analysis object contains a 0007 % time-series (tsdata) then the filter is applied using the normal 0008 % recursion algorithm. The output analysis object contains a tsdata 0009 % object. 0010 % 0011 % If the input analysis object contains a frequency-series (fsdata) 0012 % then the response of the filter is computed and then multiplied 0013 % with the input frequency series. The output analysis object 0014 % contains a frequency series. 0015 % 0016 % CALL: >> [b, filt] = filtfilt(a,pl) 0017 % >> b = filtfilt(a,pl) 0018 % 0019 % INPUTS: pl - a parameter list 0020 % a - input analysis object 0021 % 0022 % OUTPUTS: filt - a copy of the input filter object with the 0023 % history values filled in. 0024 % b - output analysis object containing the filtered data. 0025 % 0026 % PARAMETERS: filter - the filter object to use to filter the data 0027 % 0028 % M-FILE INFO: Get information about this methods by calling 0029 % >> ao.getInfo('filtfilt') 0030 % 0031 % Get information about a specified set-plist by calling: 0032 % >> ao.getInfo('filtfilt', 'None') 0033 % 0034 % VERSION: $Id: filtfilt.m,v 1.27 2008/09/05 11:05:29 ingo Exp $ 0035 % 0036 % HISTORY: 11-02-07 M Hewitson 0037 % Creation 0038 % 0039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0040 0041 function varargout = filtfilt(varargin) 0042 0043 % Check if this is a call for parameters 0044 if utils.helper.isinfocall(varargin{:}) 0045 varargout{1} = getInfo(varargin{3}); 0046 return 0047 end 0048 0049 import utils.const.* 0050 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0051 0052 % Collect input variable names 0053 in_names = cell(size(varargin)); 0054 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0055 0056 % Collect all AOs and plists 0057 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0058 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names); 0059 [fobj, f_invars] = utils.helper.collect_objects(varargin(:), 'ltpda_filter', in_names); 0060 0061 % Make copies or handles to inputs 0062 bs = copy(as, nargout); 0063 0064 % combine plists 0065 pl = combine(pl, getDefaultPlist()); 0066 0067 if isempty(fobj) 0068 fobj = find(pl, 'filter'); 0069 f_invars{1} = class(fobj); 0070 end 0071 0072 % check inputs 0073 if ~isa(fobj, 'miir') && ~isa(fobj, 'mfir') 0074 error('### the filter input should be an miir/mfir object.'); 0075 end 0076 0077 % Now copy the filter so we can change it 0078 fobj = copy(fobj, 1); 0079 0080 % Loop over AOs 0081 for j=1:numel(bs) 0082 %--------- Time-series filter 0083 if isa(bs(j).data, 'tsdata') 0084 fs = bs(j).data.fs; 0085 if fs ~= fobj.fs 0086 warning('!!! Filter is designed for a different sample rate of data.'); 0087 % Adjust/redesign if this is a standard filter 0088 fobj = redesign(fobj, fs); 0089 end 0090 % apply filter 0091 bs(j).data.y = filtfilt(fobj.a, fobj.b, bs(j).data.y); 0092 % add history 0093 bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist); 0094 % name for this object 0095 bs(j).setName(sprintf('%s(%s)', f_invars{1}, ao_invars{j}), 'internal'); 0096 elseif isa(d, 'fsdata') 0097 %--------- Frequency-series filter 0098 error('### I don''t work yet. Please code me up.'); 0099 else 0100 error('### unknown data type.'); 0101 end 0102 end 0103 0104 % Set outputs 0105 if nargout == 1 0106 varargout{1} = bs; 0107 elseif nargout == 2 0108 varargout{1} = bs; 0109 varargout{2} = fobj; 0110 elseif nargout > 2 0111 error('### wrong number of output arguments.'); 0112 end 0113 end 0114 0115 %-------------------------------------------------------------------------- 0116 % Get Info Object 0117 %-------------------------------------------------------------------------- 0118 function ii = getInfo(varargin) 0119 if nargin == 1 && strcmpi(varargin{1}, 'None') 0120 sets = {}; 0121 pls = []; 0122 else 0123 sets = {'Default'}; 0124 pls = getDefaultPlist; 0125 end 0126 % Build info object 0127 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: filtfilt.m,v 1.27 2008/09/05 11:05:29 ingo Exp $', sets, pls); 0128 end 0129 0130 %-------------------------------------------------------------------------- 0131 % Get Default Plist 0132 %-------------------------------------------------------------------------- 0133 function pl_default = getDefaultPlist() 0134 pl_default = plist('filter', ''); 0135 end 0136 0137