Signal_Final_TikeaTE/zeroPole.m

45 lines
874 B
Matlab

function [Z,P] = zeroPole(b,a,plt)
%{
function [Z,P] = zeroPoles(b,a,plt)
Ex: [Z,P] = zeroPoles([1 0.5 -1],[1 0 0.81],1)
Task: To compute the zeros and poles of a transfer function
Inputs:
-a: vector of a_i (denominator)
-b: vector of b_i (numerator)
-plt: plot if greater than 0
Outputs:
-Z: zeros (roots of the numerator)
-P: poles (roots of the denominator)
Author: Tikea TE
Date: 15/04/2025
%}
% ======== calculate the zeros =========
Z = roots(b);
% ======== calculate the poles =========
P = roots(a);
if(plt)
figure;
zplane(Z,P);
title("zeros and poles of H(z) in the complex plane");
xlabel("Real part");
ylabel("imaginary part");
legend("zeros","poles");
grid on;
figure;
impz(b,a);
title("Impulse response");
xlabel("samples (n)");
ylabel("amplitude of the output y")
grid on;
end