MATLAB: How to design IIR highpass filter with cutoff frequency of 20Hz and FIR bandpass filter with cutoff frequency of 10Hz and 15Hz

design filter

Fs = 8000;
Fn = Fs/2;
Wp = 20/Fn;
Ws = 3/Fn;
Rp = 0.2;
Rs = 40;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn,'high');
[sos,g] = tf2sos(b,a);
figure(1)
freqz(sos, 2048, Fs)

Best Answer

I can’t design a fir filter to those specifications with any of the fir design functions, regardless of the order of the filter. The normalised frequencies are simply too low and the passband too narrow.
The best I can do is a Chebyshev Type II filter:
Fs = 8000;
Fn = Fs/2;
Wp = [10 15]/Fn;
Ws = [ 6 25]/Fn;
Rp = 10;
Rs = 40;
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs);
[b,a] = cheby2(n,Rs,Ws);
[sos,g] = tf2sos(b,a);
figure(2)
freqz(sos, 2^16, Fs)
set(subplot(2,1,1), 'Xlim', [0 25])
set(subplot(2,1,2), 'Xlim', [0 25])
I also had to increase the fft length 2^16 and narrow the frequency axis to [0 25] to see the details of the passband. Note that a Chebyshev Type II filter has a flat passband, so you can state the passband ripple, ‘Rp’, to be essentially anything you want.
If you want a fir bandpass filter with those characteristics, you would probably have to design separate highpass and lowpass filters and cascade them. The best way to do this would be with dfilt objects, using dfilt.cascade.