Skip to main content
v2026.11,986 entries · CC-BY 4.0

filt in MATLAB: DSP-Form Transfer Functions vs filter

filt creates a z^-1 transfer function model, not filtered data. Syntax, worked examples, and when to use filter or filtfilt instead.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

filt in MATLAB creates a discrete-time transfer function model written in DSP form: a ratio of two polynomials in z-1, with coefficients listed in ascending powers of z-1. It builds a model object, a tf object whose Variable property is set to "z^-1". It does not filter your data. MathWorks’ own reference page says so directly: “To filter vector data, use filter instead.” If you have a signal in a variable and want a smoothed or band-limited version of it, you want filter (core MATLAB) or filtfilt (zero-phase filtering, documented in the Signal Processing Toolbox area). If you want to analyse a digital filter as a system, with a model you can pass to Control System Toolbox analysis and design tools, you want filt.

This guide explains what each of the three functions takes and returns, walks through filt with the three examples from the current MathWorks documentation, shows how filter and filtfilt are called on real data, lists the documented limits that cause most errors, and points to free alternatives in Python (SciPy) and Octave. All behaviour described here comes from the MathWorks, SciPy and Octave documentation pages listed under Sources, read on 2026-11-12; the MathWorks filt page was the R2026b documentation.

What it is used for in research

Researchers who record sampled signals (physiological traces, accelerometer or sensor streams, instrument voltages, audio) often describe a digital filter by two coefficient vectors, a numerator and a denominator. That pair can be used in two quite different ways, and the three function names in the search results map onto them:

  • Describe the filter as a system. filt(numerator,denominator) turns the coefficient vectors into a discrete-time transfer function model. You then use that model with other Control System Toolbox functions that accept transfer function models, for example to inspect or combine it with other systems. The result is a model, not a filtered signal.
  • Apply the filter to data in one pass. y = filter(b,a,x) runs the filter along the data and returns the filtered signal. It is the one that introduces the usual delay (phase shift) associated with causal filtering.
  • Apply the filter to data forward and backward. y = filtfilt(b,a,x) filters in the forward direction, then reverses the result and filters again. The MathWorks page describes the outcome as “zero phase distortion”, with an effective transfer function equal to the squared magnitude of the filter’s response and an effective filter order that is double the original.

The practical consequence for a methods section is that “filtered with filt” is never a correct description of what was done to data. If a script uses filt, it is creating a model; the data processing in that script must happen in another call. When you report filtering in a paper or a data-management plan, state the function actually applied to the samples, the coefficients or design specification, and whether the processing was one-pass or zero-phase, because those choices change timing in the output. For how analysts document processing steps alongside datasets, see the CASRAI guide on signal analysis in MATLAB.

How to install or access it

The three functions live in different parts of the MathWorks documentation, which is the clearest guide to where each is supported:

  • filter is documented in the core MATLAB reference (mathworks.com/help/matlab/ref/filter.html), so it needs no add-on product.
  • filt is documented in the Control System Toolbox reference (mathworks.com/help/control/ref/filt.html). Its history note reads “Introduced before R2006a”, so it is a long-standing function, not a recent addition.
  • filtfilt is documented under the Signal Processing Toolbox area (mathworks.com/help/signal/ref/filtfilt.html), and its own example uses designfilt to build a filter object.

Obtain MATLAB and its toolboxes only from MathWorks (mathworks.com), or through your institution’s campus or site licence administered by your IT or research-computing office. Licensing terms and costs are set by MathWorks and your institution; check them there, because this page does not describe them. To see whether a toolbox function is available in your session, type help filt or doc filt at the command prompt; if the toolbox is not installed, MATLAB will not find the function.

Step-by-step task: build a DSP-form transfer function with filt

