%Compute Eq. 4.22, pg. 172 - DTFT of a rectangular pulse
q=10; %half-width of time-domain pulse
omega=-pi:.01:2*pi; %Frequency points at which to evaluate spectrum
pnum=exp(j.*omega*q)-exp(-j.*omega*(q+1)); %numerator of spectrum
pden=1-exp(-j.*omega); %denominator of spectrum
p=pnum./pden; %spectrum
pmag=abs(p); %magnitude of spectrum
pang=angle(p); %angle of spectrum
plot(omega/pi, pmag); %plot spectrum on normalized freq. axis ( pi = 1)
xlabel('Omega/pi')
ylabel('|P(Omega)|')
title('Magnitude DTFT of Rect. Pulse with q = 10')