% dtft_disp2.m
% Script that runs and displays results of DTFT operation
%
% n = vector of n values used for calculation
% x = vector of time function, same size as x
% w = vector of omega values, not normalized
% ndisp = vector of n values used for display, a subset of n
% X = DTFT values computed at w frequencies


[X] = dtft(x,n,w);

ndisplen = length(ndisp);
ndispbeg = ndisp(1)-n(1)+1;
ndispend = ndispbeg+ndisplen-1;

angX = angle(X);
for i = 1:length(angX),
	if angX(i) < -pi+.01
	angX(i)=angX(i)+2*pi;
	elseif angX(i) == -0
	angX(i) = 0;
	end
			
	end

subplot(4,1,1),stem(ndisp,x(ndispbeg:ndispend))
xlabel('n')
ylabel('x[n]')
nlimitdisp = num2str(nlimit);
title(['x[n] = u[n+',nlimitdisp,'] u[',nlimitdisp,'-n]'],'fontsize',14)


subplot(4,1,2),plot(w/pi,real(X))
hold on
xlabel('omega/pi')
ylabel('X')
zerosw = zeros(1,length(w));
plot(w/pi,zerosw,'r')
hold off
	
subplot(4,1,3),plot(w/pi,abs(X))
xlabel('omega/pi')
ylabel('|X|')
	
	
subplot(4,1,4),plot(w/pi,angX)
xlabel('omega/pi')
ylabel('<X')
axis([-2 2 -1  4])
