function [H,O,OB]=ss2h(A,B,D,E,L,g);
% SS2H
% Compute the lower block triangular Toeplizt matrix H^d_L from
% a state space model given by the quadruple system matrices (A,B,D,E).
% SYNTAX
% [H^d_L,O_L,O_L B]=ss2h(A,B,D,E,L,g);
% ON INPUT
% A,B,D,E  System matrices.
% L        Number of block rows in H^d, O_L
% g        Define number of block columns, L+g-1, in H^d_L.
%          Olso g=0 when E=0 and g=1 when E.neq.0.
% ON OUTPUT
% H^D_L, O_L AND O_L B
%

[ny,nu]=size(E);

O = eobsv(A,D,L);            % The extended observability matrix.
OB= O*B;                     % DB, DAB, and so on.
hi=[E;OB(1:(L-1)*ny,:)];     % The impulse responses which are needed.

                             % The lower block triangular Toeplizt matrix.
for j=1:L+g-1
  H((j-1)*ny+1:L*ny,(j-1)*nu+1:j*nu) =hi(1:(L-j+1)*ny,:);
end
