%Vedrana Sarajlic
%ID#:2730-3757
%File:project1
%Transfer function
%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

disp('Transfer function:')
disp('H(z)=   (0.025 - 0.07z^-1 + 0.05z^-2 - 0.02z^-3)')
disp('     ---------------------------------------------- ')
disp('     (1 + 1.5z^-1 + 1.75z^-2 + 1.02z^-3 + 0.4z^-4)')

%find zeros
num=[0.025 -0.07 0.05 -0.02]
disp('Zeros:')
z=roots(num)


%find poles
den=[1 1.5 1.75 1.02 0.4]
disp('Poles:')
p=roots(den)


[r,p,k]=residuez(num,den)

%pole/zero patterns of the filter
figure(1);
zplane(z,p)

%frequency respons of the filter
figure(2);
freqz(num,den,'whole')

%find h(n) and plot finite samples
figure(3);
x=[1 zeros(1,35)];
h=filter(num,den,x);
stem(h);
grid
xlabel('Samples from 1 to 35') %label horizontal axis
ylabel('h(n)') %label vertical axis

%System is stable since poles are inside the unit circle on the left side of the plane.
