Written and maintained by CASRAI Editorial Board
Last updated
Quick answer: in MATLAB, a transfer function is created with tf(numerator, denominator), or by defining s = tf('s') and typing the rational expression directly. Coefficients are entered in descending powers of s. Both forms below produce the same model, G(s) = s / (s² + 3s + 2). The functions come from the Control System Toolbox.
This guide is for researchers and analysts who need to define a linear model in MATLAB, inspect it, and move it into step-response or state-space work. It adds a side-by-side comparison of the three ways to build the same model, and the output-format pitfalls that the reference pages treat separately.
What a transfer function is used for in research
A transfer function describes a linear time-invariant system as the ratio of a numerator polynomial N(s) to a denominator polynomial D(s). MathWorks documents this for single-input single-output (SISO) systems, and treats multi-input multi-output (MIMO) systems as arrays of SISO transfer functions. Researchers use the model to simulate a response, compare a fitted model with measurements, or convert it to another representation such as state space.
What is the function of a transfer function?
It gives a compact algebraic description of how a system maps an input to an output: the numerator and denominator coefficients together fix the model. In MATLAB the object you create stores that polynomial form, and the same object can then be simulated, plotted or converted.
Is a transfer function the same as gain?
No. A transfer function is a ratio of polynomials in s (or z for discrete time), not a single number. Gain appears as one parameter inside a model: in the zero-pole-gain form MATLAB documents with zpk(Z,P,K), K is the gain, alongside the zeros and poles.
Install or access
tf is documented in the Control System Toolbox, so check that this toolbox is part of your MATLAB installation. MathWorks notes separately that uncertain models need the Robust Control Toolbox, identified models need the System Identification Toolbox, and parallel computation needs the Parallel Computing Toolbox. For licence questions see MATLAB licence types and what they cover; obtain MATLAB only from MathWorks or through your institution.
Step-by-step: define and use a transfer function in MATLAB
How to do a transfer function in MATLAB
- Write the model with descending powers. For G(s) = s / (s² + 3s + 2) the numerator coefficients are
[1 0]and the denominator coefficients are[1 3 2]. - Create the model.
num = [1 0]; den = [1 3 2]; G = tf(num, den); - Or build it from the variable s.
s = tf('s'); G = s/(s^2 + 3*s + 2); - Add a sample time for a discrete-time model.
sys = tf(numerator, denominator, ts); passingts = -1leaves the sample time unspecified. For a discrete variable usez = tf('z', ts). - Plot the step response.
step(G)with no output arguments plots it;[y, tOut] = step(G)returns the data instead. - Read the coefficients back.
[num, den] = tfdata(G)returns cell arrays;[num, den] = tfdata(G, 'v')returns row vectors for a SISO model. - Convert to state space.
sys_ss = ss(G).
One runnable block covering the whole workflow:
s = tf('s');
G = s/(s^2 + 3*s + 2);
step(G) % plot the step response
[num, den] = tfdata(G, 'v'); % coefficients as row vectors
G_ss = ss(G); % state-space version of the same model
Three ways to build the same model
The constructions below are taken from the MathWorks Transfer Functions page and the tf reference page.
| Method | Code for G(s) = s/(s²+3s+2) | What it stores | Use it when |
|---|---|---|---|
| Coefficient vectors | G = tf([1 0],[1 3 2]); |
Polynomial form | You already have fitted or tabulated coefficients. |
| Rational expression | s = tf('s'); G = s/(s^2+3*s+2); |
Polynomial form | The model is written as a formula in your paper or notes. |
| Zero-pole-gain | G = zpk(Z,P,K); with Z the zeros, P the poles, K the gain |
Zero-pole-gain form | You know pole and zero locations rather than coefficients. |
The “use it when” column is editorial guidance; the other columns follow the documentation. The documentation example for zpk uses Z=[0]; P=[-1-1i -1+1i -2]; K=5;, which is a different model from the one above.
Output and how to read it
Displaying a model prints its polynomial form and its type. The tf reference example with numerator 1 and denominator [2,3,4] displays 1 / (2 s² + 3 s + 4) and labels it a continuous-time transfer function. step returns the response samples in y and the time vector in tOut; by default the response starts at time 0 with a unit step. MathWorks lists impulse, initial and lsim as related functions. For formatting the resulting figure, see MATLAB graphing and MATLAB plot color.
Troubleshooting
- Wrong dynamics from correct-looking coefficients.
tfreads coefficients in descending powers of s.[1 3 2]means s² + 3s + 2; entering the same numbers in ascending order describes a different model. - Cell-array output from
tfdata. By defaulttfdatareturns cell arrays. For a SISO model add'v'to get plain row vectors. - Discrete versus continuous. Omitting
tsgives a continuous-time model. Supply a sample time, or usez = tf('z', ts), for discrete time. MathWorks also providesfiltfor a discrete transfer function in the DSP convention. - Function not found.
tf,zpk,tfdataandssare documented in the Control System Toolbox, so confirm the toolbox is installed and licensed.
For block-diagram simulation of the same model, see MATLAB Simulink. For state estimation built on state-space models, see the Kalman filter guide.
Free alternatives
| Tool | Transfer-function entry point | Source read |
|---|---|---|
| Python Control Systems Library | control.tf(num, den[, dt]) creates a transfer function and can create MIMO systems; the library reference also lists tf2ss, tfdata and a MATLAB compatibility module |
python-control.readthedocs.io, read 2026-11-08 |
GNU Octave, control package |
Control package for system analysis and control synthesis; version 4.3.0 listed 2026-11-01, requires Octave 6.4.0 or later | gnu-octave.github.io/packages/control, read 2026-11-08 |
Check each library’s own documentation for exact function names and differences from MATLAB before porting scripts.
FAQ
How do I do a transfer function?
Write the system as a numerator polynomial over a denominator polynomial in s, then enter the coefficients in descending powers. In MATLAB that is tf(num, den).
What is the difference between tf and zpk?
tf stores the polynomial form; zpk stores zeros, poles and a gain.
How do I plot a transfer function?
Call step(G) for the step response; the function plots when no output arguments are requested.
How do I get state space from a transfer function in MATLAB?
Use ss(G) on the transfer function model.
Sources
- MathWorks, tf: Transfer function model, read 2026-11-08.
- MathWorks, Transfer Functions, read 2026-11-08.
- MathWorks, tfdata, step and ss, read 2026-11-08.
- Python Control Systems Library: control.tf, read 2026-11-08.
- GNU Octave control package, read 2026-11-08.







