% Kevin Brenon
% 26785079
% EE 416
% MATLAB Project 1
% 10/18/01

% 1. Find the poles and zeros of H(z).

% I will find the zeros first using the corresponding coefficients and 
% the roots function.

z1 = [0.025 -0.07 0.05 -0.02];  % These are the polynomial coefficients.
z = roots(z1)                   % The roots function finds the roots of the
                                % polynomial, which in this case are the zeros.
                                
% Now I will find the poles using the same method.

p1 = [1 1.5 1.75 1.02 0.4];     % These are the polynomial coefficients.
p = roots(p1)                   % The roots function finds the roots of the
                                % polynomial, which in this case are the poles.
                                
% 2. Use MATLAB to give pole/zero patterns of the filter.

% To plot the zeros and poles, the zplane function can be used.

figure(1);
zplane(z,p)                     % The zplane function is used with the zeros
                                % vector, z, and the poles vector, p.
title('Zeros and Poles of H(z)');
                                
% 3. Plot the frequency response of the filter. 

[H,w] = freqz(z1,p1);           % The freqz function is used to find the 
                                % frequency response vector, h, and the 
                                % corresponding frequency vector,w.
figure(2);
freqzplot(H,w)                  % the freqzplot function is then used to 
                                % plot the information found from the freqz
                                % function.
title('Frequency Response');
                                
% 4. Find h(n). Plot finite samples of h(n).

figure(3);
impz(z1,p1);                    % The impz function finds the impulse response
                                % of the filter and plots it. The number of 
                                % points is chosen automatically by MATLAB.
title('Impulse Response');
xlabel('n');
ylabel('h(n)');
                                
% 5. Comment on the stability of the filter.

% In order for the filter to be stable, all of the poles must be within the unit
% circle.  By looking at the graph obtained from part 2, all of the poles are
% clearly within the unit circle, thereby making this filter stable.