function isallpassflag = isallpass(f,sec)
%ISALLPASS  Determine if filter object has allpass sections.
%   FLAG = ISALLPASS(F) determines if the filter object F has
%   allpass filter sections, and returns 1 if true and 0 if
%   false.
%
%   FLAG = ISALLPASS(F,I) determines if the I-th section of the
%   filter object F is an allpass section and returns 1 if true
%   and 0 if false.  
%
%   See also DFILT/ISMINPHASE, DFILT/ISMAXPHASE, DFILT/ISLINPHASE,
%   DFILT/ISFIR, DFILT/ISSTABLE.

%   Author(s): R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 2000/07/18 18:27:55 $ 

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

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

isallpassflag = 1; % Initialized assuming minimum-phase
n = 1;

while isallpassflag & n <= nsections(f),
	
	fsec = section(f,n);
	
	if ~isa(fsec,'latcallpass'),
		% We check if each section is allpass for the case of cas and par filters
		
		[b,a] = tf(fsec);
		
		% Remove zeros at the beggining of b (trailing zeros have been removed by tf)
		b = b(min(find(b~=0)):end);
		
		if length(b) ~= length(a),
			isallpassflag = 0;
			return
		end
		
		% Since we normalize by a(1), a(1) is always = 1.
		% We must compensate for that to compare
		b = b./b(end); % b(end) is now = 1
		if max(abs(conj(b(end:-1:1)) - a)) > eps^(2/3),
			isallpassflag = 0;
		end
	end
	
	n = n + 1;
end
