%
%     MATLAB PROJECT 1
%
% Name - Kris Tuthill
% PN# - 26505936
% 
% Date - 10/18/01
%
% Course - EE416
% 
%
%  Given the transfer function of a causal filter:  
%
%  H(z) = (0.025 - 0.07z^-1 + 0.05z^-2 - 0.02z^-3)
%          -------------------------------------
%         (1 + 1.5z^-1 +1.75z^-2 + 1.02z^-3 + 0.4z^-4)
%
% 1. Find poles and zeros
% 2. give pole/zero pattern
% 3. plot frequency response
% 4. find h(n)
% 5. comment on stability of filter
%


%
% 1.

a = [.025 -.07 .05 -.02 0];			% coefficients of numerator

b = [1 1.5 1.75 1.02 .4];	 		% coefficients of denominator

zeros = roots(a)				% gives zeros of H(z)

poles = roots(b)				% gives poles of H(z)


%
% 2.

figure(1);					% assigns first plot to figure 1
zplane(a,b)					% plot of zero/pole pattern
TITLE('Zero/Pole pattern')


%
% 3.

H =a/b;						% our transfer function H(z)

[H,W] = freqz(a, b, 50, 'whole');     % frequency domain analysis of H(z), 
				          % taking 50 points over 2Pi
                                     
                                     
figure(2);
magnitude = plot(W, abs(H))     		% magnitude plot
TITLE('Magnitude vs Frequency')
XLABEL('Frequency, rad')
YLABEL('Magnitude')

figure(3);
phase = plot (W, angle(H))			% phase plot
TITLE('Phase vs Frequency')
XLABEL('Frequency, rad')
YLABEL('Phase')



%
% 4.

w = 1:50;					% assign arbitrary length to omega
t = 1:50;					% assign arbitrary length to time
[h,t] = impz(a,b,w);				% take inverse z-transform of H(z)

figure(4);  
impulse = plot(t,h)				% plot impulse response
TITLE('Impulse Response, h(t)')
XLABEL('Time')
YLABEL('Magnitude')



%
% 5.

% The stability of the filter characterized by the above transfer equation
% depends upon the value of |z|.  If |z| falls within the range between
% the origin and the pole nearest the origin, the filter will be stable.  
% This is the filter's Region of Convergence, ROC.  Given any value of |z|
% outside this region and the filter will diverge (not be stable).

