MATLAB: Cut off frequency for butterworth filters


Hi All,
I have a very basic question.
I am trying to use a butterworth filter but the instructions make no sense. Matlab on accepts a frequency between 0 and 1. The specific instructions say:
"The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate."
Lets say my data was sampled at 2500 Hz. I want to low pass filter at 20 Hz. What exactly would I need to enter for Wn and how can I figure it out on my own.
Thanks in advance!

Best Answer

The ‘frequency between 0 and 1’ refers to a normalised frequency with respect to the Nyquist frequency (Nyquist frequency = sampling frequency/2).
For your low-pass filter with a cutoff of 20 Hz and a sampling frequency (Fs) of 2500 Hz, you would define:
Fs = 2500;
Fco = 20;
Fn = Fs/2;
Wn = Fco/Fn;
Since ‘Wn’ is the upper passband frequency, and you will want to use the buttord function to help you design your filter, you will set the stopband frequency at about 1.25 times the passband frequency, and the passband ripple to be 1 dB and the stopband ripple at 10 dB. (These have no relevance to a Butterworth design, but buttord wants them.)
Also, use tf2sos to create the most stable (second-order-section) representation of your filter.