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 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) VERSION: $Id: resp.m,v 1.2 2007/06/07 08:51:26 ingo Exp $ NOTE: Some of the code below is taken from Mathworks's treeplot.m HISTORY: 27-08-02 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function [varargout] = resp(varargin) 0002 % RESP Make a frequency response of the filter. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: RESP Make a frequency response of the filter. 0007 % The input filter should be an miir object. 0008 % 0009 % The response is returned as a frequency-series in an 0010 % analysis object. 0011 % 0012 % If no outputs are specified, the frequency-series is plotted as 0013 % mag/deg. 0014 % 0015 % CALL: a = resp(filt, pl) 0016 % resp(filt, pl); 0017 % 0018 % PARAMETERS: f1 - the start frequency 0019 % f2 - the stop frequency 0020 % nf - number of evaluation points 0021 % or 0022 % f - a vector of frequency values 0023 % 0024 % OUTPUTS: 0025 % a - an analysis object 0026 % 0027 % The response is calculated as: 0028 % 0029 % a0 + a1*exp(s/fs) + ... + an*exp((n-1)s/fs) 0030 % H(s) = gain * --------------------------------------------- 0031 % b0 + b1*exp(s/fs) + ... + bm*exp((m-1)s/fs) 0032 % 0033 % VERSION: $Id: resp.m,v 1.2 2007/06/07 08:51:26 ingo Exp $ 0034 % 0035 % NOTE: Some of the code below is taken from Mathworks's treeplot.m 0036 % 0037 % HISTORY: 27-08-02 M Hewitson 0038 % Creation 0039 % 0040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0041 0042 ALGONAME = mfilename; 0043 VERSION = '$Id: resp.m,v 1.2 2007/06/07 08:51:26 ingo Exp $'; 0044 0045 % get input filter 0046 filt = varargin{1}; 0047 if ~isa(filt, 'miir') 0048 error('### first input must be an miir filter object.'); 0049 end 0050 0051 0052 % create empty input if it is not specified 0053 if nargin == 1 0054 pl = plist(); 0055 else 0056 pl = varargin{2}; 0057 end 0058 0059 % create empty output parameter list 0060 plo = plist(); 0061 0062 % parse input parameter list 0063 f1 = find(pl, 'f1'); 0064 f2 = find(pl, 'f2'); 0065 ndata = find(pl, 'nf'); 0066 f = find(pl, 'f'); 0067 0068 % fill parameter list 0069 if isempty(f) 0070 0071 % we look for the other parameter set 0072 if isempty(f1) 0073 f1 = 0; 0074 end 0075 plo = append(plo, param('f1', f1)); 0076 % we look for the other parameter set 0077 if isempty(f2) 0078 f2 = filt.fs/2; 0079 end 0080 plo = append(plo, param('f2', f2)); 0081 % we look for the other parameter set 0082 if isempty(ndata) 0083 ndata = 1000; 0084 end 0085 plo = append(plo, param('nf', ndata)); 0086 0087 % compute f from this 0088 f = linspace(f1, f2, ndata); 0089 else 0090 plo = append(plo, param('f', f)); 0091 0092 ndata = length(f); 0093 0094 end 0095 0096 % append input filter to output parameter list 0097 plo = append(plo, param('filter', filt)); 0098 0099 % compute Laplace vector 0100 s = -1i.*2*pi.*f; 0101 0102 % Compute filter response 0103 num = zeros(1, ndata); 0104 for n=1:length(filt.a) 0105 num = num + filt.a(n).*exp(s.*(n-1)/filt.fs); 0106 end 0107 denom = zeros(1, ndata); 0108 for n=1:length(filt.b) 0109 denom = denom + filt.b(n).*exp(s.*(n-1)/filt.fs); 0110 end 0111 dresp = num ./ denom; 0112 dresp = dresp .* filt.g; % apply the gain 0113 0114 % mag = 20*log10(abs(dresp)); 0115 % phase = angle(dresp)*180/pi; 0116 0117 %----------------------------------------------------------- 0118 % Create an analysis object 0119 0120 % create new output fsdata 0121 fs = fsdata(f, dresp, filt.fs); 0122 fs = set(fs, 'name', sprintf('resp(%s)', filt.name)); 0123 0124 % create new output history 0125 h = history(ALGONAME, VERSION, plo); 0126 0127 % make output analysis object 0128 b = ao(fs, h); 0129 0130 % set name 0131 b = set(b, 'name', sprintf('resp(%s)', filt.name)); 0132 0133 % Outputs 0134 if nargout == 0 0135 plot(b) 0136 end 0137 0138 if nargout == 1 0139 varargout{1} = b; 0140 end 0141 if nargout > 1 0142 error('incorrect output arguments'); 0143 end 0144 0145