add zeroPole.m to ceuurent folder

This commit is contained in:
Tikea TE 2025-04-16 14:48:38 +02:00
parent 9d349a8d80
commit 5ba653331e
2 changed files with 49 additions and 0 deletions

5
main.m
View File

@ -22,4 +22,9 @@ plotRawSignal(X, Fs);
% ==== Analyze frequency spectrum ==== % ==== Analyze frequency spectrum ====
[f, power] = frequencySpectrum(X, Fs, 1); % set 1 to plot [f, power] = frequencySpectrum(X, Fs, 1); % set 1 to plot
% ======== Apply a bandpass filter ==============
[filteredSignal, Z, P] = iirFilter(6, [5 20], X, 200, 1); % Butterworth bandpass
end end

44
zeroPole.m Normal file
View File

@ -0,0 +1,44 @@
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