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.
 
 
 usage: a = resp(p, f);   % compute response for vector f
        a = resp(p, f1, f2, nf); % compute response from f1 to f2 in nf
                                   steps.
        a = resp(p, pl); % compute response from parameter list.
 
 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'
 
 M Hewitson 03-04-07
 
 $Id: resp.html,v 1.1 2007/06/08 14:15:07 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = resp(varargin)
0002 
0003 % RESP returns the complex response of a pzmodel as an Analysis Object.
0004 %
0005 %
0006 % usage: a = resp(p, f);   % compute response for vector f
0007 %        a = resp(p, f1, f2, nf); % compute response from f1 to f2 in nf
0008 %                                   steps.
0009 %        a = resp(p, pl); % compute response from parameter list.
0010 %
0011 % Parameters:
0012 %   'f'  - a vector of frequencies to evaluate at
0013 % or
0014 %   'f1'    - start frequency
0015 %   'f2'    - stop frequency
0016 %   'nf'    - number of evaluation frequencies
0017 %   'scale' - spacing of frequencies: 'lin' or 'log'
0018 %
0019 % M Hewitson 03-04-07
0020 %
0021 % $Id: resp.html,v 1.1 2007/06/08 14:15:07 hewitson Exp $
0022 %
0023 
0024 ALGONAME = mfilename;
0025 VERSION  = '$Id: resp.html,v 1.1 2007/06/08 14:15:07 hewitson Exp $';
0026 
0027 if nargin < 1
0028   error('### incorrect number of inputs.')
0029 end
0030 
0031 % look at inputs
0032 pzm = varargin{1};
0033 if ~isa(pzm, 'pzmodel')
0034   error('### first argument should be a pzmodel object.');
0035 end
0036 % Now look at the model
0037 name  = get(pzm, 'name');
0038 gain  = get(pzm, 'gain');
0039 poles = get(pzm, 'poles');
0040 zeros = get(pzm, 'zeros');
0041 np    = length(poles);
0042 nz    = length(zeros);
0043 
0044 % check inputs
0045 pl    = [];
0046 scale = [];
0047 
0048 if nargin == 1
0049   
0050   f1 = getlowerFreq(pzm)/10;
0051   f2 = getupperFreq(pzm)*10;
0052   nf = 10000;
0053   f = linspace(f1, f2, nf);
0054   scale = 'lin';
0055   
0056 elseif nargin == 2
0057   if isa(varargin{2}, 'plist')
0058     pl = varargin{2};
0059     f  = find(pl, 'f');
0060     f1 = find(pl, 'f1');
0061     f2 = find(pl, 'f2');
0062     nf = find(pl, 'nf');
0063     scale = find(pl, 'scale');
0064     
0065     if ~isempty(f)
0066       % nothing
0067     else
0068       if isempty(f1)
0069         f1 = getlowerFreq(pzm)/10;
0070       end
0071       if isempty(f2)
0072         f2 = getupperFreq(pzm)*10;
0073       end
0074       if isempty(nf)
0075         nf = 10000;
0076       end
0077       if isempty(scale)
0078         scale = 'lin';
0079       end
0080       
0081       switch scale
0082         case {'lin', 'linear'}
0083           f = linspace(f1, f2, nf);
0084         case 'log'
0085           f = logspace(f1, f2, nf);
0086       end
0087       
0088       
0089     end
0090 %     if ~isempty(f1) && ~isempty(f2) && ~isempty(nf)
0091 %       if isempty(scale) || strcmp(scale, 'lin')
0092 %       elseif strcmp(scale, 'log')
0093 %       else
0094 %         error('### unknown scale option for pzmodel response.');
0095 %       end
0096 %     else
0097 %       % build default
0098 %       f1 = getlowerFreq(pzm)/10;
0099 %       f2 = getupperFreq(pzm)*10;
0100 %       nf = 10000;
0101 %       f = linspace(f1, f2, nf);
0102 %       scale = 'lin';
0103 %     end
0104     
0105   else
0106     f = varargin{2};
0107   end
0108 elseif nargin == 4
0109   f1 = varargin{2};
0110   f2 = varargin{3};
0111   nf = varargin{4};
0112   f  = linspace(f1, f2, nf);
0113 else
0114   error('### incorrect number of inputs.');
0115 end
0116 
0117 
0118 % make output plist
0119 f1 = f(1);
0120 f2 = f(end);
0121 nf = length(f);
0122 plo = plist();
0123 plo = append(plo, param('f1', f1));
0124 plo = append(plo, param('f2', f2));
0125 plo = append(plo, param('nf', nf));
0126 if ~isempty(scale)
0127   plo = append(plo, param('scale', scale));
0128 end
0129 
0130 % Now compute the response
0131 r = gain;
0132 for j=1:np
0133   [f, pr] = resp(poles(j),f);
0134 %   figure,loglog(f, abs(pr))
0135   r = r .* pr;
0136 end
0137 for j=1:nz
0138   [f, zr] = resp(zeros(j),f);
0139 %   figure,loglog(f, abs(zr))
0140   r = r .* zr;  
0141 end
0142 
0143 %---------- Build output ao
0144 
0145 % create new output fsdata
0146 fs = fsdata(f, r, 1);
0147 fs = set(fs, 'name', sprintf('resp(%s)', pzm.name));
0148 
0149 % create new output history
0150 h = history(ALGONAME, VERSION, plo);
0151 
0152 % make output analysis object
0153 b = ao(fs, h);
0154 
0155 % set name
0156 b = set(b, 'name', sprintf('resp(%s)', pzm.name));
0157 
0158 % Outputs
0159 if nargout == 0
0160   figure
0161   plot(b)
0162 elseif nargout == 1
0163   varargout{1} = b;
0164 else
0165   error('### incorrect output arguments');  
0166 end
0167 
0168 
0169 % END

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