


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.13 2007/11/26 14:48:13 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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