In part two of the problem, you will have to use the definition of the DTFT to compute X(omega). The resultant function is just a periodic version of X(jw) from part one of the problem. See the following code below.
clear variables
close all
N= 200;
T = 2;
t = -2:4/(N-1):2;
x = rectpuls(t,T);
f= -2:4/(N-1):2;
X = T*sin(pi*f*T)./(pi*f*T);
figure
subplot(121)
plot(t,x,'linewidth',2,'color','b')
grid;
a = title('x(t)');
set(a,'fontsize',14);
a = ylabel('x');
set(a,'Fontsize',14);
a = xlabel('t');
set(a,'Fontsize',14);
subplot(122)
plot(f,abs(X)/(max(X)),'linewidth',2,'color','m')
a = title('|X(jw)|');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
M = 1000;
N = 7;
n = 0:N-1;
xn = ones(1,N);
w = 8*pi;
omega = -w:2*w/(M-1):w;
Xn= exp(-1i.*omega.*(N-1)./2).*(sin(omega*N/2)./sin(omega/2));
Mag = abs(Xn)/max(Xn);
Phase = angle(Xn);
figure
subplot(3,1,1)
stem(n,xn,'linewidth',2,'color','b');
a = title('x(n)');
set(a,'fontsize',14);
a = ylabel('xn');
set(a,'Fontsize',14);
a = xlabel('n');
set(a,'Fontsize',14);
grid
subplot(3,1,2)
plot(omega/pi,real(Mag),'linewidth',2,'color','k');
a = title('|X(\omega)|');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
subplot(3,1,3)
plot(omega./pi,Phase,'linewidth',2,'color','k');
a = title('<X(\omega)');
set(a,'fontsize',14);
a = ylabel('X');
set(a,'Fontsize',14);
a = xlabel('f');
set(a,'Fontsize',14);
grid
Best Answer