%Tan Nguyen
%#1
%BPF second order IIR
w0=0.4368*pi; %digital center frequency
b=cos(w0);	%the parameter called beta
bw=0.17*pi;	%the 3-dB bandwidth
%Find a (the parameter called alpha)
%sovle the quadratic equation
%(a*a +1)cos(bw)-2a=0
v=[cos(bw),-2, cos(bw)];
%coefficient of quad. equ.
a=roots(v);
%choosing the roots with mag. <1
if abs(a(1))<1
   a=a(1);
else
   a=a(2);
end
num=(1-a)*[1,0,-1]; %num vec. of transfer function
den=2*[1,-b*(1+a),a];	%den vec. of transfer function

figure(1);
freqz(num,den)

%Finding the difference equation using matlab
[Bdigital,Adigital]=bilinear(num,den,1)
Hz=tf(Bdigital,Adigital,1)



Bdigital =

    0.1631   -0.5437    0.1631


Adigital =

    1.0000   -1.7361    1.3136

 
Transfer function:
0.1631 z^2 - 0.5437 z + 0.1631
------------------------------
    z^2 - 1.736 z + 1.314