RESP Make a frequency response of the filter. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: RESP Make a frequency response of the filter. The input filter should be an miir object. The response is returned as a frequency-series in an analysis object. If no outputs are specified, the frequency-series is plotted as mag/deg. CALL: a = resp(filt, pl) resp(filt, pl); PARAMETERS: 'f1' - the start frequency 'f2' - the stop frequency 'nf' - number of evaluation points 'scale' - spacing of frequencies: 'lin' or 'log' or 'f' - a vector of frequency values OUTPUTS: a - an analysis object The response is calculated as: a0 + a1*exp(s/fs) + ... + an*exp((n-1)s/fs) H(s) = gain * --------------------------------------------- b0 + b1*exp(s/fs) + ... + bm*exp((m-1)s/fs) M-FILE INFO: Get information about this methods by calling >> miir.getInfo('resp') Get information about a specified set-plist by calling: >> miir.getInfo('resp', 'List') VERSION: $Id: resp.m,v 1.20 2008/09/04 15:29:31 ingo Exp $ NOTE: Some of the code below is taken from Mathworks's treeplot.m HISTORY: 27-08-02 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % RESP Make a frequency response of the filter. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: RESP Make a frequency response of the filter. 0005 % The input filter should be an miir object. 0006 % 0007 % The response is returned as a frequency-series in an 0008 % analysis object. 0009 % 0010 % If no outputs are specified, the frequency-series is plotted as 0011 % mag/deg. 0012 % 0013 % CALL: a = resp(filt, pl) 0014 % resp(filt, pl); 0015 % 0016 % PARAMETERS: 'f1' - the start frequency 0017 % 'f2' - the stop frequency 0018 % 'nf' - number of evaluation points 0019 % 'scale' - spacing of frequencies: 'lin' or 'log' 0020 % or 0021 % 'f' - a vector of frequency values 0022 % 0023 % OUTPUTS: 0024 % a - an analysis object 0025 % 0026 % The response is calculated as: 0027 % 0028 % a0 + a1*exp(s/fs) + ... + an*exp((n-1)s/fs) 0029 % H(s) = gain * --------------------------------------------- 0030 % b0 + b1*exp(s/fs) + ... + bm*exp((m-1)s/fs) 0031 % 0032 % M-FILE INFO: Get information about this methods by calling 0033 % >> miir.getInfo('resp') 0034 % 0035 % Get information about a specified set-plist by calling: 0036 % >> miir.getInfo('resp', 'List') 0037 % 0038 % VERSION: $Id: resp.m,v 1.20 2008/09/04 15:29:31 ingo Exp $ 0039 % 0040 % NOTE: Some of the code below is taken from Mathworks's treeplot.m 0041 % 0042 % HISTORY: 27-08-02 M Hewitson 0043 % Creation 0044 % 0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0046 0047 function varargout = resp(varargin) 0048 0049 %%% Check if this is a call for parameters 0050 if utils.helper.isinfocall(varargin{:}) 0051 varargout{1} = getInfo(varargin{3}); 0052 return 0053 end 0054 0055 %%% get input filter 0056 filt = varargin{1}; 0057 if ~isa(filt, 'miir') 0058 error('### first input must be an miir filter object.'); 0059 end 0060 0061 %%% Collects parameters 0062 % create empty input if it is not specified 0063 if nargin == 1 0064 pl = plist(); 0065 else 0066 pl = varargin{2}; 0067 end 0068 0069 % parse input parameter list 0070 if ~isempty(find(pl, 'f')) 0071 pl = combine(pl, getDefaultPlist('List')); 0072 else 0073 pl = combine(pl, getDefaultPlist('Range')); 0074 end 0075 0076 % fill parameter list 0077 reshape_f = false; 0078 if isempty(find(pl, 'f')) 0079 % Compute from frequency range 0080 f1 = find(pl, 'f1'); 0081 f2 = find(pl, 'f2'); 0082 ndata = find(pl, 'nf'); 0083 scale = find(pl, 'scale'); 0084 0085 % Set frequencies 0086 if f1 < 0 0087 f1 = filt.fs/1000; 0088 end 0089 if f2 < 0 0090 f2 = filt.fs/2-1/ndata; 0091 end 0092 switch scale 0093 case 'lin' 0094 f = linspace(f1, f2, ndata); 0095 case 'log' 0096 f = logspace(log10(f1), log10(f2), ndata); 0097 end 0098 else 0099 % Compute from frequency list 0100 f = find(pl, 'f'); 0101 % Want to deal with rows 0102 reshape_f = false; 0103 if size(f,1) > 1 0104 f = f.'; 0105 reshape_f = true; 0106 end 0107 ndata = length(f); 0108 end 0109 0110 % create output parameter list, with the frequency array values and the 0111 % input filter 0112 plo = plist('f', f, 'filter', filt); 0113 0114 %%% compute Laplace vector 0115 s = -1i.*2*pi.*f; 0116 0117 %%% Compute filter response 0118 num = zeros(1, ndata); 0119 for n=1:length(filt.a) 0120 num = num + filt.a(n).*exp(s.*(n-1)/filt.fs); 0121 end 0122 denom = zeros(1, ndata); 0123 for n=1:length(filt.b) 0124 denom = denom + filt.b(n).*exp(s.*(n-1)/filt.fs); 0125 end 0126 dresp = num ./ denom; 0127 0128 % mag = 20*log10(abs(dresp)); 0129 % phase = angle(dresp)*180/pi; 0130 0131 %%% Create an analysis object 0132 if reshape_f 0133 f = f.'; 0134 dresp = dresp.'; 0135 end 0136 0137 % create new output fsdata 0138 fs = fsdata(f, dresp, filt.fs); 0139 0140 % make output analysis object 0141 b = ao(fs); 0142 0143 % Add history 0144 b.addHistory(getInfo, plo, [], filt.hist); 0145 0146 % set name 0147 b.setName(sprintf('resp(%s)', filt.name), 'internal'); 0148 0149 % Outputs 0150 if nargout == 0 0151 iplot(b) 0152 end 0153 0154 if nargout == 1 0155 varargout{1} = b; 0156 end 0157 if nargout > 1 0158 error('incorrect output arguments'); 0159 end 0160 end 0161 0162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0163 % Local Functions % 0164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0165 0166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0167 % 0168 % FUNCTION: getInfo 0169 % 0170 % DESCRIPTION: Get Info Object 0171 % 0172 % HISTORY: 11-07-07 M Hewitson 0173 % Creation. 0174 % 0175 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0176 0177 function ii = getInfo(varargin) 0178 if nargin == 1 && strcmpi(varargin{1}, 'None') 0179 sets = {}; 0180 pls = []; 0181 elseif nargin == 1&& ~isempty(varargin{1}) && ischar(varargin{1}) 0182 sets{1} = varargin{1}; 0183 pls = getDefaultPlist(sets{1}); 0184 else 0185 sets = {'List', 'Range'}; 0186 pls = []; 0187 for kk=1:numel(sets) 0188 pls = [pls getDefaultPlist(sets{kk})]; 0189 end 0190 end 0191 % Build info object 0192 ii = minfo(mfilename, 'miir', '', utils.const.categories.sigproc, '$Id: resp.m,v 1.20 2008/09/04 15:29:31 ingo Exp $', sets, pls); 0193 end 0194 0195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0196 % 0197 % FUNCTION: getDefaultPlist 0198 % 0199 % DESCRIPTION: Get Default Plist 0200 % 0201 % HISTORY: 11-07-07 M Hewitson 0202 % Creation. 0203 % 0204 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0205 0206 function plo = getDefaultPlist(set) 0207 switch set 0208 case 'List' 0209 plo = plist('f', []); 0210 case 'Range' 0211 plo = plist('f1', -1, 'f2', -1, 'nf', 1000, 'scale', 'log'); 0212 otherwise 0213 error('### Unknown set [%s] for a default list.', set); 0214 end 0215 end 0216