From 5ba653331e897fd17eb04cb4abb5b2cb516ab066 Mon Sep 17 00:00:00 2001 From: Tikea TE Date: Wed, 16 Apr 2025 14:48:38 +0200 Subject: [PATCH] add zeroPole.m to ceuurent folder --- main.m | 5 +++++ zeroPole.m | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 zeroPole.m diff --git a/main.m b/main.m index c1714d1..8b3a126 100644 --- a/main.m +++ b/main.m @@ -22,4 +22,9 @@ plotRawSignal(X, Fs); % ==== Analyze frequency spectrum ==== [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 diff --git a/zeroPole.m b/zeroPole.m new file mode 100644 index 0000000..0bef98d --- /dev/null +++ b/zeroPole.m @@ -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 + +