function [num,den] = Ghat(theta,L,alpha,c0),

% GHAT = calculate the approximation of the 
%        transfer function as a linear combination
%        of orthogonal rational functions (ORF).
%
%  USE: [num,den] = Ghat(theta,L,alpha,c0);
%   output:
%    num = coefficients of numerator of Ghat
%    den = coefficients of denominator of Ghat
%   input:
%    theta = identification coefficients
%    L     = reflection coefficients of the ORF
%    alpha = the poles of the ORF
%    c0    = the zero-th moment
%
% See also: ORFsysidC, ORFsysidD1, ORFsysidD2, ORFcalcul, interactiveORFsysid
%

% Patrick Van gucht, september 18, 2000.

% INITIALIZATION
n = length(alpha);

numphi = 1/sqrt(c0);
numphistar = numphi;

num = theta(1)*numphi;
den = 1;

alpha = [0 alpha];

% RECURRENCE
for k=1:n,
   e_k = sqrt((1-abs(alpha(k+1))^2)/((1-abs(alpha(k))^2)*(1-abs(L(k))^2)));
   helpnumphi = [0 numphi] - alpha(k)'*[numphi 0];
   helpnumphistar = [numphistar 0] - alpha(k)*[0 numphistar];
   numphi = e_k*(helpnumphi + L(k)'*helpnumphistar);
   numphistar = e_k*(L(k)*helpnumphi + helpnumphistar);
   num = [num 0] - alpha(k+1)*[0 num] + theta(k+1)*numphi;
   den = [den 0] - alpha(k+1)*[0 den];
end
