butter — Design Butterworth IIR filters.
butter(n,Wn) designs an order-n Butterworth filter. A digital scalar cutoff defaults to lowpass, while a two-element cutoff defaults to bandpass. Filter-type text selects low, high, bandpass, or stop, and 's' selects an analog design.
Syntax
b = butter(n, Wn)
b = butter(n, Wn, ftype)
b = butter(n, Wn, 's')
b = butter(n, Wn, ftype, 's')
[b, a] = butter(n, Wn)
[b, a] = butter(n, Wn, ftype)All supported butter forms
b = butter(n, Wn)
b = butter(n, Wn, ftype)
b = butter(n, Wn, 's')
b = butter(n, Wn, ftype, 's')
[b, a] = butter(n, Wn)
[b, a] = butter(n, Wn, ftype)
[b, a] = butter(n, Wn, 's')
[b, a] = butter(n, Wn, ftype, 's')
[z, p, k] = butter(n, Wn)
[z, p, k] = butter(n, Wn, ftype)
[z, p, k] = butter(n, Wn, 's')
[z, p, k] = butter(n, Wn, ftype, 's')
[A, B, C, D] = butter(n, Wn)
[A, B, C, D] = butter(n, Wn, ftype)
[A, B, C, D] = butter(n, Wn, 's')
[A, B, C, D] = butter(n, Wn, ftype, 's')Inputs
n- Type
IntegerScalar- Required
- Yes
- Description
- Filter order.
Wn- Type
NumericArray- Required
- Yes
- Description
- Normalized digital cutoff frequency or analog cutoff frequency.
ftype- Type
StringScalar- Required
- No
- Default
"low" for scalar Wn, "bandpass" for two-element Wn- Description
- Filter type: low, high, bandpass, or stop.
Wn- Type
NumericArray- Required
- Yes
- Description
- Analog cutoff frequency.
s- Type
StringScalar- Required
- Yes
- Description
- Analog filter-design flag.
s- Type
StringScalar- Required
- No
- Description
- Analog filter-design flag.
Returns
b- Type
NumericArray- Description
- Numerator coefficient vector.
a- Type
NumericArray- Description
- Denominator coefficient vector.
z- Type
NumericArray- Description
- Filter zeros.
p- Type
NumericArray- Description
- Filter poles.
k- Type
NumericScalar- Description
- Filter gain.
A- Type
NumericArray- Description
- State matrix.
B- Type
NumericArray- Description
- Input matrix.
C- Type
NumericArray- Description
- Output matrix.
D- Type
NumericScalar- Description
- Feedthrough term.
Returned values from butter depend on how many outputs the caller requests.
Errors
RunMat:butter:ArgCount- When
- The argument count is outside butter's supported forms.
- Message
butter: expected two to four input arguments
RunMat:butter:InvalidOrder- When
- Filter order is missing, non-finite, non-integer, less than one, or too large.
- Message
butter: order must be a positive integer
RunMat:butter:InvalidFrequency- When
- Cutoff frequencies are malformed or outside the valid range.
- Message
butter: invalid cutoff frequency
Forms and outputs
b = butter(n,Wn) returns numerator coefficients as a row; [b,a] returns transfer-function rows suitable for filter(b,a,x) in digital mode. [z,p,k] returns zero-pole-gain form. [A,B,C,D] returns a controllable-canonical state-space realization.
The effective order doubles for bandpass and bandstop designs. Digital cutoff frequencies must be finite, greater than zero, and less than one, with one normalized to Nyquist. Analog cutoff frequencies must be finite and positive. Two-edge bands require strictly increasing cutoffs.
The documented cascaded-transfer-function (ctf) forms introduced in MATLAB R2024b are not implemented.
Classes, extensions, and residency
MATLAB-compatible calls use double for order and cutoff and limit order to 500. RunMat mode additionally admits independently gated integer, logical, single, resident, option-alias, and larger-order forms up to order 1024.
Typed integer order is parsed exactly as a structural control. Typed integer cutoff is explicitly converted at the double design boundary. Outputs are host double values or complex double tensors according to the designed coefficients and requested representation.
Filter design is host-side. MATLAB-compatible mode rejects resident arguments before gather; RunMat extensions may gather them non-destructively through their owner. Downstream filter can use a provider's iir_filter hook for supported resident signals; butter itself claims no GPU design kernel.
Examples
Low-pass filter a noisy signal
fs = 1000;
t = (0:999) / fs;
x = sin(2*pi*25*t) + 0.2*sin(2*pi*200*t);
[b, a] = butter(4, 80/(fs/2), 'low');
y = filter(b, a, x);High-pass filter coefficients
[b, a] = butter(2, 0.25, 'high');Band-pass filter coefficients
[b, a] = butter(3, [0.2 0.4], 'bandpass');Analog low-pass prototype
[b, a] = butter(1, 2, 's');
fprintf('%.0f %.0f; %.0f %.0f\n',b(1),b(2),a(1),a(2));Expected output:
0 2; 1 2Request zero-pole-gain outputs
[z, p, k] = butter(2,0.25);Request state-space outputs
[A, B, C, D] = butter(2,0.25);Reject a cutoff outside the digital band
butter(2,1.2)Using butter with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how butter changes the result.
Run a small butter example, explain the result, then change one input and compare the output.
FAQ
What does Wn mean for digital filters?⌄
It is normalized to Nyquist, so a 600 Hz cutoff at 4800 Hz sample rate uses 600/(4800/2).
Can I use the result with filter?⌄
Yes. Digital [b,a] outputs are row vectors accepted by filter(b,a,x).
Does butter execute on the GPU?⌄
No. Design runs on the host; admitted resident controls are gathered, and downstream filtering may use a separate provider hook.
Related Math functions
Signal
blackman · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how butter is executed, line by line, in Rust.
- View the source for butter in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.