function G = qfilt2dfilt(G)
%QFILT2DFILT  Convert QFILT object to DFILT object
%   G = QFILT2DFILT(Hq) converts QFILT object Hq to DFILT object G.

%   Thomas A. Bryan
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.9 $  $Date: 2000/05/19 18:45:23 $ 

% If already a dfilt, then return.
if isa(G,'dfilt')
  return
end

% The only other thing we know how to translate is a qfilt, so if it isn't
% that, then error.
if ~isa(G,'qfilt')
  error('Unrecognized filter type.')
end

if prod(scalevalues(G)) ~=1
  warning('Scale values are not applied to unquantized filter');
end


%fstruc = class(G);
fstruc = filterstructure(G);
c = referencecoefficients(G);
% Wrap the coefficient cell array as a cell off cells, e.g.,
% convert {b,a} to {{b,a}}, which is what dfilt expects.
if ~isempty(c) & iscell(c) & isnumeric(c{1})
    c = {c};
end
switch fstruc
case {'df1','df1t','df2','df2t'}
    % c = {num,den} or c = {{num1,den1},{num2,den2},...}
    G = feval(fstruc,c);
case 'latticeca'
    % latticeca: c = {k1,k2,beta}
    G = latcca(c{1}{:});
case 'latticecapc'
    % latticecapc: c = {k1,k2,beta}
    G = latccapc(c{1}{:});
case 'latticearma'
    % latticearma: c = {k,v}
    G =latcarma(c);
case 'latticema'
    % latticema:   c = {k}
    G = latcma(c);
case 'latcmax'
    % latcmax:     c = {k}
    G = latcmax(c);
case 'latcallpass'
    % latcallpass:     c = {k}
    G = latcallpass(c);
case 'latticear'
    % latticear:     c = {k}
    G = latcarma(c{1},1);
case 'statespace'
    % statespace:  c = {A,B,C,D}
    G = ssd(c);
case 'fir'
    % direct form FIR: c = {num}
    G = dffir(c);
case 'firt'
    % direct form transposed FIR: c = {num}
    G = dftfir(c);
case 'symmetricfir',
    % symmetric direct form FIR: c = {num}
    G = dfsymfir(c);
case 'antisymmetricfir'
    % antisymmetric direct form FIR: c = {num}
    G = dfasymfir(c);
otherwise
    error('Unrecognized filter structure.')
end
