%#2

N1 = [1 -5.792 9.14];
N2= [1 -4.2 11.487];
Nanalog = conv(N1,N2);
D1 = [1 5.792 9.14];
D2= [1 4.2 11.487];
Danalog = conv(D1,D2);

%Analog Transfer Function
H_s = tf (Nanalog,Danalog)

w=[0:pi/1024:pi];
HS=freqs(Nanalog,Danalog,w);
MagHS=abs(HS);
PhaseHS=angle(HS);

%Prewarping and warping
T=2.55;
%Design of Digital Filter using the Bilinear Trans. 
%Finding the coefficient of DE of digital filter
[Ndigital,Ddigital]=bilinear(Nanalog,Danalog,1/T)
Hz=freqz(Ndigital,Ddigital,w);

%Finding the transfer function of digital filter
HDZ=tf(Ndigital,Ddigital,1)
MagHz=abs(Hz);
PhaseHz=angle(Hz);

%plot for each
figure(1)
subplot (2,1,1);
plot (w/pi, MagHS);    
ylabel('Magnitude in dB');
xlabel('omega');
title('Magnitude  Frequency response of analog filter');
grid on;

subplot (2,1,2);
plot (w/pi, MagHz);   
ylabel('Magnitude in dB');
xlabel('omega');
title('Magnitude Prequency response of digital filter');
grid on;

figure(2)
subplot (2,1,1);
plot (w/pi, PhaseHS, 'r');
xlabel('omega');
ylabel('Angle in Radians');
title('Phase response of analog filter');
grid on;
axis([0,1.2,-4,4]);

subplot (2,1,2);
plot (w/pi, PhaseHz, 'r');
xlabel('omega');
ylabel('Angle in Radians');
title('Phase response of digital filter');
grid on;
axis([0,1.2,-4,4]);




