function [F, psi] = coherentState(r)
t = 0:0.002:pi;  % this is really omega t
Nt = length(t);

x = (-(r+2):(0.05*pi/r):(r+2))'; % this is really x/a
%Nx = length(x);

psi = exp(-(x-r*cos(t)).^2 - 1i *(0.5*t + 2*r*x*sin(t) - r^2*0.5*sin(2*t)));
env = exp(-(x-r*cos(t)).^2);
F(Nt) = struct('cdata',[],'colormap',[]);

amp = max(max(abs(psi)));

figure(3);
fname = sprintf('coherentState%d.avi',r);
v = VideoWriter(fname);
open(v);
for n = 1:Nt
    plot(x,real(psi(:,n)),x,env(:,n),'r',x,-env(:,n),'r');
    ylim([-1,1]*amp)
    axis tight
    drawnow
    frame = getframe(gcf);
    F(n) = frame;
    writeVideo(v,frame);
end
close(v)

%figure(1)
%surf(real(psi))


end

