RESP returns the complex response of the pole object. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: RESP returns the complex response of the pole object. CALL: [f,r] = resp(p, f); % compute response for vector f [f,r] = resp(p, f1, f2, nf); % compute response from f1 to f2 % in nf steps. [f,r] = resp(p, pl); % compute response from parameter list. [f,r] = resp(p); % compute response REMARK: This is just a helper function. This function should only be called from class functions. 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(pole, 'Params') The following call returns a parameter list object that contains the default parameters for the jj-th set: >> pl = resp(pole, 'Params', sets{jj}) The following call returns a string that contains the routine CVS version: >> version = resp(pole, 'Version') The following call returns a string that contains the routine category: >> category = resp(pole, 'Category') VERSION: $Id: resp.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $ HISTORY: 03-04-2007 Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [f,r] = resp(varargin) 0002 % RESP returns the complex response of the pole object. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: RESP returns the complex response of the pole object. 0007 % 0008 % CALL: [f,r] = resp(p, f); % compute response for vector f 0009 % [f,r] = resp(p, f1, f2, nf); % compute response from f1 to f2 0010 % % in nf steps. 0011 % [f,r] = resp(p, pl); % compute response from parameter list. 0012 % [f,r] = resp(p); % compute response 0013 % 0014 % REMARK: This is just a helper function. This function should only be 0015 % called from class functions. 0016 % 0017 % PARAMETERS: 'f' - a vector of frequencies to evaluate at 0018 % or 0019 % 'f1' - start frequency 0020 % 'f2' - stop frequency 0021 % 'nf' - number of evaluation frequencies 0022 % 'scale' - spacing of frequencies: 'lin' or 'log' 0023 % 0024 % These parameters (one or more) can be defined via a plist, 0025 % with the params keys named in the same way as above 0026 % 0027 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0028 % 0029 % The following call returns a cell array that contains the default parameter 0030 % sets names: 0031 % 0032 % >> sets = resp(pole, 'Params') 0033 % 0034 % The following call returns a parameter list object that contains the 0035 % default parameters for the jj-th set: 0036 % 0037 % >> pl = resp(pole, 'Params', sets{jj}) 0038 % 0039 % The following call returns a string that contains the routine CVS version: 0040 % 0041 % >> version = resp(pole, 'Version') 0042 % 0043 % The following call returns a string that contains the routine category: 0044 % 0045 % >> category = resp(pole, 'Category') 0046 % 0047 % 0048 % VERSION: $Id: resp.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $ 0049 % 0050 % HISTORY: 03-04-2007 Hewitson 0051 % Creation 0052 % 0053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0054 0055 VERSION = '$Id: resp.html,v 1.14 2008/03/31 10:27:38 hewitson Exp $'; 0056 CATEGORY = 'Signal Processing'; 0057 0058 %% 'Params', 'Version' and 'Category' Call 0059 if (nargin == 2 || nargin == 3) && ... 0060 isa(varargin{1}, 'pole') && ... 0061 ischar(varargin{2}) 0062 in = char(varargin{2}); 0063 if strcmp(in, 'Params') 0064 if nargin == 2 0065 f = getDefaultPL(); 0066 else 0067 f = getDefaultPL(varargin{3}); 0068 end 0069 return 0070 elseif strcmp(in, 'Version') 0071 f = VERSION; 0072 return 0073 elseif strcmp(in, 'Category') 0074 f = 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 p = varargin{1}; 0086 if ~isa(p, 'pole') 0087 error('### first argument should be a pole object.'); 0088 end 0089 0090 0091 % Now look at the pole 0092 f0 = get(p, 'f'); 0093 Q = get(p, 'q'); 0094 0095 0096 0097 %% check inputs 0098 0099 if nargin == 1 0100 %% a = resp(p); %% 0101 pl = getDefaultPL(p); 0102 0103 elseif nargin == 2 0104 if isa(varargin{2}, 'plist') 0105 %% a = resp(p, plist); %% 0106 pl = varargin{2}; 0107 if ~isempty(find(pl, 'f')) 0108 pl = combine(pl, getDefaultPL('List')); 0109 else 0110 pl = combine(pl, getDefaultPL('Range')); 0111 end 0112 else 0113 %% a = resp(p, f); %% 0114 f = varargin{2}; 0115 pl = plist('f',f); 0116 end 0117 elseif nargin == 4 0118 %% a = resp(p, f1, f2, nf); %% 0119 f1 = varargin{2}; 0120 f2 = varargin{3}; 0121 nf = varargin{4}; 0122 0123 pl = plist('f1',f1,... 0124 'f2',f2,... 0125 'nf',nf, ... 0126 'scale', 'lin'); 0127 0128 else 0129 error('### incorrect number of inputs.'); 0130 end 0131 0132 0133 %% Compute or extract the frequency vector 0134 if ~isempty(find(pl, 'f')) 0135 % Compute from frequency list 0136 f = find(pl, 'f'); 0137 % Want to deal with rows 0138 if size(f,1) > 1 0139 f = f.'; 0140 end 0141 else 0142 % Compute from frequency range 0143 f1 = find(pl, 'f1'); 0144 f2 = find(pl, 'f2'); 0145 nf = find(pl, 'nf'); 0146 scale = find(pl, 'scale'); 0147 switch scale 0148 case 'lin' 0149 f = linspace(f1, f2, nf); 0150 case 'log' 0151 f = logspace(log10(f1), log10(f2), nf); 0152 end 0153 0154 end 0155 0156 0157 %% Now compute the response 0158 if Q>=0.5 0159 re = 1 - (f.^2./f0^2); 0160 im = f ./ (f0*Q); 0161 r = 1./complex(re, im); 0162 else 0163 re = 1; 0164 im = f./f0; 0165 r = 1./complex(re, im); 0166 end 0167 0168 0169 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0170 % 0171 % FUNCTION: getDefaultPL 0172 % 0173 % DESCRIPTION: Get default params 0174 % 0175 % HISTORY: 20-02-2008 M Hueller 0176 % Creation 0177 % 0178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0179 function plo = getDefaultPL(varargin) 0180 0181 % List of available parameter sets 0182 sets = {'List', 'Range'}; 0183 0184 if nargin == 0 0185 plo = sets; 0186 return 0187 end 0188 0189 set = varargin{1}; 0190 0191 if isa(set, 'pole') 0192 f1 = get(set, 'f')/10; 0193 f2 = get(set, 'f')*10; 0194 nf = 1000; 0195 scale = 'lin'; 0196 plo = plist('f1', f1,... 0197 'f2', f2,... 0198 'nf', nf,... 0199 'scale', scale); 0200 else 0201 switch set 0202 case 'List' 0203 plo = plist('f', []); 0204 case 'Range' 0205 plo = plist('f1', 0.001,... 0206 'f2', 1,... 0207 'nf', 10000,... 0208 'scale', 'lin'); 0209 otherwise 0210 plo = plist(); 0211 end 0212 end 0213 0214 % END