function b = fireqint(N,L,alpha,W)
%FIREQINT Equiripple interpolation FIR filter design.

%   Copyright 1999-2023 The MathWorks, Inc.

% Check for arguments data types and number of arguments
narginchk(3,4);

validateattributes(L,'double', {'scalar','nonempty','real','nonnan','finite'}, ...
    'fireqint','L');

validateattributes(alpha,'double', {'scalar','nonempty','real','nonnan','finite'}, ...
    'fireqint','alpha');

% Some error checking
if (iscell(N) || dsp.util.isChar(N)) && nargin < 4
    error(message('dsp:fireqint:nodevs'));
end

if dsp.util.isChar(N)
    N = char(N);
end

if iscell(N)
    if dsp.util.isChar(N{1})
        N{1} = char(N{1});
    end
    % Check initial order is an integer
    if N{2} ~= round(N{2})
        error(message('dsp:fireqint:nonIntInitOrd'));
    end
end

if ~iscell(N)
    if N ~= round(N)
        error(message('dsp:fireqint:nonIntOrd'));
    end
end

if L ~= round(L)
	error(message('dsp:fireqint:nonIntL'));
end

if alpha <= 0  || alpha >= 1
	error(message('dsp:fireqint:alpha0t1'));
end

if nargin > 3 
    validateattributes(W,'double',{'nonempty','real','nonnan','finite'}, ...
    'fireqint','W');
    if(length(W) ~= floor(L/2) + 1)
        error(message('dsp:fireqint:wronglengthw'));
    end
end

% Determine length of F
lf = L+2;
lastf = 1;
if rem(L,2)
    lastf=[];
end

fpartialedges = (alpha+0:2:lf-2)/L;
fpartialedges2 = (-alpha+2:2:lf-2)/L;

% Determine frequency vector
F = sort([0,fpartialedges,fpartialedges2,lastf]);

% Determine magnitude vector
A = [1 1 zeros(1,length(F)-2)];

if nargin < 4
    W = ones(1,length(A)/2); 
end

% If L is odd, estimate the order with the previous even factor first
if rem(L,2) && dsp.util.isChar(N)
    btemp = fireqint(char(N),L-1,alpha,W);
    N = {'minorder',length(btemp)-1};
end
    
b = L*firgr(N,F,A,W/L);

