RunMat
GitHub

butter — Design Butterworth IIR filters.

butter(n, Wn) designs an order-n Butterworth filter. Digital designs use MATLAB's normalized convention where Wn = 1 is Nyquist. Scalar Wn produces a lowpass filter by default; a two-element Wn produces a bandpass filter by default. Add an ftype string for low, high, bandpass, or stop, and add 's' for analog transfer functions.

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

NameTypeRequiredDefaultDescription
nIntegerScalarYesFilter order.
WnNumericArrayYesNormalized digital cutoff frequency or analog cutoff frequency.
ftypeStringScalarNo"low" for scalar Wn, "bandpass" for two-element WnFilter type: low, high, bandpass, or stop.
WnNumericArrayYesAnalog cutoff frequency.
sStringScalarYesAnalog filter-design flag.
sStringScalarNoAnalog filter-design flag.

Returns

NameTypeDescription
bNumericArrayNumerator coefficient vector.
aNumericArrayDenominator coefficient vector.
zNumericArrayFilter zeros.
pNumericArrayFilter poles.
kNumericScalarFilter gain.
ANumericArrayState matrix.
BNumericArrayInput matrix.
CNumericArrayOutput matrix.
DNumericScalarFeedthrough term.

Returned values from butter depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:butter:ArgCountThe argument count is outside butter's supported forms.butter: expected two to four input arguments
RunMat:butter:InvalidOrderFilter order is missing, non-finite, non-integer, less than one, or too large.butter: order must be a positive integer
RunMat:butter:InvalidFrequencyCutoff frequencies are malformed or outside the valid range.butter: invalid cutoff frequency

How butter works

  • b = butter(n, Wn) returns numerator coefficients as a row vector.
  • [b, a] = butter(...) returns numerator and denominator coefficient row vectors suitable for filter(b, a, x) in digital mode.
  • [z, p, k] = butter(...) returns zero-pole-gain form.
  • [A, B, C, D] = butter(...) returns a controllable-canonical state-space realization.
  • Digital cutoff frequencies must be finite, greater than 0, and less than 1. Analog cutoff frequencies must be finite and greater than 0.
  • Bandpass and bandstop designs require a strictly increasing two-element Wn vector.

Examples

Low-pass filtering 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);

Expected output:

y contains the low-pass filtered signal.

High-pass filter coefficients

[b, a] = butter(2, 0.25, 'high')

Expected output:

b and a are row-vector IIR coefficients.

Band-pass filter coefficients

[b, a] = butter(3, [0.2 0.4], 'bandpass')

Expected output:

b and a each contain 7 coefficients.

Analog low-pass prototype

[b, a] = butter(1, 2, 's')

Expected output:

b = [0 2]
a = [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?

RunMat follows MATLAB's normalized digital convention: Wn = 1 is the Nyquist frequency, so a 600 Hz low-pass filter at a 4800 Hz sample rate uses butter(n, 600/(4800/2)).

Can I use the result directly with filter?

Yes. Digital [b, a] outputs are ordinary row vectors and can be passed directly to filter(b, a, x).

Does butter execute on the GPU?

No. It generates small coefficient arrays on the host. GPU acceleration applies when those coefficients are used by filter with a real gpuArray signal and a provider that implements iir_filter.

Signal

blackman · conv · conv2 · deconv · filter · hamming · hann · sawtooth · sinc · square

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · pinv · rank · rcond · rref

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how butter is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.