The reference page defines four syntaxes:

  • sys = filt(numerator,denominator): creates the model with unspecified sample time.
  • sys = filt(numerator,denominator,ts): sets the sample time ts.
  • sys = filt(m): creates a model that represents a static gain matrix m.
  • sys = filt(___,Name=Value): sets model properties such as InputName. The filt page refers to the tf reference page for the list of available properties.

Step 1. Write coefficients in ascending powers of z-1

The numerator and denominator are row vectors whose first element is the constant term (the z0 coefficient), the second multiplies z-1, the third z-2, and so on. Coefficients can be real or complex. This is the most common source of confusion: the vector [2,5,7] means 2 + 5z-1 + 7z-2.

Step 2. Create the model

Example 1 from the MathWorks page:

numerator = [2,5,7];
denominator = [6,8,3];
sys = filt(numerator,denominator)

MATLAB prints the model as (2 + 5 z^-1 + 7 z^-2) over (6 + 8 z^-1 + 3 z^-2), followed by “Sample time: unspecified” and “Discrete-time transfer function.” The page notes that the same model can be created with tf:

systf = tf(numerator,denominator,-1,Variable="z^-1")

That is the useful way to remember what filt does: it is shorthand for a discrete-time tf with the sample time set to -1 (unspecified) and the variable set to "z^-1". The CASRAI guides on tf in MATLAB and transfer functions in MATLAB cover the general tf function.

Step 3. Add a sample time when the sampling interval matters

Example 2 from the page uses a third argument:

numerator = [2,9];
denominator = [3,5,7,1];
ts = 0.2;
sys = filt(numerator,denominator,ts)

The result is (2 + 9 z^-1) over (3 + 5 z^-1 + 7 z^-2 + z^-3) with “Sample time: 0.2 seconds”. The argument ts is a positive scalar expressed in the time unit of the model’s TimeUnit property, or -1 for an unspecified sample time. Note that the denominator has four coefficients and the numerator two, so the numerator and denominator do not need to be the same length.

Step 4. Build a two-input model with cell arrays and named inputs

Example 3 shows a multi-input model. For multiple inputs or outputs, the numerator is an Ny-by-Nu cell array of row vectors, where Ny is the number of outputs and Nu the number of inputs:

numerator = {1,[1 0.3]};
denominator = {[1 1 2],[5 2]};
sys = filt(numerator,denominator,InputName=["channel1","channel2"])

The output lists each path separately: from input “channel1”, 1 over (1 + z^-1 + 2 z^-2); from input “channel2”, (1 + 0.3 z^-1) over (5 + 2 z^-1). If both arguments are cell arrays they must have the same dimensions. If every single-input, single-output entry of a MIMO model shares one denominator, you can pass one row vector as the denominator while the numerator stays a cell array.

Step 5. Create a static gain

sys = filt(m), with m a scalar or matrix, creates a model for a static gain: the steady-state ratio of output to input.

Applying a filter to data: filter and filtfilt

Because most searches for “filt” in MATLAB end in a data-processing goal, here are the two functions that do the work, with the behaviour the MathWorks pages document.

filter: one-pass filtering

Syntax: y = filter(b,a,x), plus filter(b,a,x,zi), filter(b,a,x,zi,dim) and [y,zf] = filter(___). If a(1) is not equal to 1, filter normalizes the coefficients by a(1), so a(1) must be nonzero. For a vector input, the output has the same size. For a matrix, filter works along the first dimension (down the columns); for N-D arrays it works along the first non-singleton dimension. Use dim to override this: y = filter(b,a,x,[],2) filters each row, and the empty array [] stands for default (zero) initial conditions.

The MathWorks moving-average example shows the idiom:

windowSize = 5;
b = (1/windowSize)*ones(1,windowSize);
a = 1;
y = filter(b,a,x);

For other smoothing approaches in MATLAB, see the CASRAI guide on the moving average in MATLAB, and for FIR design see FIR filters in MATLAB.

