Home > classes > @ao > filtfilt.m

filtfilt

PURPOSE ^

FILTFILT overides the filtfilt function for analysis objects.

SYNOPSIS ^

function varargout = filtfilt(a, pl)

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.8 2007/06/22 10:19:57 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(a, pl)
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.8 2007/06/22 10:19:57 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 %% Check if this is a call for parameters
0045 if nargin == 2
0046   if isa(a, 'ao') && ischar(pl)
0047     in = char(pl);
0048     if strcmp(in, 'Params')
0049       varargout{1} = getDefaultPL();
0050       return
0051     end
0052   end
0053 end
0054 
0055 %% capture input variable names
0056 invars = {};
0057 for j=1:nargin
0058   invars = [invars cellstr(inputname(j))];
0059 end
0060 
0061 ALGONAME = mfilename;
0062 VERSION  = '$Id: filtfilt.m,v 1.8 2007/06/22 10:19:57 ingo Exp $';
0063 
0064 filt = find(pl, 'filter');
0065 
0066 % Initialise output
0067 bs = [];
0068 
0069 % check inputs
0070 if ~isa(filt, 'miir')
0071   error('### the first input should be an miir object.');
0072 end
0073 if ~isa(a, 'ao')
0074   error('### second input should be an analysis object.');
0075 end
0076 
0077 % get input data
0078 d = a.data;
0079 
0080 %--------- Time-series filter
0081 %
0082 if isa(d, 'tsdata')
0083 
0084   % get input data
0085   x  = d.x;
0086   fs = d.fs;
0087   if fs ~= get(filt, 'fs')
0088     warning('!!! Filter is designed for a different sample rate of data.');
0089     % Adjust/redesign if this is a standard filter
0090     filt = redesign(filt, fs);
0091   end
0092 
0093   % get filter coeffs
0094   ac = get(filt,'a');
0095   bc = get(filt,'b');
0096 
0097   % apply filter
0098   y = filtfilt(ac, bc, x);
0099 %   [fstruct, y] = ltpda_filtfilt(struct(filt), d.x, length(d.x));
0100   % consolodate this structure with miir class before converting.
0101 %   filt = set(filt, 'histin', fstruct.histin);
0102 %   filt = set(filt, 'histout', fstruct.histout);
0103 
0104   %----- Create output analysis object
0105   % make a new tsdata object
0106   ts = tsdata(d.t, y);
0107   ts = set(ts, 'name', sprintf('filtfilt %s with %s', d.name, get(filt,'name')));
0108   ts = set(ts, 'xunits', d.xunits);
0109   ts = set(ts, 'yunits', d.yunits);
0110   ts = set(ts, 't0', d.t0);
0111 
0112   % make a new history object
0113   pl = plist();
0114   pl = append(pl, param('filter', filt));
0115   h = history(ALGONAME, VERSION, pl, a.hist);
0116   h = set(h, 'invars', invars);
0117 
0118   % make output analysis object
0119   bs = ao(ts, h);
0120   % name for this object
0121   if isempty(invars{1})
0122     n1 = a.name;
0123   else
0124     n1 = invars{1};
0125   end
0126   bs = set(bs, 'name', sprintf('%s(%s)', get(filt,'name'), n1));
0127 
0128   if nargout == 1
0129     varargout{1} = bs;
0130   elseif nargout == 2
0131     varargout{1} = bs;
0132     varargout{2} = filt;
0133   else
0134     error('### wrong number of output arguments.');
0135   end
0136 
0137 
0138 %--------- Frequency-series filter
0139 %
0140 elseif isa(d, 'fsdata')
0141   error('### I don''t work yet. Please code me up.');
0142 
0143 else
0144   error('### unknown data type.');
0145 end
0146 
0147 %% Get default params
0148 function pl_default = getDefaultPL()
0149 
0150 disp('* creating default plist...');
0151   pl_default = plist(param('filter',  ''));
0152 disp('* done.');

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003