RESP returns the complex response of the zero object. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: RESP returns the complex response of the zero object. CALL: [f,r] = resp(z, f); % compute response for vector f [f,r] = resp(z, f1, f2, nf); % compute response from f1 to f2 % in nf steps. [f,r] = resp(z, pl); % compute response from parameter list. [f,r] = resp(z); % 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(zero, 'Params') The following call returns a parameter list object that contains the default parameters for the jj-th set: >> pl = resp(zero, 'Params', sets{jj}) The following call returns a string that contains the routine CVS version: >> version = resp(zero, 'Version') The following call returns a string that contains the routine category: >> category = resp(zero, 'Category') VERSION: $Id: resp.m,v 1.9 2008/02/24 21:43:59 mauro Exp $ HISTORY: 03-04-2007 Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [f,r] = resp(varargin) 0002 % RESP returns the complex response of the zero object. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: RESP returns the complex response of the zero object. 0007 % 0008 % CALL: [f,r] = resp(z, f); % compute response for vector f 0009 % [f,r] = resp(z, f1, f2, nf); % compute response from f1 to f2 0010 % % in nf steps. 0011 % [f,r] = resp(z, pl); % compute response from parameter list. 0012 % [f,r] = resp(z); % 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(zero, '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(zero, 'Params', sets{jj}) 0038 % 0039 % The following call returns a string that contains the routine CVS version: 0040 % 0041 % >> version = resp(zero, 'Version') 0042 % 0043 % The following call returns a string that contains the routine category: 0044 % 0045 % >> category = resp(zero, 'Category') 0046 % 0047 % 0048 % VERSION: $Id: resp.m,v 1.9 2008/02/24 21:43:59 mauro Exp $ 0049 % 0050 % HISTORY: 03-04-2007 Hewitson 0051 % Creation 0052 % 0053 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0054 0055 VERSION = '$Id: resp.m,v 1.9 2008/02/24 21:43:59 mauro Exp $'; 0056 CATEGORY = 'Signal Processing'; 0057 0058 %% 'Params', 'Version' and 'Category' Call 0059 if (nargin == 2 || nargin == 3) && ... 0060 isa(varargin{1}, 'zero') && ... 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 z = varargin{1}; 0086 if ~isa(z, 'zero') 0087 error('### first argument should be a zero object.'); 0088 end 0089 0090 0091 % Now look at the zero 0092 f0 = get(z, 'f'); 0093 Q = get(z, 'q'); 0094 0095 0096 0097 %% check inputs 0098 0099 if nargin == 1 0100 %% a = resp(z); %% 0101 pl = getDefaultPL(z); 0102 0103 elseif nargin == 2 0104 if isa(varargin{2}, 'plist') 0105 %% a = resp(z, 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(z, f); %% 0114 f = varargin{2}; 0115 pl = plist('f',f); 0116 end 0117 elseif nargin == 4 0118 %% a = resp(z, 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 = complex(re, im); 0162 else 0163 re = 1; 0164 im = f./f0; 0165 r = complex(re, im); 0166 end 0167 0168 0169 0170 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0171 % 0172 % FUNCTION: getDefaultPL 0173 % 0174 % DESCRIPTION: Get default params 0175 % 0176 % HISTORY: 20-02-2008 M Hueller 0177 % Creation 0178 % 0179 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0180 function plo = getDefaultPL(varargin) 0181 0182 % List of available parameter sets 0183 sets = {'List', 'Range'}; 0184 0185 if nargin == 0 0186 plo = sets; 0187 return 0188 end 0189 0190 set = varargin{1}; 0191 0192 if isa(set, 'zero') 0193 f1 = get(set, 'f')/10; 0194 f2 = get(set, 'f')*10; 0195 nf = 1000; 0196 scale = 'lin'; 0197 plo = plist('f1', f1,... 0198 'f2', f2,... 0199 'nf', nf,... 0200 'scale', scale); 0201 else 0202 switch set 0203 case 'List' 0204 plo = plist('f', []); 0205 case 'Range' 0206 plo = plist('f1', 0.001,... 0207 'f2', 1,... 0208 'nf', 1000,... 0209 'scale', 'lin'); 0210 otherwise 0211 plo = plist(); 0212 end 0213 end 0214 0215 % END