How to Butterworth Filter with Bandpass [10 500] with sampling rate 1000?

7 views (last 30 days)
Hi,
I want to butterworth filter with bandpass [10 500] with sampling frequency 1000 but there is an error stating "The cutoff frequencies must be within the interval of (0,1)." How do I solve this problem?

Accepted Answer

Star Strider
Star Strider on 9 Mar 2016
You have to divide your passband and stopband frequencies by the Nyquist frequency to normalise them:
Fs = 1000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [10 495]/Fn; % Norrmalised Passband Frequencies
Ws = [5 499]/Fn; % Normalised Stopband Frequencies
Rp = 1; % Passband Ripple (dB)
Rs = 25; % Stopband Ripple (dB)
[n,Wn] = buttord(Wp, Ws, Rp, Rs); % Optimal Filter Order
[b,a] = butter(n, Wn); % Calculate Filter Coefficients
[sos,g] = tf2sos(b,a); % Convert To Second-Order Sections For Stability
figure(1)
freqz(sos, 4096, Fs) % Filter Bode Plot
You cannot have any frequency exactly at zero or exactly at the Nyquist frequency, so I designed your passband to be close enough to them to be stable. In your filter, you can also use a high-pass design with a lower cutoff of 10 Hz, since your upper passband is at the Nyquist frequency. The passband and stopband ripple values are necessary to specify in the design but irrelevant to a Butterworth filter. These are acceptable values for most filter designs (for example Chebyshev) that require them.
You would use the ‘sos’ and ‘g’ variables in your actual filter:
filtered_signal = filtfilt(sos, g, signal);
(This design works well in R2016a and should also work in earlier releases.)
  2 Comments
Hazwani Harun
Hazwani Harun on 13 Mar 2016
Thanks sir. I had tried and it works. I would like to ask , if there any effect on my result if the bandpass demand is 10-500 but i use 495/499?
Star Strider
Star Strider on 13 Mar 2016
My pleasure.
The ‘495,499’ will not produce a noticeable difference as an upper passband frequency in a band-pass filter as compared to a high-pass filter with a 500 Hz Nyquist frequency (the highest resolvable frequency in a sampled signal, in this instance with a sampling frequency, ‘Fs’ of 1 kHz). Those frequencies are necessary to (1) produce a stable filter, and (2) to avoid the upper passband frequency equaling the Nyquist frequency.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!