syms n,z;
B=[0.025 -0.07 0.05 -0.02 0]; %Numerator polynomial coeffs presented as a vector set
A=[1 1.5 1.75 1.02 0.4];      %Denominator polynomial coeffs presented as a vector set
dt_sys=tf([0.025 -0.07 0.05 -0.02 0],[1 1.5 1.75 1.02 0.4],0.02)
[z,p,k]=residuez(B,A);  %Finds the residues, poles and direct terms 
                        %of the partial-fraction expansion of B(z)/A(z),
 

figure (1);
z=roots(B);
p=roots(A);
zplane(z,p);   %Plots the zeros Z and poles P (in column vectors) with the 
title('Unit circle on the z-plane'); %unit circle for reference.  Each zero is represented with a 'o' and 
               %each pole with a 'x' on the plot.  
[h,w]=freqz(B,A,256,1000);%This returns the N-point complex frequency response
               %vector H and the N-point frequency vector W in radians/sample the filter;
figure (2);    %Frequency response using 256 samples and 1000 units within, i.e. 1/1000
plot(w,h);     %units apart.
title('Frequency response plot'); 
xlabel('time');    
ylabel('h(w)');

[H,T]=impz(B,A,25)%computes the impulse response of the filter B/A 
                  %choosing the number of samples for you, and returns the response in 
                  %column vector H and a vector of times (or sample intervals) in T 
                  %(T = [0 1 2 ...]').
figure(3);
plot(T,H);        %Plots impulse response with respect to time.
title('Impulse Response');
xlabel('time');
ylabel('Impulse response,h(n)');

%Part5-Comment on the stability of the filter from the pole-zero analysis:

%In this problem we were dealing with a two-sided sequence. A two-sided sequence is an
%infinite-duration sequence that is neither right sided nor left sided. As we observe from the
%graph of figure 1, the region of convergence(ROC) consists of a rings in the z-plane,
%bounded on the interior and exterior by a pole, and not containing any poles within itself.
%For the system to be stable, h(n) needs to be absolutely summable and therefore has a fourier 
%transform.Thr ROC needs to consst of the unit circle which in this case it does not, 
%following that the system is not stable.
%Looking at the third graph of h(n) we find how it is a slowly decaying graph. 
%We have already found the poles to be (-0.5272, -0.2228)
%and the zeros to be (0.4, 0, 2);