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

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

ind=find(wvec==w);
mag_w=abs(mag(ind))
phase_w=phase(ind);

y=filter(b,a,x);						%total response
yss=mag_w*2*cos(w*n-pi/4+phase_w);	%steady state value 
ytr=y-yss;			               %transient resp = total resp - steady state resp

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

subplot(3,1,2), plot(n,yss), grid on
xlabel('n'),ylabel('Amplitude'),title('Steady State Response, yss')

subplot(3,1,3), plot(n,ytr), grid on
xlabel('n'),ylabel('Amplotude'),title('Transient Response, ytr')


