function [b,a,error,sos,h0] = iirlpnorm(numOrd,denOrd,f,edges,des,varargin)
%IIRLPNORM Least P-norm optimal IIR filter design.

%   References:
%     [1] A. Antoniou, Digital Filters:  Analysis, Design, and Applications,
%         2nd ed., McGraw-Hill, 1993.

%   Copyright 1999-2022 The MathWorks, Inc.

myArgin = varargin;
if nargin > 6
   myArgin = {myArgin{1} 0.9 myArgin{2:end}};  % To satisfy iirparser.
end

% Parse the input
s = iirparser(1,numOrd,denOrd,f,edges,des,myArgin{:});

% Design the filter
[bs,as,h0,error] = filterdesign.internal.iirlpnormmex(s.numOrd,s.denOrd,s.edges,s.f,...
    s.des,s.wt,s.P,s.density,s.Ho,s.BS,s.AS);

% If any of the returned coefficients is not finite, throw an error.
coder.internal.errorIf(~(all(isfinite(bs)) && all(isfinite(as))),'dsp:iirlpnorm:NonFiniteCoeffs')

% Compute the transfer function and the sos matrix. h0 is sos gain
[b,a,sos] = computetfandsos(s.numOrd,s.denOrd,bs,as,h0);
