% x[n] = delta(n) + delta(n-1) + delta(n-2)
n = 0:2;
x = ones(size(n));
subplot(411)
stem(n,x)
grid
axis([-1 3 -1 2])
xlabel('n')
ylabel('x[n]')
title('x[n] = \delta(n) + \delta(n-1) + \delta(n-2)')

% DTFT of x[n]
subplot(412)
W=0:0.001:2*pi;
X = (1 + 2*cos(W)).*exp(-j*W);
plot(W/pi,abs(X),'r')
grid
xlabel('\Omega/\pi');
ylabel('|X(\Omega)|');
title('DTFT of x[n] = \delta(n) + \delta(n-1) + \delta(n-2)')


% 3-point DFT of x[n]

N = 3;
k = 0:N-1;

subplot(413)
Wk = 2*pi*k/N;
X3 = fft(x,N);
stem(Wk/pi,abs(X3))
hold on
plot(W/pi,abs(X),'r')
grid
xlabel('\Omega/\pi');
ylabel('|X_k^3|');
title('3-point DFT of x[n] = \delta(n) + \delta(n-1) + \delta(n-2)')

% 3-point DFT of x[n]

N = 100;
k = 0:N-1;

subplot(414)
Wk = 2*pi*k/N;
X100 = fft(x,N);
stem(Wk/pi,abs(X100))
hold on
plot(W/pi,abs(X),'r')
grid
xlabel('\Omega/\pi');
ylabel('|X_k^100|');
title('100-point DFT of x[n] = \delta(n) + \delta(n-1) + \delta(n-2)')

print -dpsc2 dftplot.ps
