40 lines
1.1 KiB
Matlab
40 lines
1.1 KiB
Matlab
function [signal_filtered, Z,P] = iirFilter(N, cutoffFreq, signal, samplingFreq, filterType)
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
% function [Z, P] = iirFilter(N, cutoffFreq, signal, samplingFreq, filterType)
|
|
% ex.: [Z, P] =iirFilter(6, 10, x, 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)
|
|
% -signal: signal to be filter
|
|
% -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;
|
|
|
|
signal_filtered = filter(b, a, signal);
|