Home > classes > @pzmodel > resp.m

resp

PURPOSE ^

RESP returns the complex response of a pzmodel as an Analysis Object.

SYNOPSIS ^

function varargout = resp(varargin)

DESCRIPTION ^

 RESP returns the complex response of a pzmodel as an Analysis Object.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: RESP returns the complex response of a pzmodel as an Analysis
              Object.

 CALL:        a = resp(pzm, f);          % compute response for vector f
              a = resp(pzm, f1, f2, nf); % compute response from f1 to f2 in nf
                                         steps.
              a = resp(pzm, pl);         % compute response from parameter list.
              a = resp(pzm);             % compute response

 % PARAMETERS: 'f'  - a vector of frequencies to evaluate at
             or
               'f1'    - start frequency
               'f2'    - stop frequency
               'nf'    - number of evaluation frequencies
               'scale' - spacing of frequencies: 'lin' or 'log'

               These parameters (one or more) can be defined via a plist,
               with the params keys named in the same way as above

 M-FILE INFO: Get information about this methods by calling
              >> pzmodel.getInfo('resp')

              Get information about a specified set-plist by calling:
              >> pzmodel.getInfo('resp', 'Range')

 VERSION:     $Id: resp.m,v 1.26 2008/09/04 15:29:31 ingo Exp $

 HISTORY:     03-04-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % RESP returns the complex response of a pzmodel as an Analysis Object.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: RESP returns the complex response of a pzmodel as an Analysis
