# Designing Butterworth Filter [closed]

I want to design butterworth filter in matlab only based on order of the filter and the cutoff frequency in Hz.

the syntax is for returning the ABCD matrix of statespace is

[A,B,C,D] = butter(____)


I tried doing below for 2nd order and 30Hz cut off

[A, B, C, D] = butter(2,30)


But i get an error saying :

Error using butter (line 41)
The cutoff frequencies must be within the interval of
(0,1).


Any help will be appriciated

## closed as unclear what you're asking by PlasmaHH, Bence Kaulics, Daniel Grillo, Autistic, Voltage SpikeJun 21 '16 at 15:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Who is giving you the error? M\$ Office? – PlasmaHH Jun 21 '16 at 7:44
• I thought it was understood that i was designing in matlab, sorry for confusion. I have edited the question – Aashu10 Jun 21 '16 at 7:47
• "[] = butter(,'s') designs a lowpass, highpass, bandpass, or bandstop analog Butterworth filter with cutoff angular frequency Wn." Directly taken from the help file, please learn how to use other resources other than an online community. IDK if your reading the help file before you post, if your not you should. Please also see electronics.stackexchange.com/help/how-to-ask please follow the recommendations before posting. – Voltage Spike Jun 21 '16 at 15:24
• I'm voting to close this question because not much research was done before posting – Voltage Spike Jun 21 '16 at 15:25
• Hello, Sorry for the confusion. I did check the help. But as you posted, Wn is cutoff angular frequncy, so i just converted my cut off frequency to rads/sec. Which was giving me an error. Turns out Wn was actually normalized cut off frequrency as shown below. – Aashu10 Jun 22 '16 at 6:23

I'm assuming you are using Matlab to calculate the filter, judging from the syntax and function parameters.

butter calculates a normalized low pass filter response. If you are in the z domain, the actual cut-off frequency depends on your nyquist frequency (half your sampling frequency). If you sample with say 2MSPS, you have a Nyquist frequency of 1MHz and butter with Wn=0.5 would have a cut-off frequency of 500kHz. See also this discussion on matlab central.

You should read "doc butter" to get started and might also want to read a textbook on filter design. From the documentation:

[b,a] = butter(n,Wn) designs an order n lowpass digital Butterworth filter with normalized cutoff frequency Wn. It returns the filter coefficients in length n+1 row vectors b and a, with coefficients in descending powers of z.

• Hey! thanks your your detailed answer. i am little behind on some basics. but i want in state space representation. Say i want to desgin a butterworth filter for Cut off frequency of 35Hz. how would i do it '[A,B,C,D] = butter(2, __)' – Aashu10 Jun 21 '16 at 8:51
• As I said, you need to know your sampling rate if you want to relate the normalized frequency Wn to the actual frequency. If you clock your system faster, the cut off frequency will also move up. It doesn't matter whether you design in state space or not. If you want to calculate a continuous filter, you should use the parameter butter( ___, 's'). Again, this works for statespace as well. – cx05 Jun 21 '16 at 8:53
• My Ts = 0.025. I am not sure of the unit you posted. – Aashu10 Jun 21 '16 at 8:55
• The Unit is Megasamples per second. Your Ts would give you 1/Ts = 40 Samples per second (40 SPS). This means that you cannot achieve 30Hz cutoff, because your Nyquist frequency is already at 20Hz. You need a lower Ts to make it work. – cx05 Jun 21 '16 at 8:56
• If Ts is sampling period, invert it to get the sampling frequency, and half that to get the Nyquist frequency. – Brian Drummond Jun 21 '16 at 8:58