function u0 = uzero(x,lx)
% UZERO defines initial condition  u0 = u(x,0)

amp0 = 1.0;
fracshift = 1/pi;
lshift = round(lx*fracshift);
% u0 = zeros(1,lx);

% 1)
%u0 = amp0*cos(x)+ 0.5*amp0*cos(2.*x);
u0 = amp0*cos(x);

% 2)
%u0 = exp (-25*(x - 1).^2);

% 3) In Biello and Hunter's "run_amp.m" with 'Amplitude scale' = 0.5.
%u0 = 0.5*real(exp(i*x) + (1/2)* exp(2*i*(x+2*pi*pi)));

% 4) Sawtooth
%u0(1:lx/4) = x(1:lx/4)/pi;                           % 0 <= x <= pi/2
%u0((lx/4)+1:3*lx/4) = (pi - x((lx/4)+1:3*lx/4))/pi;  % pi/2 < x <= 3*pi/2
%u0((3*lx/4)+1:lx) = (x((3*lx/4)+1:lx) - 2*pi)/pi;    % 3*pi/2 < x < 2*pi

% 5) V
%u0(1:lx/2) = (pi - x(1:lx/2))/(2*pi);            % 0 <= x <= pi
%u0((lx/2)+1:lx) = (x((lx/2)+1:lx) - pi)/(2*pi);  % pi < x <= 2*pi

%u0 = circshift(u0,lshift);

%u0 = local_u0_fft(lx);
u0 = u0.';
end

function u0=local_u0_fft(lx)
    af = (1:(lx/2-1));
    af = local_cf(af,lx);
    bf = fliplr(conj(af));
    u0_hat = lx*[0 af 0 bf];
    u0 = ifft(u0_hat);
end

function cn=local_cf(n,lx)
   cn = (i).^n.*exp(-n);
end