Butterworth bandpass filter on a signal using buttord and butter
12 views (last 30 days)
Show older comments
José Santos Pérez Leal
on 14 Jun 2021
Commented: Star Strider
on 14 Jun 2021
Hi everyone.
I've been working on a butterworth bandpass filter on a signal, but I can't use the function buttord and butter properly together. The response frecuency of the signal I'm working with has been obtained using fft (shown in the image below). I want to make a bandpass filter between 5 and 450 Hz. Originally, I obtained my bandpass filter only using the function butter, but I select an arbitrary filter order and I need to obtain the order with the function buttord. The code I've been working with for the filter using buttord and butter is shown below the response frecuency image, but it didn't work properly. If someone could tell me what I'm doing wrong in the design of my Butterworth bandpass filter or if I'm designing it in a wrong way, I would be very thankful.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/653020/image.jpeg)
%Arbitrary values for the ripple in the passband and stopband
delta1=0.01;
delta2=0.005;
Ripplep=-20*log10(1-delta1); %Ripple in the passband
Ripples=-20*log10(delta2); %Ripple in the stopband
f=1260; %Sampling frecuency
fnyq=f/2; %Nyquist frecuency
wp=[10 450]/fnyq; %10 is the omegap frecuency for the inferior cut off frecuency portion. 450 is the omegap
%frecuency for the superior cut off frecuency portion
ws=[5 455]/fnyq; %5 is the omegas frecuency for the inferior cut off frecuency portion. 455 is the omegap
%frecuency for the superior cut off frecuency portion
[N,WN]=buttord(wp,ws,Ripplep,Ripples) %Obtain filter order and natural frecuency
[e,c]=butter(N,WN) %butterworth coeficients for the filter
bandpass_filt_data=filtfilt(e,c,window_data) %Apply filter to the original signal (window_data), which has
%a dimension of 15725X1
0 Comments
Accepted Answer
Star Strider
on 14 Jun 2021
The transfer function implementation created an unstable filter.
Instead, use zero-pole-gain output from butter, then implement it as a second-order-section filter with zp2sos.
And always use freqz to assess the filter characteristics first. That will tell you if it met the design requirements.
Try this —
%Arbitrary values for the ripple in the passband and stopband
delta1=0.01;
delta2=0.005;
Ripplep=-20*log10(1-delta1); %Ripple in the passband
Ripples=-20*log10(delta2); %Ripple in the stopband
f=1260; %Sampling frecuency
fnyq=f/2; %Nyquist frecuency
wp=[10 450]/fnyq; %10 is the omegap frecuency for the inferior cut off frecuency portion. 450 is the omegap
%frecuency for the superior cut off frecuency portion
ws=[5 455]/fnyq; %5 is the omegas frecuency for the inferior cut off frecuency portion. 455 is the omegap
%frecuency for the superior cut off frecuency portion
[N,WN]=buttord(wp,ws,Ripplep,Ripples); %Obtain filter order and natural frecuency
[z,p,k]=butter(N,WN); %butterworth coeficients for the filter
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos,2^14,f)
bandpass_filt_data=filtfilt(sos,g,window_data) %Apply filter to the original signal (window_data), which has
%a dimension of 15725X1
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!