MATLAB: Designing a higher order lowpass filter to avoid Gibbs phenomenon

filter designfilter ordergibbs phenomenonhigher order lowpass filterlowpass filter

Hello!
I'm designing a simple but higher order lowpass filter to get rid of the Gibbs Phenomenon. This is what I thought of. Am I correct? Is this a valid filter?
d = designfilt('lowpassiir', 'FilterOrder',20,… % Response type
'PassbandFrequency',400, % Frequency constraints
'MatchExactly','passband', % Design method options
'SampleRate',2000)
I want to keep it simple having only cutoff frequency and the order as variables. (I assumed 'Match exactly' should be 'passband' because I need the filter to depend on cutoff frequency. Is this not necessary?)
How should I compensate for the delay in this? Since it is an IIR filter, it's only a phase shift, am I right?
Thank you!!

Best Answer

I could not get that code to work.
Try this:
Fs = 2000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 400/Fn; % Normalised Passband (Passband = 5 Hz To 40 Hz)
Ws = 450/Fn; % Normalised Stopband (Passband = 2 Hz To 45 Hz)
Rp = 1; % Passband Ripple/Attenuation
Rs = 60; % Stopband Ripple/Attenuation
[n,Wp] = ellipord(Wp, Ws, Rp, Rs); % Calculate Elliptic Filter Optimum Order
[z,p,k] = ellip(n, Rp, Rs, Wp,'low'); % Elliptic Filter
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
figure
freqz(sos, 2^26, Fs)
To use it with filtfilt:
y_filtered = filtfilt(sos, g, y);