%lab2 #3 (a) 
a=[1,-1.8*cos(pi/16),0.81];
b=[2,1,0];

w=0.125*pi;
wvec=[0:pi/1048:pi]';
n=[0:300]';
H=freqz(b,a,wvec);
x=2*cos(w*n-pi/4);   %given input x(n)
mag=abs(H);
phase=angle(H);
y=filter(b,a,x);

subplot(3,1,1), plot(n,y), grid on
xlabel('n'),ylabel('Amplitude'),title('Response to sinusoidal input y')

subplot(3,1,2), plot(wvec/pi,mag), grid on
xlabel('w/pi'),ylabel('Amplitude'),title('Magnitude Response')
subplot(3,1,3), plot(wvec/pi,phase), grid on
xlabel('w/pi'),ylabel('Angle in Red'),title('Phase Response')
