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(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'

 VERSION:     $Id: resp.m,v 1.9 2008/01/11 14:00:55 ingo Exp $

 HISTORY:     03-04-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003