function [a,b,c,d] = sec2ss(h)
%SEC2SS  Convert a single-section df2 object to state-space.

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

[num,den] = tf(h);

% Normalize the transfer function and get order of num and den
[num,den,N,M] = normalizengetord(num,den);

if M == 0 & N == 0
    % Scalar case,
    a = []; b = []; c = []; d = num;
    return
end


% Make sure num is at least as long as den
num = [num zeros(1,M-N)];
% Recalculate the num order
N = length(num)-1;

% Build the system matrix A
a = sysmatrix(den,N,M);
	
% Build the input matrix B
b = [1;
        zeros(N-1,1)];
	
% Build output matrix C
ct1 = [-num(1).*den(2:end)];
ct2 = [num(2:end)];
ct1 = [ct1 zeros(1,length(ct2)-length(ct1))];
ct2 = [ct2 zeros(1,length(ct1)-length(ct2))];
c = ct1+ct2;

% Build direct feedthrough matrix D
d = num(1);
