function islinphaseflag = islinphase(f,sec)
%ISLINPHASE  Determine if filter object has linear phase sections.
%   FLAG = ISLINPHASE(F) determines if the filter object F has
%   linear phase sections, and returns 1 if true and 0 if false.
%
%   FLAG = ISLINPHASE(F,I) determines if the I-th section of the
%   filter object F is a linear phase section and returns 1 if true
%   and 0 if false. 

%   Author(s): R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 2000/06/13 21:21:05 $ 

error(nargchk(1,2,nargin));

if nargin == 2,
    f = section(f,sec);
end

islinphaseflag = 1; % Initialized assuming linear phase
n = 1;

while islinphaseflag & n <= nsections(f),

    fsec = section(f,n);
        
    [b,a] = tf(fsec);
    
    if isfir(fsec),
        islinphaseflag = determineiflinphase(b);
    
    else,
        if isstable(fsec),
            % Causal stable IIR filters cannot have linear phase
            islinphaseflag = 0;
        else
            islinphaseflag = determineiflinphase(a);
        end
    end        
    
    n = n + 1; % Increment counter
end

%------------------------------------------------------------------------------------
function islinphaseflag = determineiflinphase(b)

% Set defaults
islinphaseflag = 0;

% If b is a scalar, filter is always FIR and linear-phase
if length(b) == 1,
    islinphaseflag = 1;
    return
end

% Remove zeros at the beggining of b (trailing zeros have been removed by tf)
b = b(min(find(b~=0)):end);


symstr = signalpolyutils('symmetrytest',b);

if ~strcmpi(symstr,'none'),
    islinphaseflag = 1;
end
 

