function eta = eta(p,x,t)
% eta Return wave amplitude as a function of position and time.

k = (2*pi*p.freq).^2/p.g;
df = (p.fmax-p.fmin)/p.n_freq;
H = (2*p.spectrum*df).^0.5;

%wavep = 2*0.001*(1/(8*pi))*1025*(9.81^2)*trapz(f,p.Spectrum./f);

eta = H(1)*cos(k(1)*x - p.beta*2*pi*p.freq(1)*t + p.phases(1));

for i = 2:length(p.freq)
  eta = eta +  H(i)*cos(k(i)*x - p.beta*2*pi*p.freq(i)*t + p.phases(i));
end

if(p.tau > 0)
 for j = 1:length(eta)
  eta(j) = eta(j).*(1-exp(-t(j)/p.tau));
 end
end                
        
end