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.4 2007/07/18 13:58:45 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.4 2007/07/18 13:58:45 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.4 2007/07/18 13:58:45 ingo Exp $';
0030 
0031 if nargin < 1
0032   error('### incorrect number of inputs.')
0033 end
0034 
0035 % look at inputs
0036 pzm = varargin{1};
0037 if ~isa(pzm, 'pzmodel')
0038   error('### first argument should be a pzmodel object.');
0039 end
0040 % Now look at the model
0041 name  = get(pzm, 'name');
0042 gain  = get(pzm, 'gain');
0043 poles = get(pzm, 'poles');
0044 zeros = get(pzm, 'zeros');
0045 np    = length(poles);
0046 nz    = length(zeros);
0047 
0048 % check inputs
0049 pl    = [];
0050 scale = [];
0051 
0052 if nargin == 1
0053 
0054   f1 = getlowerFreq(pzm)/10;
0055   f2 = getupperFreq(pzm)*10;
0056   nf = 10000;
0057   f = linspace(f1, f2, nf);
0058   scale = 'lin';
0059 
0060 elseif nargin == 2
0061   if isa(varargin{2}, 'plist')
0062     pl = varargin{2};
0063     f  = find(pl, 'f');
0064     f1 = find(pl, 'f1');
0065     f2 = find(pl, 'f2');
0066     nf = find(pl, 'nf');
0067     scale = find(pl, 'scale');
0068 
0069     if ~isempty(f)
0070       % nothing
0071     else
0072       if isempty(f1)
0073         f1 = getlowerFreq(pzm)/10;
0074       end
0075       if isempty(f2)
0076         f2 = getupperFreq(pzm)*10;
0077       end
0078       if isempty(nf)
0079         nf = 10000;
0080       end
0081       if isempty(scale)
0082         scale = 'lin';
0083       end
0084 
0085       switch scale
0086         case {'lin', 'linear'}
0087           f = linspace(f1, f2, nf);
0088         case 'log'
0089           f = logspace(f1, f2, nf);
0090       end
0091 
0092 
0093     end
0094 %     if ~isempty(f1) && ~isempty(f2) && ~isempty(nf)
0095 %       if isempty(scale) || strcmp(scale, 'lin')
0096 %       elseif strcmp(scale, 'log')
0097 %       else
0098 %         error('### unknown scale option for pzmodel response.');
0099 %       end
0100 %     else
0101 %       % build default
0102 %       f1 = getlowerFreq(pzm)/10;
0103 %       f2 = getupperFreq(pzm)*10;
0104 %       nf = 10000;
0105 %       f = linspace(f1, f2, nf);
0106 %       scale = 'lin';
0107 %     end
0108 
0109   else
0110     f = varargin{2};
0111   end
0112 elseif nargin == 4
0113   f1 = varargin{2};
0114   f2 = varargin{3};
0115   nf = varargin{4};
0116   f  = linspace(f1, f2, nf);
0117 else
0118   error('### incorrect number of inputs.');
0119 end
0120 
0121 
0122 % make output plist
0123 f1 = f(1);
0124 f2 = f(end);
0125 nf = length(f);
0126 plo = plist();
0127 plo = append(plo, param('f1', f1));
0128 plo = append(plo, param('f2', f2));
0129 plo = append(plo, param('nf', nf));
0130 if ~isempty(scale)
0131   plo = append(plo, param('scale', scale));
0132 end
0133 
0134 % Now compute the response
0135 r = gain;
0136 for j=1:np
0137   [f, pr] = resp(poles(j),f);
0138 %   figure,loglog(f, abs(pr))
0139   r = r .* pr;
0140 end
0141 for j=1:nz
0142   [f, zr] = resp(zeros(j),f);
0143 %   figure,loglog(f, abs(zr))
0144   r = r .* zr;
0145 end
0146 
0147 %---------- Build output ao
0148 
0149 % create new output fsdata
0150 fs = fsdata(f, r, 1);
0151 fs = set(fs, 'name', sprintf('resp(%s)', pzm.name));
0152 
0153 % create new output history
0154 h = history(ALGONAME, VERSION, plo);
0155 
0156 % make output analysis object
0157 b = ao(fs, h);
0158 
0159 % set name
0160 b = set(b, 'name', sprintf('resp(%s)', pzm.name));
0161 
0162 % Outputs
0163 if nargout == 0
0164   figure
0165   plot(b)
0166 elseif nargout == 1
0167   varargout{1} = b;
0168 else
0169   error('### incorrect output arguments');
0170 end
0171 
0172 
0173 % END

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003