clear all; close all;

% Pulse description
A0  = 1;
tau = 1; 
g1 = 1/(2*tau^2);
f0  = 3;
w0  = 2*pi*f0;

N = 1e4;
t = 5*tau*linspace(-1,1,N);
c = exp(1j*w0*t);

A = A0*exp(-g1*t.^2);
E = A.*c;

Er = real(E);
subplot(311);
plot(t,Er); hold on;
ylabel('amplitude (a.u.)');
title('original pulse e^{-\Gamma_1*t^2}{\cdot}e^{jw_0t}');

% Fiber chirp
g2 = sqrt(3)*g1;
Af = A.*exp(-1j*g2*t.^2);
Ef = Af.*c;
Efr = real(Ef);
subplot(312);
plot(t,Efr,'r');
ylabel('amplitude (a.u.)');
title('fiber chirped pulse e^{-\Gamma_1*t^2}{\cdot}e^{-j\Gamma_2*t^2}{\cdot}e^{jw_0t}');

% Compression
D2 = -sqrt(3)/8*tau^2;
g = g1+1j*g2;
gp = 1/(1/g-1j*4*D2);

Ac = exp(-gp*t.^2);
Ec = Ac.*c;
Ecr = real(Ec);
subplot(313);
plot(t,Ecr,'k');
xlabel('time');
ylabel('amplitude (a.u.)');
title('grating-pair compensated pulse e^{-\Gamma''*t^2}{\cdot}e^{jw_0t}');
