How can I set a frequency range for a butterworth filter?
10 views (last 30 days)
Show older comments
Sonal Muzumdar
on 1 Jun 2015
Commented: Darsana P M
on 16 Mar 2017
I want to use a bandpass butterworth filter that only takes in frequencies between 1-25 Hz. How would I go about doing that? The butter function only accepts values in (0,1). Thank you so much!
0 Comments
Accepted Answer
Star Strider
on 1 Jun 2015
You have to normalise your frequencies in terms of the Nyquist frequency (one-half the sampling frequency). So if you have a sampling frequency of, for instance, 100 Hz, you might design your filter as:
Fs = 100; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1 25]/Fn; % Filter Passband (Normalised)
Ws = Wp.*[.75 1/.75]; % Filter Stopband (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Wn] = buttord(Wp, Ws, Rp, Rs);
[b,a] = butter(n, Wn);
[sos,g] = tf2sos(b,a);
then examine it for stability:
figure(1)
freqz(sos, 1024, Fs)
If you are satisfied with the design as plotted with freqz, use it with filtfilt to filter your signal. If not, adjust the stopband and ripple until you have a stable filter that performs as you want it to. Filter design sometimes requires a few adjustments to get it the way you want it.
5 Comments
Star Strider
on 2 Jun 2015
The stopband limits define the ‘steepness’ of the rolloff of the passband, and therefore the order of the filter. As with everything else in digital filter design, they are defined according to the characteristics of your signal. I have found that the limits of [0.75 1/0.75] times the passband for a bandpass filter work well in practice and usually produce a stable filter with good characteristics. If the filter (always use the second-order-section implementation for maximum stability) is not stable, I change the passband and stopband limits until it is. The stopband limits are yours to decide, so you have to choose them so you have a stable filter that does what you want.
If you’re going to be working with digital filters in your research, I encourage you to take a course in digital signal processing. There is much more to it than in my brief comments here.
My pleasure!
I apologise for the delay — life intrudes.
Darsana P M
on 16 Mar 2017
In the above question,if suppose we need to divide frequencies 1-25Hz,25-50 Hz and so on in the same graph, what should we do?
More Answers (1)
Rohit Kanji
on 18 Aug 2016
If I change Fs = 100 in the above code to Fs = 400, it does not work. Why is that?
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!