Questions about Butterworth filter

I need to apply a Butterworth filter 4th-order with 6Hz cutoff frequency. This is what I get:
[B,A] = BUTTER(4,0.6)
Is this correct? And what does 'B' and 'A' mean? Thanks.

Answers (1)

Use lower case letters:
[B,A] = butter(4, 0.6);
‘B’ and ‘A’ are the coefficients of the numerator and denominator coefficients of the filter transfer function, respectively.
The cutoff frequency is normalised by the Nyquist frequency, so a normalised frequency of 0.6 means you have a Nyquist frequency of 10 Hz and a sampling frequency of 20 Hz. If those are not your Nyquist and sampling frequencies, you need to redesign your filter.
I do these steps whenever I design a filter:
Fs = ...; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Fc = 6/Fn; % Passband Frequency (Normalised)
Fz = 7/Fn; % Stopgand Frequency (Normalised)
[n,Wn] = buttord(Fc, Fs, 1, 10); % Order Of Filter
[B,A] = butter(n,Wn); % Designs Lowpass Filter By Default
I always use the freqz function at this stage, to be sure the filter is stable. If it is not, I either redesign it or add these additional steps:
[sos,g] = tf2sos(B,A); % Second-Order-Section Implementation
Then use the filtfilt function to filter your signals, to avoid phase distortion in the filter.

5 Comments

Okay. Thanks! I understand the steps that you do, but why do I don't need to type in the order '4' anymore?
My pleasure!
You can type in the order ‘4’ if you want to.
The buttord function calculates the appropriate order for you (as ‘n’). If you want to override it, you can specify ‘n=4;’ just before your call to butter, or specify it as a parameter as you did previously. I suggested a more efficient way of designing your filter and being sure that it is stable, but you can certainly specify your own parameters if you want to.
Fs = data_stair_rise(1, 1).VideoFrameRate % Sampling Frequency is 100 with me
Fn = Fs/2; % Nyquist Frequency
Fc = 6/Fn; % Passband Frequency (Normalised)
Fz = 7/Fn; % Stopgand Frequency (Normalised)
[n,Wn] = buttord(Fc, Fs, 1, 10); % Order Of Filter
[B,A] = butter(n,Wn); % Designs Lowpass Filter By Default
When I press run now, it gives the following error: The cutoff frequencies must be within the interval of (0,1).
[n,Wn] = buttord(Fc, Fs, 1, 10);
I think 'Fs' must be replaced by 'Fz'. Am I correct?
Yes. It is the normalised stopband frequency. I couldn’t test the code (I didn’t have your sampling frequency, Fs) or I’d have caught that.

Sign in to comment.

Tags

Asked:

Sam
on 24 Dec 2014

Commented:

on 3 Jan 2015

Community Treasure Hunt

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

Start Hunting!