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.
 
 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.
 
 >> [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
 
 Uses ltpda_filtfilt() to do the filtering.
 
 M Hewitson 11-02-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = filtfilt(a, pl)
0002 
0003 % FILTFILT overides the filtfilt function for analysis objects.
0004 %
0005 % Applies the input digital IIR filter to the input analysis object forwards and backwards.
0006 %
0007 % If the input analysis object contains a time-series (tsdata) then the
0008 % filter is applied using the normal recursion algorithm. The output
0009 % analysis object contains a tsdata object.
0010 %
0011 % If the input analysis object contains a frequency-series (fsdata) then
0012 % the response of the filter is computed and then multiplied with the input
0013 % frequency series. The output analysis object contains a frequency series.
0014 %
0015 % >> [b, filt] = filtfilt(a,pl)
0016 % >> b = filtfilt(a,pl)
0017 %
0018 % Inputs:
0019 %   pl   - a parameter list
0020 %   a    - input analysis object
0021 %
0022 % Outputs:
0023 %   filt - a copy of the input filter object with the history values filled
0024 %          in.
0025 %   b    - output analysis object containing the filtered data.
0026 %
0027 % Parameters:
0028 %   filter - the filter object to use to filter the data
0029 %
0030 % Uses ltpda_filtfilt() to do the filtering.
0031 %
0032 % M Hewitson 11-02-07
0033 %
0034 
0035 % capture input variable names
0036 invars = {};
0037 for j=1:nargin
0038   invars = [invars cellstr(inputname(j))];
0039 end
0040 
0041 ALGONAME = mfilename;
0042 VERSION  = '$Id: filtfilt.html,v 1.1 2007/06/08 14:15:02 hewitson Exp $';
0043 
0044 filt = find(pl, 'filter');
0045 
0046 % Initialise output
0047 bs = [];
0048 
0049 % check inputs
0050 if ~isa(filt, 'miir')
0051   error('### the first input should be an miir object.');
0052 end
0053 if ~isa(a, 'ao')
0054   error('### second input should be an analysis object.');
0055 end
0056 
0057 % get input data
0058 d = a.data;
0059 
0060 %--------- Time-series filter
0061 %
0062 if isa(d, 'tsdata')
0063   
0064   % get input data
0065   x  = d.x;
0066   fs = d.fs;
0067   if fs ~= get(filt, 'fs')
0068     warning('!!! Filter is designed for a different sample rate of data.');
0069     % Adjust/redesign if this is a standard filter
0070     filt = redesign(filt, fs);
0071   end
0072   
0073   % get filter coeffs
0074   ac = get(filt,'a');
0075   bc = get(filt,'b');
0076   
0077   % apply filter
0078   y = filtfilt(ac, bc, x);
0079 %   [fstruct, y] = ltpda_filtfilt(struct(filt), d.x, length(d.x));
0080   % consolodate this structure with miir class before converting.
0081 %   filt = set(filt, 'histin', fstruct.histin);
0082 %   filt = set(filt, 'histout', fstruct.histout);
0083   
0084   %----- Create output analysis object
0085   % make a new tsdata object
0086   ts = tsdata(d.t, y);
0087   ts = set(ts, 'name', sprintf('filtfilt %s with %s', d.name, get(filt,'name')));
0088   ts = set(ts, 'xunits', d.xunits);
0089   ts = set(ts, 'yunits', d.yunits);
0090   ts = set(ts, 't0', d.t0);
0091 
0092   % make a new history object
0093   pl = plist();
0094   pl = append(pl, param('filter', filt));
0095   h = history(ALGONAME, VERSION, pl, a.hist);
0096   h = set(h, 'invars', invars);
0097 
0098   % make output analysis object
0099   bs = ao(ts, h);
0100   % name for this object
0101   if isempty(invars{1})
0102     n1 = a.name;
0103   else
0104     n1 = invars{1};
0105   end
0106   bs = set(bs, 'name', sprintf('%s(%s)', get(filt,'name'), n1));
0107 
0108   if nargout == 1
0109     varargout{1} = bs;
0110   elseif nargout == 2
0111     varargout{1} = bs;
0112     varargout{2} = filt;
0113   else
0114     error('### wrong number of output arguments.');
0115   end
0116   
0117   
0118 %--------- Frequency-series filter
0119 %
0120 elseif isa(d, 'fsdata')
0121   error('### I don''t work yet. Please code me up.');
0122   
0123 else
0124   error('### unknown data type.');
0125 end
0126

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003