% Construct an mfir from a pzmodel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromPzmodel
%
% DESCRIPTION: Construct an mfir from a pzmodel
%
% CALL:        f = fromPzmodel(f, pli)
%
% PARAMETER:   type:     String with filter type description
%              pli:       Parameter list object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function f = fromPzmodel(f, pli)
  
  VERSION = '$Id: fromPzmodel.m,v 1.15 2011/08/15 11:43:01 hewitson Exp $';
  ii = mfir.getInfo('mfir', 'From Pzmodel');
  % Set the method version string in the minfo object
  ii.setMversion([VERSION '-->' ii.mversion]);
  
  % Add default values
  pl = applyDefaults(ii.plists, pli);
  
  % Get parameters
  pzm = find(pl, 'pzmodel');
  fs  = find(pl, 'fs');
  
  if isempty(fs)
    % get max freq in pzmodel
    fs = 8*getupperFreq(pzm);
    warning([sprintf('!!! no sample rate specified. Designing for fs=%2.2f Hz.', fs)...
      sprintf('\nThe filter will be redesigned later when used.')]);
  end
  % make MIIR filter
  f = tomfir(pzm, plist('fs', fs));
  
  % override default input plist values
  if isempty(pl.find('name'))
    pl.pset('name', sprintf('fir(%s)', pzm.name));
  end
  if isempty(pl.find('description'))
    pl.pset('description', pzm.description);
  end
  if isempty(pl.find('iunits'))
    pl.pset('iunits', pzm.iunits);
  end
  if isempty(pl.find('ounits'))
    pl.pset('ounits', pzm.ounits);
  end
  
  % Add history
  f.addHistory(ii, pl, [], pzm.hist);
  
  % Set remaining properties
  f.setObjectProperties(pl);
  
end % End fromPzmodel
