Home > classes > @ao > filtfilt.m

filtfilt

PURPOSE ^

FILTFILT overides the filtfilt function for analysis objects.

SYNOPSIS ^

function varargout = filtfilt(varargin)

DESCRIPTION ^

 FILTFILT overides the filtfilt function for analysis objects.

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

 DESCRIPTION: FILTFILT overides 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

 REMARK:      Uses ltpda_filtfilt() to do the filtering.

 VERSION:     $Id: filtfilt.m,v 1.9 2007/11/02 12:26:24 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = filtfilt(ao, 'Params')

 HISTORY: 11-02-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = filtfilt(varargin)
0002 % FILTFILT overides the filtfilt function for analysis objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: FILTFILT overides the filtfilt function for analysis objects.
0007 %              Applies the input digital IIR filter to the input analysis object
0008 %              forwards and backwards. If the input analysis object contains a
0009 %              time-series (tsdata) then the filter is applied using the normal
0010 %              recursion algorithm. The output analysis object contains a tsdata
0011 %              object.
0012 %
0013 %              If the input analysis object contains a frequency-series (fsdata)
0014 %              then the response of the filter is computed and then multiplied
0015 %              with the input frequency series. The output analysis object
0016 %              contains a frequency series.
0017 %
0018 % CALL:        >> [b, filt] = filtfilt(a,pl)
0019 %              >> b = filtfilt(a,pl)
0020 %
0021 % INPUTS:      pl   - a parameter list
0022 %              a    - input analysis object
0023 %
0024 % OUTPUTS:     filt - a copy of the input filter object with the
0025 %                     history values filled in.
0026 %              b    - output analysis object containing the filtered data.
0027 %
0028 % PARAMETERS:  filter - the filter object to use to filter the data
0029 %
0030 % REMARK:      Uses ltpda_filtfilt() to do the filtering.
0031 %
0032 % VERSION:     $Id: filtfilt.m,v 1.9 2007/11/02 12:26:24 ingo Exp $
0033 %
0034 % The following call returns a parameter list object that contains the
0035 % default parameter values:
0036 %
0037 % >> pl = filtfilt(ao, 'Params')
0038 %
0039 % HISTORY: 11-02-07 M Hewitson
0040 %             Creation
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 ALGONAME = mfilename;
0045 VERSION  = '$Id: filtfilt.m,v 1.9 2007/11/02 12:26:24 ingo Exp $';
0046 
0047 %% Check if this is a call for parameters
0048 if nargin == 2
0049   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0050     in = char(varargin{2});
0051     if strcmp(in, 'Params')
0052       varargout{1} = getDefaultPL();
0053       return
0054     elseif strcmp(in, 'Version')
0055       varargout{1} = VERSION;
0056       return
0057     end
0058   end
0059 end
0060 
0061 invars = {};
0062 as     = [];
0063 bo     = [];
0064 ps     = [];
0065 filt   = [];
0066 
0067 for j=1:nargin
0068   if isa(varargin{j}, 'ao')
0069     invars = [invars cellstr(inputname(j))];
0070   end
0071   if isa(varargin{j}, 'ao')
0072     as = [as varargin{j}];
0073   end
0074   if isa(varargin{j}, 'plist')
0075     ps = [ps varargin{j}];
0076   end
0077   if isa(varargin{j}, 'miir')
0078     filt = varargin{j};
0079   end
0080 end
0081 
0082 if isa(ps, 'plist')
0083   pl = combine(ps);
0084 else
0085   pl = plist();
0086 end
0087 if isempty(filt)
0088   filt = find(pl, 'filter');
0089 end
0090 
0091 % check inputs
0092 if ~isa(filt, 'miir')
0093   error('### the first input should be an miir object.');
0094 end
0095 if ~isa(as, 'ao')
0096   error('### second input should be an analysis object.');
0097 end
0098 
0099 for ii=1:numel(as)
0100 
0101   % get input data
0102   a = as(ii);
0103   d = a.data;
0104 
0105   %--------- Time-series filter
0106   %
0107   if isa(d, 'tsdata')
0108 
0109     % get input data
0110     x  = d.x;
0111     fs = d.fs;
0112     if fs ~= get(filt, 'fs')
0113       warning('!!! Filter is designed for a different sample rate of data.');
0114       % Adjust/redesign if this is a standard filter
0115       filt = redesign(filt, fs);
0116     end
0117 
0118     % get filter coeffs
0119     ac = get(filt,'a');
0120     bc = get(filt,'b');
0121 
0122     % apply filter
0123     y = filtfilt(ac, bc, x);
0124     %   [fstruct, y] = ltpda_filtfilt(struct(filt), d.x, length(d.x));
0125     % consolodate this structure with miir class before converting.
0126     %   filt = set(filt, 'histin', fstruct.histin);
0127     %   filt = set(filt, 'histout', fstruct.histout);
0128 
0129     %----- Create output analysis object
0130     % make a new tsdata object
0131     ts = tsdata(d.t, y);
0132     ts = set(ts, 'name', sprintf('filtfilt %s with %s', d.name, get(filt,'name')));
0133     ts = set(ts, 'xunits', d.xunits);
0134     ts = set(ts, 'yunits', d.yunits);
0135     ts = set(ts, 't0', d.t0);
0136 
0137     % make a new history object
0138     pl = plist();
0139     pl = append(pl, param('filter', filt));
0140     h = history(ALGONAME, VERSION, pl, a.hist);
0141     h = set(h, 'invars', invars);
0142 
0143     % make output analysis object
0144     bs = ao(ts, h);
0145     % name for this object
0146     if isempty(invars{1})
0147       n1 = a.name;
0148     else
0149       n1 = invars{1};
0150     end
0151     bs = set(bs, 'name', sprintf('%s(%s)', get(filt,'name'), n1));
0152 
0153     bo = [bo bs];
0154 
0155     %--------- Frequency-series filter
0156     %
0157   elseif isa(d, 'fsdata')
0158     error('### I don''t work yet. Please code me up.');
0159 
0160   else
0161     error('### unknown data type.');
0162   end
0163 
0164 end
0165 
0166 % Reshape the ouput to the same size of the input
0167 bo = reshape(bo, size(as));
0168 
0169 if nargout == 1
0170   varargout{1} = bo;
0171 elseif nargout == 2
0172   varargout{1} = bo;
0173   varargout{2} = filt;
0174 else
0175   error('### wrong number of output arguments.');
0176 end
0177 
0178 
0179 %% Get default params
0180 function pl_default = getDefaultPL()
0181 
0182   pl_default = plist(param('filter',  ''));

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003