Home > classes > @miir > resp.m

resp

PURPOSE ^

RESP Make a frequency response of the filter.

SYNOPSIS ^

function [varargout] = resp(varargin)

DESCRIPTION ^

 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.5 2007/12/10 18:07:17 ingo Exp $

 NOTE:    Some of the code below is taken from Mathworks's treeplot.m

 HISTORY: 27-08-02 M Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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.5 2007/12/10 18:07:17 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.5 2007/12/10 18:07:17 ingo Exp $';
0044 
0045 % 'Params' Call
0046 if nargin == 2
0047   if isa(varargin{1}, 'miir') && strcmp(varargin{2}, 'Params')
0048     varargout{1} = plist();
0049     return
0050   elseif isa(varargin{1}, 'miir') && strcmp(varargin{2}, 'Version')
0051     varargout{1} = VERSION;
0052     return
0053   end
0054 end
0055 
0056 % get input filter
0057 filt = varargin{1};
0058 if ~isa(filt, 'miir')
0059   error('### first input must be an miir filter object.');
0060 end
0061 
0062 
0063 % create empty input if it is not specified
0064 if nargin == 1
0065   pl = plist();
0066 else
0067   pl = varargin{2};
0068 end
0069 
0070 % create empty output parameter list
0071 plo = plist();
0072 
0073 % parse input parameter list
0074 f1    = find(pl, 'f1');
0075 f2    = find(pl, 'f2');
0076 ndata = find(pl, 'nf');
0077 f     = find(pl, 'f');
0078 
0079 % fill parameter list
0080 if isempty(f)
0081 
0082   % we look for the other parameter set
0083   if isempty(f1)
0084     f1 = 0;
0085   end
0086   plo = append(plo, param('f1', f1));
0087   % we look for the other parameter set
0088   if isempty(f2)
0089     f2 = filt.fs/2;
0090   end
0091   plo = append(plo, param('f2', f2));
0092   % we look for the other parameter set
0093   if isempty(ndata)
0094     ndata = 1000;
0095   end
0096   plo = append(plo, param('nf', ndata));
0097 
0098   % compute f from this
0099   f   = linspace(f1, f2, ndata);
0100   plo = append(plo, param('f', f));
0101 else
0102   plo = append(plo, param('f', f));
0103 
0104   ndata = length(f);
0105 
0106 end
0107 
0108 % append input filter to output parameter list
0109 plo = append(plo, param('filter', filt));
0110 
0111 % compute Laplace vector
0112 s = -1i.*2*pi.*f;
0113 
0114 % Compute filter response
0115 num = zeros(1, ndata);
0116 for n=1:length(filt.a)
0117   num = num + filt.a(n).*exp(s.*(n-1)/filt.fs);
0118 end
0119 denom = zeros(1, ndata);
0120 for n=1:length(filt.b)
0121   denom = denom + filt.b(n).*exp(s.*(n-1)/filt.fs);
0122 end
0123 dresp = num ./ denom;
0124 dresp = dresp .* filt.gain;  % apply the gain
0125 
0126 % mag   = 20*log10(abs(dresp));
0127 % phase = angle(dresp)*180/pi;
0128 
0129 %-----------------------------------------------------------
0130 % Create an analysis object
0131 
0132 % create new output fsdata
0133 fs = fsdata(f, dresp, filt.fs);
0134 fs = set(fs, 'name', sprintf('resp(%s)', filt.name));
0135 
0136 % create new output history
0137 h = history(ALGONAME, VERSION, plo);
0138 
0139 % make output analysis object
0140 b = ao(fs, h);
0141 
0142 % set name
0143 b = setnh(b, 'name', sprintf('resp(%s)', filt.name));
0144 
0145 % Outputs
0146 if nargout == 0
0147   plot(b)
0148 end
0149 
0150 if nargout == 1
0151   varargout{1} = b;
0152 end
0153 if nargout > 1
0154   error('incorrect output arguments');
0155 end
0156 
0157

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003