You are here : matlab → Signal Processing → butter
# butter() - Signal Processing

### Syntax

### Example

### Output / Return Value

### Limitations

### Alternatives / See Also

### Reference

example[b,a] = butter(n,Wn) returns the transfer function coefficients of an nth-order lowpass digital Butterworth filter with normalized cutoff frequency Wn. example[b,a] = butter(n,Wn,ftype) designs a lowpass, highpass, bandpass, or bandstop Butterworth filter, depending on the value of ftype and the number of elements of Wn. The resulting bandpass and bandstop designs are of order 2n. Note: See Limitations for information about numerical issues that affect forming the transfer function. example[z,p,k] = butter(___) designs a lowpass, highpass, bandpass, or bandstop digital Butterworth filter and returns its zeros, poles, and gain. This syntax can include any of the input arguments in previous syntaxes. example[A,B,C,D] = butter(___) designs a lowpass, highpass, bandpass, or bandstop digital Butterworth filter and returns the matrices that specify its state-space representation. example[___] = butter(___,'s') designs a lowpass, highpass, bandpass, or bandstop analog Butterworth filter with cutoff angular frequency Wn.

[b,a] = butter(n,Wn) example[b,a] = butter(n,Wn,ftype) example[z,p,k] = butter(___) example[A,B,C,D] = butter(___) example[___] = butter(___,'s') example

Lowpass Butterworth Transfer FunctionOpen This Example Design a 6th-order lowpass Butterworth filter with a cutoff frequency of 300 Hz, which, for data sampled at 1000 Hz, corresponds to rad/sample. Plot its magnitude and phase responses. Use it to filter a 1000-sample random signal. [b,a] = butter(6,0.6); freqz(b,a) dataIn = randn(1000,1); dataOut = filter(b,a,dataIn); Bandstop Butterworth FilterOpen This ExampleDesign a 6th-order Butterworth bandstop filter with normalized edge frequencies of and rad/sample. Plot its magnitude and phase responses. Use it to filter random data.[b,a] = butter(3,[0.2 0.6],'stop'); freqz(b,a) dataIn = randn(1000,1); dataOut = filter(b,a,dataIn); Highpass Butterworth FilterOpen This Example Design a 9th-order highpass Butterworth filter. Specify a cutoff frequency of 300 Hz, which, for data sampled at 1000 Hz, corresponds to rad/sample. Plot the magnitude and phase responses. Convert the zeros, poles, and gain to second-order sections for use by fvtool. [z,p,k] = butter(9,300/500,'high'); sos = zp2sos(z,p,k); fvtool(sos,'Analysis','freq') Bandpass Butterworth FilterOpen This Example Design a 20th-order Butterworth bandpass filter with a lower cutoff frequency of 500 Hz and a higher cutoff frequency of 560 Hz. Specify a sample rate of 1500 Hz. Use the state-space representation. Design an identical filter using designfilt. [A,B,C,D] = butter(10,[500 560]/750); d = designfilt('bandpassiir','FilterOrder',20, ... 'HalfPowerFrequency1',500,'HalfPowerFrequency2',560, ... 'SampleRate',1500); Convert the state-space representation to second-order sections. Visualize the frequency responses using fvtool.sos = ss2sos(A,B,C,D); fvt = fvtool(sos,d,'Fs',1500); legend(fvt,'butter','designfilt') Comparison of Analog IIR Lowpass FiltersOpen This Example Design a 5th-order analog Butterworth lowpass filter with a cutoff frequency of 2 GHz. Multiply by to convert the frequency to radians per second. Compute the frequency response of the filter at 4096 points.n = 5; f = 2e9; [zb,pb,kb] = butter(n,2*pi*f,'s'); [bb,ab] = zp2tf(zb,pb,kb); [hb,wb] = freqs(bb,ab,4096); Design a 5th-order Chebyshev Type I filter with the same edge frequency and 3 dB of passband ripple. Compute its frequency response.[z1,p1,k1] = cheby1(n,3,2*pi*f,'s'); [b1,a1] = zp2tf(z1,p1,k1); [h1,w1] = freqs(b1,a1,4096); Design a 5th-order Chebyshev Type II filter with the same edge frequency and 30 dB of stopband attenuation. Compute its frequency response.[z2,p2,k2] = cheby2(n,30,2*pi*f,'s'); [b2,a2] = zp2tf(z2,p2,k2); [h2,w2] = freqs(b2,a2,4096); Design a 5th-order elliptic filter with the same edge frequency, 3 dB of passband ripple, and 30 dB of stopband attenuation. Compute its frequency response.[ze,pe,ke] = ellip(n,3,30,2*pi*f,'s'); [be,ae] = zp2tf(ze,pe,ke); [he,we] = freqs(be,ae,4096); Plot the attenuation in decibels. Express the frequency in gigahertz. Compare the filters.plot(wb/(2e9*pi),mag2db(abs(hb))) hold on plot(w1/(2e9*pi),mag2db(abs(h1))) plot(w2/(2e9*pi),mag2db(abs(h2))) plot(we/(2e9*pi),mag2db(abs(he))) axis([0 4 -40 5]) grid xlabel('Frequency (GHz)') ylabel('Attenuation (dB)') legend('butter','cheby1','cheby2','ellip') The Butterworth and Chebyshev Type II filters have flat passbands and wide transition bands. The Chebyshev Type I and elliptic filters roll off faster but have passband ripple. The frequency input to the Chebyshev Type II design function sets the beginning of the stopband rather than the end of the passband.