A Butterworth filter is a signal processing filter designed to maintain a perfectly flat frequency response in the passband without any ripples. When engineers and researchers search for a 'butter filter matlab' implementation, they are looking to apply this maximally flat magnitude response using MATLAB's butter function to clean up sampled data, design digital control loops, or simulate analog crossover networks. In a real circuit or digital signal processing (DSP) installation, applying this filter changes the signal by smoothly rolling off unwanted frequency components—such as high-frequency PWM switching noise from a variable frequency drive (VFD)—without introducing the passband amplitude variations that could corrupt sensitive sensor readings or audio fidelity.

The Core Math and MATLAB Syntax

The defining characteristic of the Butterworth filter is its maximally flat passband. Mathematically, the magnitude squared of the frequency response is given by |H(jω)|² = 1 / (1 + (ω/ωc)^(2n)), where n is the filter order and ωc is the cutoff frequency. This ensures that the first 2n-1 derivatives of the magnitude response are zero at DC (for low-pass), resulting in zero ripple.

In MATLAB, the butter function generates the filter coefficients. By default, it designs a digital Infinite Impulse Response (IIR) filter using the bilinear transform method. If you need an analog filter transfer function for Laplace-domain circuit simulation, you must append the 's' argument.

Critical DSP Warning: For filter orders greater than 6, using the standard transfer function syntax [b,a] = butter(n, Wn) can lead to severe numerical instability due to coefficient quantization errors in the polynomial roots. For high-order designs, always use the zero-pole-gain [z,p,k] or second-order sections [sos] output formats.

Below is a reference table detailing how the filter order directly impacts the roll-off rate and stopband attenuation. This data is crucial when deciding how aggressive your filter needs to be without overloading your microcontroller's compute budget.

Filter Order (n) Number of Poles Roll-Off Rate Attenuation at 2× fc Attenuation at 10× fc
1st Order 1 -20 dB/decade (-6 dB/oct) -7.0 dB -20.0 dB
2nd Order 2 -40 dB/decade (-12 dB/oct) -12.0 dB -40.1 dB
4th Order 4 -80 dB/decade (-24 dB/oct) -24.1 dB -80.4 dB
6th Order 6 -120 dB/decade (-36 dB/oct) -36.1 dB -120.2 dB
8th Order 8 -160 dB/decade (-48 dB/oct) -48.2 dB -160.3 dB

Worked Numeric Example: 4th-Order Low-Pass Design

Let's design a digital low-pass Butterworth filter to clean up vibration data from an accelerometer mounted on a 3-phase induction motor. The motor is driven by a VFD with a PWM switching frequency of 4000 Hz. Our data acquisition (DAQ) system samples at 8000 Hz (Fs), and we only care about mechanical vibration frequencies below 1000 Hz (fc).

Normalization Step: MATLAB's digital butter function requires the cutoff frequency to be normalized to the Nyquist frequency (Fs/2).
Nyquist = 8000 / 2 = 4000 Hz.
Normalized Wn = 1000 / 4000 = 0.25.

We will use a 4th-order filter to ensure aggressive attenuation of the 4000 Hz PWM noise. At 4000 Hz (which is 4× our cutoff), a 4th-order Butterworth provides roughly -48 dB of attenuation, effectively killing the switching noise.

% Define sampling frequency and desired cutoff
Fs = 8000;          % Sampling frequency in Hz
Fc = 1000;          % Cutoff frequency in Hz
order = 4;          % Filter order

% Calculate normalized cutoff frequency (0 to 1 range)
Wn = Fc / (Fs / 2); % Yields 0.25

% Design the filter using Second-Order Sections (SOS) for numerical stability
[sos, g] = butter(order, Wn, 'low');

% Generate a test signal: 50Hz sine wave + 4000Hz PWM noise
t = 0:1/Fs:1-1/Fs;
raw_signal = sin(2*pi*50*t) + 0.5*sin(2*pi*4000*t);

% Apply the filter using filtfilt to eliminate phase distortion
filtered_signal = filtfilt(sos, g, raw_signal);

% Plot the frequency response to verify the design
figure;
freqz(sos, g, 1024, Fs);
title('4th-Order Butterworth Low-Pass Filter Response');

Notice the use of filtfilt instead of filter. While filter processes the signal in real-time (causing phase shift), filtfilt runs the signal forward and backward through the filter. This doubles the effective order to 8th-order (yielding -96 dB attenuation at 4000 Hz) and guarantees zero phase distortion, which is critical when analyzing the exact timing of mechanical impacts in vibration analysis.

Where You Meet This in Practice

While we simulate and design these in MATLAB, the underlying math translates directly to both digital microcontrollers and physical analog workbenches. Here is where you will encounter Butterworth topologies in the field:

  • Biomedical Instrumentation (ECG/EEG): Electrocardiogram machines use Butterworth band-pass filters (typically 0.5 Hz to 150 Hz) to isolate the heart's electrical activity. The flat passband ensures the amplitude of the QRS complex is not distorted, which is vital for accurate diagnostic measurements.
  • Audio Crossover Networks: In high-fidelity analog speaker systems, 2nd-order (12 dB/oct) or 4th-order (24 dB/oct) Butterworth filters are built using op-amps, capacitors, and inductors. They split the audio spectrum between tweeters and woofers without introducing resonant peaks that would color the sound.
  • Anti-Aliasing Before ADCs: Before an analog signal hits an Analog-to-Digital Converter, an analog Butterworth low-pass filter is placed in the signal path to hard-cut frequencies above the Nyquist limit, preventing high-frequency noise from folding back into the baseband as unremovable aliasing artifacts.
  • Phase-Locked Loops (PLLs): In RF and power electronics, the loop filter of a PLL is often designed as a Butterworth filter to balance lock-time and phase noise rejection, ensuring a clean synthesized output frequency.

Common Confusions and Filter Selection

What people commonly confuse the Butterworth filter with are other classical IIR filter designs—specifically Chebyshev, Bessel, and Elliptic filters. Choosing the wrong one can ruin a control system or measurement setup. Here is how to distinguish them and when to use which:

Filter Type Passband Behavior Stopband Behavior Phase Linearity Best Use Case
Butterworth Maximally Flat (No ripple) Moderate roll-off Non-linear General purpose, audio, sensor data where amplitude accuracy in the passband is critical.
Chebyshev Type I Equi-ripple (Amplitude varies) Steeper roll-off than Butter Poor RF channel selection where you need a sharp cutoff and can tolerate slight passband ripple.
Bessel Flat magnitude Very slow roll-off Highly Linear Pulse and square-wave preservation (e.g., digital communications) where wave shape matters more than noise rejection.
Elliptic (Cauer) Equi-ripple Equi-ripple, steepest cutoff Poor Strict bandwidth constraints where compute/memory is limited and you need maximum noise rejection in the minimum order.

If you are analyzing the magnitude of a vibration spectrum and need to ensure that a peak at 800 Hz isn't artificially suppressed by the filter's own roll-off curve, stick to the Butterworth. If you are feeding a square wave into an oscilloscope trigger circuit and need to preserve the sharp edges without ringing, switch to a Bessel design using MATLAB's besself function instead.

Pro-Tip for MATLAB Users: Always verify your digital filter design using the freqz function before deploying the coefficients to an embedded C environment (like an ARM Cortex-M4 or an ESP32). Plotting the response reveals whether your chosen bit-depth for the fixed-point coefficients will cause the filter to become unstable or deviate from the ideal Butterworth curve.