%lab3
%#1a
n=[0:10]';               
x=zeros(size(n));
index=find(n>=0 & n<9);
x(index)=1;

y=x.*(-1).^n;
w=[0:pi/1024:pi]';
Xspect=freqz(x,1,w);
Yspect=freqz(y,1,w);

magX=abs(Xspect);
phaseX=angle(Xspect);
magY=abs(Yspect);
phaseY=angle(Yspect);

g=conv(y,y)             
Gspect=freqz(g,1,w);
magG=abs(Gspect);
phaseG=angle(Gspect);

figure(1)

subplot(3,1,1);
stem(n,y) ; %Y(n) output signal
xlabel('n');
ylabel('Amplitude');
title('Problem #1A: Y(n)');
grid on

subplot(3,1,2);
plot(w,magY) ; %Magnitude plot of Y(n)
xlabel('\omega');
ylabel('Amplitude');
title('Magnitude spectrum of Y(n)');
grid on
axis([0,pi,0,8]);

subplot(3,1,3);
plot(w,phaseY) ; %Phase plot of Y(n)
xlabel('\omega');
ylabel('Radians');
title('Phase spectrum of Y(n)');
grid on
axis([0,pi,-4,4]);