function [z,p,k] = zpk(f,sec)
%ZPK  Filt object zero-pole-gain conversion.
%   [Z,P,K] = ZP(F) returns the zeros, poles and gain 
%   corresponding to the dfilt object F in vectors Z, P
%   and scalar K respectively.
%
%   [Z,P,K] = ZP(F,I) returns the zeros, poles and gain 
%   corresponding to the I-th section of F.

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

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

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


% Initialize P and Z vectors
p = []; z =[]; k=1;
for n = 1:nsections(f),
    fsec = section(f,n);
    [b,a] = tf(fsec);
    [b,a] = eqtflength(b,a); %tf removes trailing zeros, we must make num and den the same length
    % Compute z, p and k per section
    [zt,pt,kt] = tf2zp(b,a);
    % Compute the overall z,p,k for cascaded connections
    z = [z;zt]; p = [p;pt]; k = k.*kt;
end

if strcmpi(connection(f),'par'),
    % Overwrite the zeros and gain with the correct ones for parallel connections
    [b,a] = tf(f);
    [b,a] = eqtflength(b,a); %tf removes trailing zeros, we must make num and den the same length
    [z,pnotused,k] = tf2zp(b,a);
end

% EOF - zpk.m    
    
