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

w=0.125*pi;
wvec=[0:pi/1048:pi]';
n=[0:200]';
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

i=200;
while ytr(i) <= (0.01*2*mag_w) & ytr(i) >=(-0.01*2*mag_w)
   i=i-1;
end
sample_number=i