Streaming and chunked data. The initial-conditions vector zi has length max(length(a),length(b))-1; the default is zero delays. The final-conditions output zf lets you continue filtering: passing the zf from one data segment as the zi of the next gives the same result as filtering the whole sequence at once. The documentation example uses past samples x_past = [1 3] with a three-point average and obtains zf = [1.3333; 1], then y = filter(b,a,x,zf) returns 2 2 3 3 4 3.

filtfilt: zero-phase filtering

filtfilt accepts several input forms: filtfilt(b,a,x), filtfilt(sos,g,x) for second-order sections with a gain, filtfilt(d,x) for a digital filter object d, filtfilt(B,A,x,"ctf") for cascaded transfer function form, and filtfilt({B,A,g},x), plus optional name-value arguments. The documentation example designs a lowpass equiripple FIR filter and compares the two functions on an ECG-style signal:

d = designfilt("lowpassfir",PassbandFrequency=0.15, ...
    StopbandFrequency=0.2,PassbandRipple=1, ...
    StopbandAttenuation=60,DesignMethod="equiripple");
y  = filtfilt(d,x);   % zero-phase
y1 = filter(d,x);     % conventional, delayed

According to the page, the zero-phase result preserves the timing of the QRS complex in the waveform, while the conventionally filtered output is delayed. That timing difference is the main reason an analyst chooses filtfilt for offline analysis of recorded data.

Output and how to read it

  • From filt: a tf model object. Read the printout as numerator over denominator in z^-1. The leading “Sample time” line tells you whether ts was set (“unspecified” for -1, or a value in seconds as in Example 2). It is a model of the filter, not a processed signal.
  • From filter: numeric data y with the same size as x for vector input, plus the optional final-state vector zf in the two-output form.
  • From filtfilt: a filtered signal with no phase delay. Per the documentation, single-precision input returns single-precision output; otherwise the output is double. Expect the response to be the filter’s magnitude response applied twice (squared magnitude) and its order doubled, so a filter designed to a stopband specification will attenuate more strongly than the same specification applied once.

The data table below compares the functions side by side, including SciPy and Octave equivalents, with a source for each row.

Troubleshooting

The output is a model, not my data

You called filt. It returns a tf object with Variable set to "z^-1". Use filter(b,a,x) or filtfilt(b,a,x) to process x.

The coefficients look reversed

filt reads coefficients in ascending powers of z-1. The first element is the constant term. A vector written for a descending-power convention (highest power first) will produce a different model, so check that the printed transfer function matches the equation you intended.

Undefined function or no results for filt or filtfilt

These two functions are documented in the Control System Toolbox and Signal Processing Toolbox areas respectively, so a session without those toolboxes will not find them. filter is core MATLAB and always available.

filtfilt errors about signal length or filter order

The MathWorks page states that x must be finite and its length must be greater than three times the filter order, where the order is max(length(B)-1,length(A)-1). For second-order-section input, sos needs at least two sections. A short recording filtered with a long filter will fail this requirement.

filtfilt on a differentiator or Hilbert filter

filtfilt is documented as not suitable for differentiator or Hilbert FIR filters. Use filter for those.

The first and last samples look distorted

Edge handling is controlled by the PaddingPattern option: "linear" is the default, with "reflect" and "none" as alternatives. The R2026a documentation also adds InitialStatesMethod ("const", "gustafsson", "zero") and TransientLength ("filtord", "stepzlen" or a nonnegative integer) name-value arguments. Check which release you run before relying on the newer options.

filter returns unexpected scaling

If a(1) is not 1, filter divides all coefficients by it. A zero a(1) is not allowed. The same requirement, a nonzero first denominator coefficient, applies to filtfilt.

My matrix was filtered along the wrong direction

The default for filter is the first non-singleton dimension, which is down the columns for a matrix. Pass dim (1 for columns, 2 for rows) as the fifth argument, with [] as the fourth, to choose the direction.

Free alternatives

