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

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

k = seccoefficients(h);

% Make sure k is a column
k = k(:);

% Record the length of k
N = length(k);

% Handle the scalar case
if N==1 & k == 0,
    a = []; b = []; c = []; d = 1;
    return
end


% Generate a lower triangular matrix of ones
lowtriag = tril(ones(N-2));

% Multiply each row by conj(k(2:end-1))
ktemp = conj(k(2:end-1,ones(size(lowtriag,2),1)));
lowtriag = lowtriag.*ktemp;

% Multiply each column by k(1:end-2)
ktemp = k(1:end-2).'; % First use a row vector of k
ktemp = ktemp(ones(size(lowtriag,2),1),:);
if ~isempty(lowtriag), % Necessary if length(k) == 1
    lowtriag = lowtriag.*ktemp;
end

% Add a row and a column to the lower triang matrix plus an identity
lowtriag = eye(N-1) + [zeros(1,N-1);lowtriag zeros(N-2,1)];

% Form the system matrix a
a = [zeros(1,N);
    lowtriag zeros(N-1,1)];
    
b = [1;conj(k(1:end-1))];

c = k.';

d = 1;
