clear hold off 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; Hp1 = plot(tt,xt) %axis([-4*T 4*T 0 1]) axis([-4*T 4*T -1 1]) 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 Xf1 = fft(xt); Xf = fftshift(Xf1); 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 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 -pi pi])