


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