MATLAB: Band-pass Butterworth filter

band-pass butterworth filterbutterworthfilter

Hello, I'm trying to make a band-pass Butterworth filter in order to filter a signal. With the help of Star Strider I already made a high-pass filter:
Fcp=1; %cutoff frequency
[z,p,k]=butter(8,Fcp/(Fsp/2),'high');
[sos,g]=zp2sos(z,p,k);
%fvtool(sos,'Analysis','freq')
deltap1filtfilt=filtfilt(sos,g,deltap_1);
I tried to make a band-pass Butterworth filter with this indications (https://it.mathworks.com/matlabcentral/answers/272316-how-to-butterworth-filter-with-bandpass-10-500-with-sampling-rate-1000) but it doesn't work. My sampling frequency is 600 Hz and I'd like to make visible only frequency contributes from 1 Hz to 50 hz. Thank u very much!

Best Answer

There is an error in your code that prevents you from calculating the passbands and stopbands correctly.
This calculation:
Wp = [1 49]/Fsp/2;
gives you these passbands:
Wp =
0.0005 0.0245
However the passbands you want are:
Wp = [1 49]/(Fsp/2);
Wp =
0.002 0.098
Those will give you the correct result. The parentheses around ‘(Fsp/2)’ make all the difference.
If you want to design a filter with rolloffs as steep as you want, a Butterworth filter is not the best option. I would use a Chebyshev Type II design.
The Code
Fsp = 1000; % Create Data
Fn = Fsp/2;
Wp = [1.0 49]/Fn;
Ws = [0.5 50]/Fn;
Rp=10;
Rs=30;
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs);
[z,p,k] = cheby2(n,Rs,Ws);
[sos,g] = zp2sos(z,p,k);
figure(1)
freqz(sos, 2^16, Fsp)
set(subplot(2,1,1), 'XLim',[0 100]) % ‘Zoom’ X-Axis

set(subplot(2,1,2), 'XLim',[0 100]) % ‘Zoom’ X-Axis
The passband ripple in a Chebyshev Type II filter are irrelevant, since the filter has a flat passband. Allowing them to be 10 dB allows you to design a stable filter.
Related Question