Band-pass Butterworth filter

18 visualizaciones (últimos 30 días)
Guglielmo Giambartolomei
Guglielmo Giambartolomei el 1 de Mzo. de 2017
Comentada: Star Strider el 2 de Mzo. de 2017
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!
  2 comentarios
Jan
Jan el 1 de Mzo. de 2017
Please post, what you have tried and explain "doesn't work" with details. Then suggestion an improvement is much easier.
Guglielmo Giambartolomei
Guglielmo Giambartolomei el 1 de Mzo. de 2017
Hello Jan Simon, I tried with the indications of the link i posted; I wrote:
Wp = [1 49]/Fsp/2;
Ws = [0.5 49.5]/Fsp/2;
Rp=1;
Rs=25;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a]=butter(n,Wn);
[sos,g]=tf2sos(b,a);
%fvtool(sos,'Analysis','freq')
deltap1filtfilt=filtfilt(sos,g,deltap_1);
This doesn't work. Instead I tried:
Fcp_low=1; %lower cutoff frequency
Fcp_high=50; %higher cutoff frequency
[z,p,k]=butter(8,[Fcp_low Fcp_high]/(Fsp/2),'bandpass');
[sos,g]=zp2sos(z,p,k);
%fvtool(sos,'Analysis','freq')
deltap1bpfiltfilt=filtfilt(sos,g,deltap_1);
This last code seems to work!

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 1 de Mzo. de 2017
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.
  2 comentarios
Guglielmo Giambartolomei
Guglielmo Giambartolomei el 2 de Mzo. de 2017
Editada: Guglielmo Giambartolomei el 2 de Mzo. de 2017
Thank you Star Strider! What about the code:
Fcp_low=1; %lower cutoff frequency
Fcp_high=50; %higher cutoff frequency
[z,p,k]=butter(8,[Fcp_low Fcp_high]/(Fsp/2),'bandpass');
[sos,g]=zp2sos(z,p,k);
%fvtool(sos,'Analysis','freq')
deltap1bpfiltfilt=filtfilt(sos,g,deltap_1);
Do you think it is correct?
Star Strider
Star Strider el 2 de Mzo. de 2017
My pleasure.
It looks like it should work. It depends on the filter characteristic you want.
The filter I posted in my Answer is the one you originally described in your Question. A Butterworth filter cannot do that effectively.
I would compare the two filters to see which design works best in your application.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by