clear
%close ALL
format long e
N = 4096; %No. of FFT samples
fc = 1e3; %radio frequency
fmax = 2e3;
sampling_rate = 2*fmax; %Nyquist rate 
tstep = 1/sampling_rate;
tmax = N*tstep/2;
tmin = -tmax;
tt = tmin:tstep:tmax-tstep;
fmin = -fmax;
fstep = (fmax-fmin)/N;
freq = fmin:fstep:fmax-fstep;

%t0 = 100*tstep;
t0 = 0;
T = 100*tstep;
xt1 = exp(-(tt-t0).*(tt-t0)/(T*T));
%xt = xt1 .* cos(2*pi*fc*tt);
xt = xt1 .* exp(j*2*pi*fc*tt);
%xt = xt1;
figure(3)
Hp1 = plot(tt,real(xt))
%axis([-4*T 4*T 0 1])
axis([-4*T 4*T min(real(xt)) max(real(xt))])
set(Hp1,'LineWidth',2)
Ha = gca;
set(Ha,'Fontsize',16)
Hx=xlabel('Time (sec) ');
set(Hx,'FontWeight','bold','Fontsize',16)
Hx=ylabel('signal x(t)  (Volt)');
set(Hx,'FontWeight','bold','Fontsize',16)
title('Input signal x(t) : Time domain');
pause
axis auto
%fft does summation from 0 to N-1. To make the summation from
%-N/2 to N/2-1, fftshift is necessary
Xf = fftshift(fft(fftshift(xt)));
figure(4)
Hp1=plot(freq,abs(Xf))
set(Hp1,'LineWidth',2)
Ha = gca;
set(Ha,'Fontsize',16)
Hx=xlabel('Frequency (Hz) ');
set(Hx,'FontWeight','bold','Fontsize',16)
Hx=ylabel('|X(f)|');
set(Hx,'FontWeight','bold','Fontsize',16)
title('magnitude spectrum X(f)');
%axis([-5/T 5/T 0 200])
axis([-fc-5/T fc+5/T 0 200])
% pause
% figure(3)
% Hp1=plot(freq,angle(Xf))
% set(Hp1,'LineWidth',2)
% Ha = gca;
% set(Ha,'Fontsize',16)
% Hx=xlabel('Frequency (Hz) ');
% set(Hx,'FontWeight','bold','Fontsize',16)
% Hx=ylabel('arg[X(f)]');
% set(Hx,'FontWeight','bold','Fontsize',16)
% title('phase spectrum X(f)');
% axis([-1 1 -0.5 0.5])





