You have to divide your passband and stopband frequencies by the Nyquist frequency to normalise them:
Fs = 1000;
Fn = Fs/2;
Wp = [10 495]/Fn;
Ws = [5 499]/Fn;
Rp = 1;
Rs = 25;
[n,Wn] = buttord(Wp, Ws, Rp, Rs);
[b,a] = butter(n, Wn);
[sos,g] = tf2sos(b,a);
figure(1)
freqz(sos, 4096, Fs)
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.)
Best Answer