
% Fourier transform of a wave packet

n=11;
N=2^n;
L=20;
dx=2*L/N;
x=-L:dx:L-dx;

b=5;
a=0.05;

envelope=b*exp(-a*x.^2);
y=envelope.*cos(b*x);
Y=fft(y);
M=max(max(abs(real(Y))));

figure(1)
subplot(3,1,1)
plot(x,y,x,envelope,'r--',x,-envelope,'r--')
xlabel('x')
ylabel('y(x)')
axis([-L L -b-2 b+2]);
title('Wave packet y(x) with enevelope and its Fourier transform Y(w)')
subplot(3,1,2)
plot(abs(real(Y(1:N/2))))
xlabel('w')
ylabel('Y(w)')
axis([0 N/2 -M/10 M+M/10])
subplot(3,1,3)
plot(abs(real(Y(1:N/2))),'.-','MarkerSize',14)
xlabel('w')
ylabel('Y(w)')
axis([0 100 -M/10 M+M/10])



