% direct_ol         - Calculate open-loop response through the cavity

function H = direct_ol(x, data)

G     = x(1);
sigma = x(2);
wr    = x(3);
tau   = x(4);
phi0  = x(5);

w = data.w(data.u);

H = -i*sigma*G*w./(w.^2 - i*sigma*w - wr^2) .* exp(-i*((w-data.wrf)*tau - phi0));

if (0)
% Add DAC lowpass response
Rl=50; L=120e-9; C=47e-12;
s=i*(w-data.f_lo*2*pi); % At IF frequency
Hlp = 2*Rl./(s.^2*L*C*Rl + (L+C*Rl^2)*s + 2*Rl);
H = H.*abs(Hlp);
end

if isfield(data, 'H_inter')
  % Add interpolator filter response
  H = H.*data.H_inter(data.u);
end

if isfield(data, 'H_rot')
  % Add rotator filter response
  H = H.*abs(data.H_rot(data.u));
end