To apply a filter to data without MATLAB, two documented free options are the Python library SciPy and the Octave signal package. Neither page documents a function that builds a DSP-form transfer function model like filt; they cover the data-filtering side, so this table maps to filtfilt.

Option Function What its documentation says
SciPy (Python) scipy.signal.filtfilt(b, a, x, axis=-1, padtype='odd', padlen=None, method='pad', irlen=None) Zero-phase forward-backward filtering with doubled filter order. When padlen is None the pad length is 3*max(len(a), len(b)).
SciPy (Python) scipy.signal.sosfiltfilt The SciPy page says it “should be preferred over filtfilt for most filtering tasks, as second-order sections have fewer numerical problems.”
Octave (signal package) y = filtfilt(b,a,x) “Forward and reverse filter the signal.” The page cautions that in practice the phase correction is not perfect and the magnitude response is distorted, particularly in the stop band.

For a Python route to signal work, see the CASRAI guide on SciPy signals. Whichever tool you use, record the coefficients, the padding option and the function name in your analysis log so another group can reproduce the timing of the output.

FAQ

What is the difference between filt and filter in MATLAB?

filt creates a discrete-time transfer function model from numerator and denominator coefficients in DSP form. filter applies a filter, given as b and a, to a data array and returns the filtered data. MathWorks directs users to filter for filtering vector data.

What is the difference between filt and tf?

For a discrete-time model in DSP form they produce the same result. The MathWorks page shows filt(numerator,denominator) as equivalent to tf(numerator,denominator,-1,Variable="z^-1"). The practical difference is the convention: filt reads coefficients in ascending powers of z-1 and sets the variable for you.

How do I do zero-phase filtering in MATLAB?

Use filtfilt, for example y = filtfilt(b,a,x), or filtfilt(d,x) with a filter object from designfilt. It filters forward and backward, giving zero phase distortion, an effective transfer function equal to the squared magnitude, and a doubled effective order.

Does filt filter a signal?

No. It returns a model object. The reference page states that to filter vector data you should use filter.

What toolbox does filt need?

filt is documented in the Control System Toolbox reference. filtfilt is documented in the Signal Processing Toolbox area, and filter is part of core MATLAB.

Is there a free equivalent of filtfilt?

Yes. SciPy provides scipy.signal.filtfilt and sosfiltfilt, and the Octave signal package provides filtfilt.

Sources

All pages read on 2026-11-12.

Data: filt, filter and filtfilt compared with SciPy and Octave equivalents

Side-by-side comparison of MATLAB filt, filter and filtfilt and the SciPy and Octave filtfilt functions: what each takes, what it returns, and documented limits. Compiled from the official MathWorks, SciPy and Octave Forge reference pages.

filt, filter and filtfilt compared with SciPy and Octave equivalents
FunctionEnvironmentTakes data to filterReturnsPhase behaviourDocumented constraint
filt(numerator,denominator,ts)MATLAB, Control System Toolbox referenceNotf model object with Variable z^-1Not applicable (model)Coefficients in ascending powers of z^-1; use filter for vector data
filter(b,a,x)MATLAB, core referenceYesFiltered data, same size as vector inputConventional one-pass (delayed output in the documentation example)a(1) must be nonzero; coefficients normalized by a(1)
filtfilt(b,a,x)MATLAB, Signal Processing Toolbox areaYesFiltered dataZero phase distortion; squared magnitude; double effective orderx finite, length greater than 3 times filter order; not for differentiator or Hilbert FIR
scipy.signal.filtfiltPython, SciPyYesFiltered dataZero phase; order doubledDefault padlen is 3*max(len(a),len(b)); sosfiltfilt preferred for most tasks
filtfilt(b,a,x)Octave, signal packageYesFiltered dataForward and reverse filteringPhase correction not perfect; magnitude response distorted, especially in the stop band

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about filt in MATLAB: DSP-Form Transfer Functions vs filter

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →