Home > classes > @mfir > 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 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, f);
              a = 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:

          H(s) = gain * (a0 + a1*exp(s/fs) + ... + an*exp((n-1)s/fs))

 M-FILE INFO: Get information about this methods by calling
              >> mfir.getInfo('resp')

              Get information about a specified set-plist by calling:
              >> mfir.getInfo('resp', 'List')

 VERSION:     $Id: resp.m,v 1.20 2008/09/04 15:29:30 ingo Exp $

 HISTORY:     27-08-02 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003