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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The following call returns a cell array that contains the default parameter sets names: >> sets = resp(pzmodel, 'Params') The following call returns a parameter list object that contains the default parameters for the jj-th set: >> pl = resp(pzmodel, 'Params', sets{jj}) The following call returns a string that contains the routine CVS version: >> version = resp(pzmodel, 'Version') The following call returns a string that contains the routine category: >> category = resp(pzmodel, 'Category') VERSION: $Id: resp.html,v 1.14 2008/03/31 10:27:37 hewitson Exp $ HISTORY: 03-04-2007 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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(pzm, f); % compute response for vector f 0010 % a = resp(pzm, f1, f2, nf); % compute response from f1 to f2 in nf 0011 % steps. 0012 % a = resp(pzm, pl); % compute response from parameter list. 0013 % a = resp(pzm); % compute response 0014 % 0015 % % PARAMETERS: 'f' - a vector of frequencies to evaluate at 0016 % or 0017 % 'f1' - start frequency 0018 % 'f2' - stop frequency 0019 % 'nf' - number of evaluation frequencies 0020 % 'scale' - spacing of frequencies: 'lin' or 'log' 0021 % 0022 % These parameters (one or more) can be defined via a plist, 0023 % with the params keys named in the same way as above 0024 % 0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0026 % 0027 % The following call returns a cell array that contains the default parameter 0028 % sets names: 0029 % 0030 % >> sets = resp(pzmodel, 'Params') 0031 % 0032 % The following call returns a parameter list object that contains the 0033 % default parameters for the jj-th set: 0034 % 0035 % >> pl = resp(pzmodel, 'Params', sets{jj}) 0036 % 0037 % The following call returns a string that contains the routine CVS version: 0038 % 0039 % >> version = resp(pzmodel, 'Version') 0040 % 0041 % The following call returns a string that contains the routine category: 0042 % 0043 % >> category = resp(pzmodel, 'Category') 0044 % 0045 % 0046 % VERSION: $Id: resp.html,v 1.14 2008/03/31 10:27:37 hewitson Exp $ 0047 % 0048 % HISTORY: 03-04-2007 M Hewitson 0049 % Creation 0050 % 0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0052 0053 ALGONAME = mfilename; 0054 VERSION = '$Id: resp.html,v 1.14 2008/03/31 10:27:37 hewitson Exp $'; 0055 CATEGORY = 'Signal Processing'; 0056 0057 0058 %% 'Params', 'Version' and 'Category' Call 0059 if (nargin == 2 || nargin == 3) && ... 0060 isa(varargin{1}, 'pzmodel') && ... 0061 ischar(varargin{2}) 0062 in = char(varargin{2}); 0063 if strcmp(in, 'Params') 0064 if nargin == 2 0065 varargout{1} = getDefaultPL(); 0066 else 0067 varargout{1} = getDefaultPL(varargin{3}); 0068 end 0069 return 0070 elseif strcmp(in, 'Version') 0071 varargout{1} = VERSION; 0072 return 0073 elseif strcmp(in, 'Category') 0074 varargout{1} = CATEGORY; 0075 return 0076 end 0077 end 0078 0079 %% Input objects checks 0080 if nargin < 1 0081 error('### incorrect number of inputs.') 0082 end 0083 0084 % look at inputs 0085 pzm = varargin{1}; 0086 if ~isa(pzm, 'pzmodel') 0087 error('### first argument should be a pzmodel object.'); 0088 end 0089 0090 0091 % Now look at the model 0092 name = get(pzm, 'name'); 0093 gain = get(pzm, 'gain'); 0094 poles = get(pzm, 'poles'); 0095 zeros = get(pzm, 'zeros'); 0096 np = length(poles); 0097 nz = length(zeros); 0098 0099 %% check inputs 0100 0101 if nargin == 1 0102 %% a = resp(pzm); %% 0103 pl = getDefaultPL(pzm); 0104 0105 elseif nargin == 2 0106 if isa(varargin{2}, 'plist') 0107 %% a = resp(pzm, plist); %% 0108 pl = varargin{2}; 0109 if ~isempty(find(pl, 'f')) 0110 pl = combine(pl, getDefaultPL('List')); 0111 else 0112 pl = combine(pl, getDefaultPL('Range')); 0113 end 0114 else 0115 %% a = resp(pzm, f); %% 0116 f = varargin{2}; 0117 pl = plist('f',f); 0118 end 0119 elseif nargin == 4 0120 %% a = resp(pzm, f1, f2, nf); %% 0121 f1 = varargin{2}; 0122 f2 = varargin{3}; 0123 nf = varargin{4}; 0124 0125 pl = plist('f1',f1,... 0126 'f2',f2,... 0127 'nf',nf, ... 0128 'scale', 'lin'); 0129 0130 else 0131 error('### incorrect number of inputs.'); 0132 end 0133 0134 0135 %% Compute or extract the frequency vector 0136 if ~isempty(find(pl, 'f')) 0137 % Compute from frequency list 0138 f = find(pl, 'f'); 0139 % Want to deal with rows 0140 if size(f,1) > 1 0141 f = f.'; 0142 end 0143 else 0144 % Compute from frequency range 0145 f1 = find(pl, 'f1'); 0146 f2 = find(pl, 'f2'); 0147 nf = find(pl, 'nf'); 0148 scale = find(pl, 'scale'); 0149 switch scale 0150 case 'lin' 0151 f = linspace(f1, f2, nf); 0152 case 'log' 0153 f = logspace(log10(f1), log10(f2), nf); 0154 end 0155 0156 end 0157 0158 %% make output plist 0159 plo = combine(plist('pzmodel', pzm), pl); 0160 0161 0162 %% Now compute the response 0163 r = gain; 0164 for j=1:np 0165 if ~isnan(poles(j).f) 0166 [f, pr] = resp(poles(j),f); 0167 r = r .* pr; 0168 end 0169 end 0170 for j=1:nz 0171 if ~isnan(zeros(j).f) 0172 [f, zr] = resp(zeros(j),f); 0173 r = r .* zr; 0174 end 0175 end 0176 0177 %% ---------- Build output ao 0178 0179 % create new output fsdata 0180 fs = fsdata(f, r, 1); 0181 fs = set(fs, 'name', sprintf('resp(%s)', name)); 0182 0183 % create new output history 0184 h = history(ALGONAME, VERSION, plo); 0185 0186 % make output analysis object 0187 b = ao(fs, h); 0188 0189 % set name 0190 b = setnh(b, 'name', sprintf('resp(%s)', name), ... 0191 'mfilename', ALGONAME); 0192 0193 % Outputs 0194 if nargout == 0 0195 iplot(b) 0196 elseif nargout == 1 0197 varargout{1} = b; 0198 else 0199 error('### incorrect output arguments'); 0200 end 0201 0202 0203 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0204 % 0205 % FUNCTION: getDefaultPL 0206 % 0207 % DESCRIPTION: Get default params 0208 % 0209 % HISTORY: 20-02-2008 M Hueller 0210 % Creation 0211 % 0212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0213 function plo = getDefaultPL(varargin) 0214 0215 % List of available parameter sets 0216 sets = {'List', 'Range'}; 0217 0218 if nargin == 0 0219 plo = sets; 0220 return 0221 end 0222 0223 set = varargin{1}; 0224 0225 if isa(set, 'pzmodel') 0226 f1 = getlowerFreq(set)/10; 0227 f2 = getupperFreq(set)*10; 0228 nf = 10000; 0229 scale = 'lin'; 0230 plo = plist('f1', f1,... 0231 'f2', f2,... 0232 'nf', nf,... 0233 'scale', scale); 0234 else 0235 switch set 0236 case 'List' 0237 plo = plist('f', []); 0238 case 'Range' 0239 plo = plist('f1', 0.001,... 0240 'f2', 1,... 0241 'nf', 10000,... 0242 'scale', 'lin'); 0243 otherwise 0244 plo = plist(); 0245 end 0246 end 0247 0248 % END 0249 0250