0005 %              Object.
0006 %
0007 % CALL:        a = resp(pzm, f);          % compute response for vector f
0008 %              a = resp(pzm, f1, f2, nf); % compute response from f1 to f2 in nf
0009 %                                         steps.
0010 %              a = resp(pzm, pl);         % compute response from parameter list.
0011 %              a = resp(pzm);             % compute response
0012 %
0013 % % PARAMETERS: 'f'  - a vector of frequencies to evaluate at
0014 %             or
0015 %               'f1'    - start frequency
0016 %               'f2'    - stop frequency
0017 %               'nf'    - number of evaluation frequencies
0018 %               'scale' - spacing of frequencies: 'lin' or 'log'
0019 %
0020 %               These parameters (one or more) can be defined via a plist,
0021 %               with the params keys named in the same way as above
0022 %
0023 % M-FILE INFO: Get information about this methods by calling
0024 %              >> pzmodel.getInfo('resp')
0025 %
0026 %              Get information about a specified set-plist by calling:
0027 %              >> pzmodel.getInfo('resp', 'Range')
0028 %
0029 % VERSION:     $Id: resp.m,v 1.26 2008/09/04 15:29:31 ingo Exp $
0030 %
0031 % HISTORY:     03-04-2007 M Hewitson
0032 %                 Creation
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 function varargout = resp(varargin)
0037 
0038   %%% Check if this is a call for parameters
0039   if utils.helper.isinfocall(varargin{:})
0040     varargout{1} = getInfo(varargin{3});
0041     return
0042   end
0043 
0044   %%% Input objects checks
0045   if nargin < 1
0046     error('### incorrect number of inputs.')
0047   end
0048 
0049   % Collect input pzmodels, plists and input variable names
0050   in_names = cell(size(varargin));
0051   for ii = 1:nargin
0052     in_names{end+1} = inputname(ii);
0053   end
0054   [pzms, invars] = utils.helper.collect_objects(varargin(:), 'pzmodel', in_names);
0055 
0056   % Loop over pzmodels
0057   bs = [];
0058   for pp=1:numel(pzms)
0059 
0060     % process this pzmodel
0061     pzm = pzms(pp);
0062     % Now look at the model
0063     name  = pzm.name;
0064     gain  = pzm.gain;
0065     poles = pzm.poles;
0066     zeros = pzm.zeros;
0067     np    = length(poles);
0068     nz    = length(zeros);
0069 
0070     %%% check inputs
0071 
0072     if nargin == 1
0073       %%% a = resp(pzm); %%
0074       % get frequencies for response
0075       minf = getlowerFreq(pzm)/10;
0076       maxf = getupperFreq(pzm)*10;
0077       pl =  plist('f1', minf, 'f2', maxf, 'nf', 1000, 'scale', 'log');
0078 
0079     elseif nargin == 2
0080       if isa(varargin{2}, 'plist')
0081         %%% a = resp(pzm, plist); %%
0082         pl = varargin{2};
0083         if ~isempty(find(pl, 'f'))
0084           pl = combine(pl, getDefaultPlist('List'));
0085         else
0086           pl = combine(pl, getDefaultPlist('Range'));
0087         end
0088       else
0089         %%% a = resp(pzm, f); %%
0090         f = varargin{2};
0091         pl = plist('f',f);
0092       end
0093     elseif nargin == 4
0094       %%% a = resp(pzm, f1, f2, nf); %%
0095       f1 = varargin{2};
0096       f2 = varargin{3};
0097       nf = varargin{4};
0098 
0099       pl = plist('f1',f1, 'f2',f2, 'nf',nf, 'scale','lin');
0100 
0101     else
0102       error('### incorrect number of inputs.');
0103     end
0104 
0105     % Compute or extract the frequency vector
0106     reshape_f = false;
0107     if ~isempty(find(pl, 'f'))
0108       % Compute from frequency list
0109       f     = find(pl, 'f');
0110       % Want to deal with rows
0111       reshape_f = false;
0112       if size(f,1) > 1
0113         f = f.';
0114         reshape_f = true;
0115       end
0116     else
0117       % Compute from frequency range
0118       f1 = find(pl, 'f1');
0119       f2 = find(pl, 'f2');
0120       nf = find(pl, 'nf');
0121       scale = find(pl, 'scale');
0122       switch scale
0123         case 'lin'
0124           f   = linspace(f1, f2, nf);
0125         case 'log'
0126           f = logspace(log10(f1), log10(f2), nf);
0127       end
0128 
0129     end
0130 
0131     % Now compute the response
0132     r = gain;
0133     for j=1:np
0134       if ~isnan(poles(j).f)
0135         [f, pr] = resp(poles(j),f);
0136         r = r .* pr;
0137       end
0138     end
0139     for j=1:nz
0140       if ~isnan(zeros(j).f)
0141         [f, zr] = resp(zeros(j),f);
0142         r = r ./zr;
0143       end
0144     end
0145 
0146     % ---------- Build output ao
0147     if reshape_f
0148       f = f.';
0149       r = r.';
0150     end
0151 
0152     % create new output fsdata
0153     fsd = fsdata(f, r);
0154 
0155     % make output analysis object
0156     b = ao(fsd);
0157 
0158     % Add history
0159     b.addHistory(getInfo, pl, invars, pzm.hist);
0160 
0161     % set name
0162     b.setName(sprintf('resp(%s)', invars{pp}), 'internal');
0163 
0164     % Add to outputs
0165     bs = [bs b];
0166 
0167   end
0168 
0169   % Outputs
0170   if nargout == 0
0171     iplot(bs)
0172   elseif nargout == 1
0173     varargout{1} = bs;
0174   else
0175     error('### incorrect output arguments');
0176   end
0177 
0178 end
0179 
0180 
0181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0182 %                               Local Functions                               %
0183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0184 
0185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0186 %
0187 % FUNCTION:    getInfo
0188 %
0189 % DESCRIPTION: Get Info Object
0190 %
0191 % HISTORY:     11-07-07 M Hewitson
0192 %                Creation.
0193 %
0194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0195 
0196 function ii = getInfo(varargin)
0197   if nargin == 1 && strcmpi(varargin{1}, 'None')
0198     sets = {};
0199     pls   = [];
0200   elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1})
0201     sets{1} = varargin{1};
0202     pls = getDefaultPlist(sets{1});
0203   else
0204     sets = {'List', 'Range'};
0205     pls = [];
0206     for kk=1:numel(sets)
0207       pls = [pls getDefaultPlist(sets{kk})];
0208     end
0209   end
0210   % Build info object
0211   ii = minfo(mfilename, 'pzmodel', '', utils.const.categories.sigproc, '$Id: resp.m,v 1.26 2008/09/04 15:29:31 ingo Exp $', sets, pls);
0212 end
0213 
0214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0215 %
0216 % FUNCTION:    getDefaultPlist
0217 %
0218 % DESCRIPTION: Get Default Plist
0219 %
0220 % HISTORY:     11-07-07 M Hewitson
0221 %                Creation.
0222 %
0223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0224 
0225 function plo = getDefaultPlist(set)
0226   switch set
0227     case 'List'
0228       plo = plist('f', []);
0229     case 'Range'
0230       plo = plist('f1', 0.001, 'f2', 1, 'nf', 10000, 'scale', 'lin');
0231     otherwise
0232       plo = plist();
0233   end
0234 end
0235

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003