Home > classes > @ao > filter.m

filter

PURPOSE ^

FILTER overrides the filter function for analysis objects.

SYNOPSIS ^

function varargout = filter(varargin)

DESCRIPTION ^

 FILTER overrides the filter function for analysis objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: FILTER overrides the filter function for analysis objects.
              Applies the input digital IIR/FIR filter to the input analysis
              object. 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] = filter(a,pl)
              >> [b, filt] = filter(a,filt,pl)
              >> b = filter(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('filter')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('filter', 'None')

 VERSION:     $Id: filter.m,v 1.40 2008/09/05 11:05:29 ingo Exp $

 HISTORY:     11-02-07 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % FILTER overrides the filter function for analysis objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: FILTER overrides the filter function for analysis objects.
0005 %              Applies the input digital IIR/FIR filter to the input analysis
0006 %              object. 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] = filter(a,pl)
0017 %              >> [b, filt] = filter(a,filt,pl)
0018 %              >> b = filter(a,pl)
0019 %
0020 % INPUTS:      pl   - a parameter list
0021 %              a    - input analysis object
0022 %
0023 % OUTPUTS:     filt - a copy of the input filter object with the
0024 %                     history values filled in.
0025 %              b    - output analysis object containing the filtered data.
0026 %
0027 % PARAMETERS:  filter - the filter object to use to filter the data
0028 %
0029 % M-FILE INFO: Get information about this methods by calling
0030 %              >> ao.getInfo('filter')
0031 %
0032 %              Get information about a specified set-plist by calling:
0033 %              >> ao.getInfo('filter', 'None')
0034 %
0035 % VERSION:     $Id: filter.m,v 1.40 2008/09/05 11:05:29 ingo Exp $
0036 %
0037 % HISTORY:     11-02-07 M Hewitson
0038 %                 Creation
0039 %
0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0041 
0042 function varargout = filter(varargin)
0043 
0044   % Check if this is a call for parameters
0045   if utils.helper.isinfocall(varargin{:})
0046     varargout{1} = getInfo(varargin{3});
0047     return
0048   end
0049 
0050   import utils.const.*
0051   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0052   
0053   % Collect input variable names
0054   in_names = cell(size(varargin));
0055   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0056 
0057   % Collect all AOs and plists
0058   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0059   [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0060   [fobj, f_invars] = utils.helper.collect_objects(varargin(:), 'ltpda_filter', in_names);
0061 
0062   % Make copies or handles to inputs
0063   bs   = copy(as, nargout);
0064 
0065   % combine plists
0066   pl = combine(pl, getDefaultPlist());
0067 
0068   if isempty(fobj)
0069     fobj        = find(pl, 'filter');
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   for j=1:numel(bs)
0081     %--------- Time-series filter
0082     if isa(bs(j).data, 'tsdata')
0083       % get input data
0084       if isa(fobj, 'mfir')
0085         % apply filter
0086         utils.helper.msg(msg.PROC1, 'filtering with FIR filter');
0087         [bs(j).data.y, Zf] = filter(fobj.a, 1, bs(j).data.y, fobj.histout);
0088         fobj.setHistout(Zf);
0089         % remove group delay
0090         if isempty(find(pl, 'gdoff'))
0091           gd = floor(fobj.gd);
0092           bs(j).data.setX(bs(j).data.getX(1:end-gd));
0093           bs(j).data.setY(bs(j).data.y(1+gd:end));
0094           bs(j).data.collapseX;
0095         end
0096       else %if isa(fobj, 'miir')
0097         if bs(j).data.fs ~= fobj.fs
0098           warning('!!! Filter is designed for a different sample rate of data.');
0099           % Adjust/redesign if this is a standard filter
0100           fobj = fobj.redesign(bs(j).data.fs);
0101         end
0102         utils.helper.msg(msg.PROC1, 'filtering with IIR filter');
0103         [bs(j).data.y, Zf] = filter(fobj.a, fobj.b, bs(j).data.y, fobj.histout);
0104         fobj.setHistout(Zf);
0105       end
0106       % add history
0107       bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0108       % name for this object
0109       bs(j).setName(sprintf('%s(%s)', fobj.name, ao_invars{j}), 'internal');
0110 
0111     elseif isa(d, 'fsdata')
0112       %--------- Frequency-series filter
0113       error('### I don''t work yet. Please code me up.');
0114     else
0115       error('### unknown data type.');
0116     end
0117   end
0118 
0119   % Set outputs
0120   if nargout == 1
0121     varargout{1} = bs;
0122   elseif nargout == 2
0123     varargout{1} = bs;
0124     varargout{2} = fobj;
0125   elseif nargout > 2
0126     error('### wrong number of output arguments.');
0127   end
0128 end
0129 
0130 %--------------------------------------------------------------------------
0131 % Get Info Object
0132 %--------------------------------------------------------------------------
0133 function ii = getInfo(varargin)
0134   if nargin == 1 && strcmpi(varargin{1}, 'None')
0135     sets = {};
0136     pls  = [];
0137   else
0138     sets = {'Default'};
0139     pls  = getDefaultPlist;
0140   end
0141   % Build info object
0142   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: filter.m,v 1.40 2008/09/05 11:05:29 ingo Exp $', sets, pls);
0143 end
0144 
0145 %--------------------------------------------------------------------------
0146 % Get Default Plist
0147 %--------------------------------------------------------------------------
0148 function pl_default = getDefaultPlist()
0149   pl_default = plist('filter',  '', 'gdoff' ,[]);
0150 end
0151

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003