num = [0.025 -0.07 0.05 -0.02];		%Coefficents of numberator
den = [1 1.5 1.75 1.02 0.4];			%Coefficents of denominator
range = -pi:0.1:pi;

%h = filt(num,den)		%Creates Transfer Funtion object and displays
								%  funtion in z^-n format.
rnum = roots(num);
disp('The zeros of H(z) are:')
disp(rnum);
rden = roots(den);
disp('The poles of H(z) are:')
disp(rden);

figure;
zplane(num,den);		%Plots poles and zeros of H(z)
title('Poles and Zeros of the transfer funtion H(z)');

H = freqz(num,den,range);

figure;
plot(range,abs(H))		%Plots absolute value of frequency responce
title('Frequency Responce of H(z)');

[r,p,k] = residuez(num,den);
disp('After partial fraction expantion,the numberator and denominator coeffecents are:')
disp('Numerator');
disp(r);
disp('Denominator');
disp(p);

disp('The inverse z-transform is:')
disp(['h(n)=(',num2str(r(1)),')(',num2str(p(1)),')^n + (',num2str(r(2)),...
        ')(',num2str(p(2)),')^n + (',num2str(r(3)),')(',num2str(p(3)),...
        ')^n + (',num2str(r(4)),')\r(',num2str(p(4)),')^n']);

% u = iztrans(h);

figure;
title('Impulse responce of h(n))');
[hh,tt]=impz(num,den);		%Takes impulse responce of H(z) and figures out
									%  correct number of samples to take
stem(tt,hh); 		%plots impulse responce
                           
%Note:
%The transfer funtion is stable due to the following:
%1. All poles are within the unit circle
%2. All poles are on the left hand side
%3. The order of the numberator is less then that of the denominator.
                          