
% Modulated wave packet
% alpha>=0 bright soliton
% alpha<0 dark soliton

if(exist('alpha')~=1)
 error('Please first define alpha, (alpha=1 : bright soliton, alpha=-1 : dark soliton)'); 
end

mu=1;
nu=0.35;
xi0=-3;
delta0=0;
dx=0.1;
dt=0.2;
x1=-10;x2=35;
x=x1:dx:x2;

%u=[];

figure(1)
clf

for t=0:dt:15
  xi=2*mu*t+xi0;
  delta=2*(mu^2+nu^2)*t+delta0;
  z=2*nu*(x-xi);
  phi=(mu/nu)*z+delta;
  planewave=exp(i*phi);
  if(alpha>=0)
   amplitude = 2*nu*sech(z);
  else
   amplitude = 2*nu*tanh(z);
  end
  u = amplitude.*planewave;

  subplot(3,1,1)
  plot(x,imag(planewave),'-b',x,real(planewave),'-r','LineWidth',2)
  xlabel('x','FontSize',15)
  ylabel('Carrier wave','FontSize',15)
  axis([x1 x2 -1.1 1.1]);
  set(gca,'FontSize',15);
  subplot(3,1,2)
  plot(x,amplitude,'-g','LineWidth',2)
  xlabel('x','FontSize',15)
  ylabel('Modulation','FontSize',15)
  axis([x1 x2 -1 1]);
  set(gca,'FontSize',15);
  subplot(3,1,3)
  plot(x,imag(u),'-b',x,real(u),'-r',x,abs(u),'g',x,-abs(u),'--g','LineWidth',2)
  xlabel('x','FontSize',15)
  ylabel('Modulated wave packet','FontSize',15)
  axis([x1 x2 -1 1]);
  set(gca,'FontSize',15);
  pause(0.001)
  if(t==0)
   fprintf('Press any key to start...\n');
   pause
  end
end


