%  Solution to PS # 1
%  Spring 2001, EECE-495
%  Signal Processing Using MATLAB
%  Instructor: Balu Santhanam
%  Date: 02/01/01
%*******************************************************************
%   Prompt the user to input the coeffcients of the 
%   quadratic polynomial and compute the roots: 
%
format short e
a_vec = input('Coefficient vector: [a,b,c] ------>');
a = a_vec(1); b = a_vec(2); c= a_vec(3); 
%  Compute roots from the coefficient vector: 
D = sqrt(b^2 - 4*a*c);
r1 = (1/(2*a))*(-b+D); 
r2 = (1/(2*a))*(-b-D);
r = [r1,r2];
%    Compute quality factor, damping ratio 
%    and bandwidth of the system: 
Q = -(1./(2*cos(angle(r))));
Q1 = Q(1); Q2 = Q(2);
damp = cos(angle(r));
D1 = damp(1); D2 = damp(2);
BW = -2*abs(r).*damp;
BW1 = BW(1); BW2 = BW(2);
save filt.mat Q1 Q2 D1 D2 r1 r2 BW1 BW2
%***********************************************
%    Display roots with the magnitude, phase 
%    quality factor, damping ratio
%    Save text session in diary file 
%***********************************************
diary filt
disp('***************************************************************')
disp('Root 1 location:')
disp(r1)
fprintf('\n')
disp('Root 1 info:')
fprintf('%s\t%s\t%s\t%s\t%s\n','Mag','Phase','Q','damp','BW')
fprintf('%0.4f\t%0.2f\t%0.4f\t%0.4f\t%2.2f\n',[abs(r1);angle(r1)*(180/pi);Q1;D1;BW1])
fprintf('\n')
disp('***************************************************************')
disp('Root 2 location:')
disp(r2)
fprintf('\n')
disp('Root 2 info:')
fprintf('%s\t%s\t%s\t%s\t%s\n','Mag','Phase','Q','damp','BW')
fprintf('%0.4f\t%0.2f\t%0.4f\t%0.4f\t%2.2f\n',[abs(r2);angle(r2)*(180/pi);Q2;D2;BW2])
fprintf('\n')	 
disp('***************************************************************')
diary off
%********************************************************************
%  Plot the polynomial f(x) with coefficients [a,b,c]
%  Save the plot (softcopy) to eps file so as to fill 
%  entire page
x = [-2.5:0.25:2.5];
f = a*x.^2 + b*x + c;
plot(x,f)
set(gca,'FontName','Helvetica')
set(gca,'FontSize',16)
xlabel('Domain of the function x')
ylabel('Range f(x)')
title('Plot of the polynomial with coefficients [a,b,c]')
grid on
orient tall
print -deps filt.eps
%*****************************************************************
