comparison m-toolbox/classes/@ao/fftfilt.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % FFTFILT overrides the fft filter function for analysis objects.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: FFTFILT overrides the fft filter function for analysis objects.
5 % Applies the input filter to the input analysis
6 % object in the frequency domain.
7 %
8 %
9 % CALL: >> b = fftfilt(a,smodel); b = fftfilt(a,plist('filter',smodel))
10 % >> b = fftfilt(a,mfir); b = fftfilt(a,plist('filter',mfir))
11 % >> b = fftfilt(a,miir); b = fftfilt(a,plist('filter',miir))
12 % >> b = fftfilt(a,ltpda_tf); b = fftfilt(a,plist('filter',ltpda_tf))
13 % >> b = fftfilt(a,plist('filter',c)) % c is an AO used as a
14 % filter
15 %
16 % INPUTS:
17 % a - input analysis object
18 % one of
19 % smodel - a model to filter with. The x-dependency must
20 % be on frequency ('f').
21 % mfir - an FIR filter
22 % miir - an IIR filter
23 % tf - an ltpda_tf object
24 % including:
25 % - pzmodel
26 % - rational
27 % - parfrac
28 % ao - a frequency-series AO. This must have the
29 % correct frequency base to match the FFT'd input
30 % data. You must input it in a plist
31 %
32 % OUTPUTS:
33 % b - output analysis object containing the filtered data.
34 %
35 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'fftfilt')">Parameters Description</a>
36 %
37 % VERSION: $Id: fftfilt.m,v 1.35 2011/05/28 05:42:15 mauro Exp $
38 %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
41 function varargout = fftfilt(varargin)
42
43 % Check if this is a call for parameters
44 if utils.helper.isinfocall(varargin{:})
45 varargout{1} = getInfo(varargin{3});
46 return
47 end
48
49 import utils.const.*
50 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
51
52 % Collect input variable names
53 in_names = cell(size(varargin));
54 for ii = 1:nargin,in_names{ii} = inputname(ii);end
55
56 % Collect all AOs and plists
57 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
58 [filt, f_invars] = utils.helper.collect_objects(varargin(:), 'ltpda_filter', in_names);
59 [mobjs, md_invars] = utils.helper.collect_objects(varargin(:), 'smodel', in_names);
60 [tfobjs, tf_invars] = utils.helper.collect_objects(varargin(:), 'ltpda_tf', in_names);
61
62 % Make copies or handles to inputs
63 bs = copy(as, nargout);
64
65 % Apply defaults to plist
66 pl = applyDefaults(getDefaultPlist, varargin{:});
67
68 % Filter with a smodel object
69 if ~isempty(mobjs)
70 filt = mobjs;
71 elseif ~isempty(tfobjs)
72 filt = tfobjs;
73 end
74
75 if isempty(filt)
76 filt = find(pl, 'filter');
77 end
78
79 if isempty(filt)
80 error('### A filter must be provided ###')
81 end
82
83 % get number of Bins for zero padding
84 Npad = find(pl,'Npad');
85
86 % get initial conditions
87 inConds = find(pl,'Initial Conditions');
88
89 % check initial conditions
90 if ~isempty(inConds)
91 if iscell(inConds) && numel(inConds) ~= numel(bs)
92 error('### Please give the proper number of initial conditions')
93 end
94 if ~iscell(inConds) && numel(bs)>1
95 error('### Please give the initial conditions in a cell-array')
96 else
97 inConds = {inConds};
98 end
99 end
100
101 inCondsMdl = repmat(smodel(), numel(bs), 1);
102 for ii = 1:numel(bs)
103 if ~isempty(inConds)
104 N = numel(inConds{ii});
105 expr = '';
106 ix = 1;
107 for jj = N-1:-1:0
108 expr = [expr,sprintf('+(2*pi*i*f).^%i*%g',jj,inConds{ii}(ix))];
109 ix = ix+1;
110 end
111 inCondsMdl(ii) = smodel(plist('expression', expr, 'xvar', 'f'));
112 end
113 end
114
115 for ii = 1:numel(bs)
116 % keep the history to suppress the history of the intermediate steps
117 inhist = bs(ii).hist;
118
119 % make sure we operate on physical frequencies
120 switch class(filt)
121 case 'smodel'
122 switch filt.xvar{1}
123 case 'f'
124 % Nothing to do
125 case 's'
126 % I need to map from 's' to 'f'
127 filt.setTrans('2*pi*i');
128 otherwise
129 error('### The filter smodel must have xvar = ''s'' or ''f''');
130 end
131 otherwise
132 end
133
134 % call core method of the fftfilt
135 bs(ii).fftfilt_core(filt, Npad, inCondsMdl(ii));
136
137 % Set name
138 bs(ii).setName(sprintf('fftfilt(%s)', ao_invars{ii}));
139 % Add history
140 bs(ii).addHistory(getInfo('None'), pl, ao_invars(ii), [inhist filt(:).hist]);
141
142 end
143
144 % Set output
145 varargout = utils.helper.setoutputs(nargout, bs);
146 end
147
148
149 %--------------------------------------------------------------------------
150 % Get Info Object
151 %--------------------------------------------------------------------------
152 function ii = getInfo(varargin)
153 if nargin == 1 && strcmpi(varargin{1}, 'None')
154 sets = {};
155 pl = [];
156 else
157 sets = {'Default'};
158 pl = getDefaultPlist();
159 end
160 % Build info object
161 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: fftfilt.m,v 1.35 2011/05/28 05:42:15 mauro Exp $', sets, pl);
162 end
163
164 %--------------------------------------------------------------------------
165 % Get Default Plist
166 %--------------------------------------------------------------------------
167 function plout = getDefaultPlist()
168 persistent pl;
169 if ~exist('pl', 'var') || isempty(pl)
170 pl = buildplist();
171 end
172 plout = pl;
173 end
174
175 function pl = buildplist()
176
177 pl = plist();
178
179 % Filter
180 p = param({'filter', 'The filter to apply to the data.'}, paramValue.EMPTY_STRING);
181 pl.append(p);
182
183 % Number of bins for zero padding
184 p = param({'Npad', 'Number of bins for zero padding.'}, paramValue.EMPTY_DOUBLE);
185 pl.append(p);
186
187 % Initial conditions
188 p = param({'Initial Conditions', ['A cell containing the arrays of initial conditions, one '...
189 'for each system being solved, '...
190 'starting from the lower order to the maximum allowed. '...
191 'It assumed that the underlying system follows a linear differential equation with constant coefficients. '...
192 'For example, if the system is the Newton '...
193 '2nd-order equation of motion, than the array contains the initial position and the '...
194 'initial velocity.']}, paramValue.EMPTY_CELL);
195 pl.append(p);
196
197 end
198
199
200