From 5b792182c67e004fc2b7da2f10c97c2825f10f0a Mon Sep 17 00:00:00 2001 From: CHARLES Date: Mon, 14 Apr 2025 12:01:05 +0200 Subject: [PATCH] Added improved downsampling. Need to finish : downsample after filter. --- iirFilter.m | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 iirFilter.m diff --git a/iirFilter.m b/iirFilter.m new file mode 100644 index 0000000..36701b2 --- /dev/null +++ b/iirFilter.m @@ -0,0 +1,37 @@ +function [Z, P]= iirFilter(N, cutoffFreq, samplingFreq, filterType) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% function [Z, P] = iirFilter(N, cutoffFreq, samplingFreq, filterType) +% ex.: [Z, P] =iirFilter(6, 10, 500, 1) +% +% Task: To create and analyze an IIR low pass filter (Butterworth ror Chebychev) +% +% Inputs: +% -N: order of the filter +% -cutoffFreq: below this frequency, signal is not modified and above signal is attenuated +% -samplingFreq: sampling frequency (In Hz) +% -filterType: Butterworth if equal to 1 and Chebychev if equal to 2 +% +% Outputs: +% +% +% Author: Guillaume Gibert, guillaume.gibert@ecam.fr +% Date: 09/04/2025 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if (filterType == 1) + [b, a] = butter(N, cutoffFreq/(samplingFreq/2)); +elseif (filterType == 2) + Rp = 10; % bandpass ripple of Rp dB + [b, a] = cheby1(N, Rp, cutoffFreq/(samplingFreq/2)); +else + disp('Filter type is incorrect!') + return +end + +[Z, P] = zeroPole(a, b, 1); + +figure; +freqz(b, a, N, samplingFreq); +title('Frequency response'); +grid on; +