Matlab

How to Create a Transfer Function Model in MATLAB

In control systems, a transfer function represents a relationship between the output signals and the input signals for all possible input values. These systems are represented by block diagrams in which blocks represent the transfer functions and arrows represent the input and output signals. The transfer functions are widely used to perform time domain as well as frequency domain analysis and controller design.

MATLAB supports the transfer functions by providing us with a built-in tf() function that can be used to quickly calculate the transfer function in MATLAB.

This article is going to explore the working of the tf() function to create a transfer function in MATLAB.

What is the Transfer Function?

In terms of mathematics, a transfer function is the ratio of the Laplace transform of output variables to the Laplace transform of input variables keeping all initial conditions to be zero. We can compute the transfer function by the given formula:

Here,

  • G(s) represents the transfer function.
  • C(s) represents the Laplace transform of output variables.
  • R(s) represents the Laplace transform of input variables.

A basic block diagram of the transfer function is given as:

Where input is provided to the transfer function to get the desired output.

How to Generate a Transfer Function Model?

A transfer function model can be created in MATLAB using the built-in tf() function. This function enables us to generate complex-valued or real-valued transfer function models or to transform dynamic system models in the form of transfer functions. This function can generate a transfer function model object either by directly specifying its coefficients or by transforming a model of another type. This function can also create uncertain state-space models or generalized state-space models.

Syntax

The tf() function uses different syntaxes to create a transfer function model in MATLAB, which are given below.

sys = tf(numerator,denominator)
sys = tf(numerator,denominator,ts)
sys = tf(numerator,denominator,ltiSys)
sys = tf(m)

 

Here,

The function sys = tf(numerator,denominator) generates a continuous time transfer function model by considering the numerator as well as denominator properties.

The function sys = tf(numerator,denominator,ts) generates a discrete-time transfer function model by considering the numerator as well as denominator properties.

The function sys = tf(numerator,denominator,ltiSys) generates a transfer function model that is inherited from the dynamic system model containing the sample time.

The function sys = tf(m) produces a transfer function model that indicates the static gain m.

Example

Consider some examples to understand the implementation of the tf() function in MATLAB.

Example 1: How to Create a Continuous Time SISO Transfer Function Model in MATLAB?

In this MATLAB code, we use the tf() function to create a continuous time SISO transfer function model in MATLAB.

numerator = [2 4];
denominator = [7,3];
sys = tf(numerator, denominator)

 

Example 2: How to Create a Discrete Time SISO Transfer Function Model in MATLAB?

The given example creates a discrete time SISO transfer function model in MATLAB using the tf() function.

numerator = [2 4];
denominator = [7,3];
sys = tf(numerator, denominator, 0.5)

 

Example 3: How to Create a Transfer Function Model Inherited from the Other in MATLAB?

In the given example, first, we create a transfer function model sys1 having properties TimeUnit and InputUnit set to minutes. After that, we create another transfer function model sys2 inherited from sys1 that yields the same properties as sys1.

num_1 = [3,2,1];
denom_1 = [5,9,0];
sys1 = tf(num_1,denom_1,'TimeUnit','minutes','InputUnit','minutes')
propValues1 = [sys1.TimeUnit,sys1.InputUnit]
num_2 = [-9,1];
denom_2 = [4,0,0,7];
sys2 = tf(num_2,denom_2,sys1)
propValues2 = [sys2.TimeUnit,sys2.InputUnit]

 

Example 4: How to Create a Static Gain MIMO Transfer Function Model in MATLAB?

In the MATLAB code, we use the tf(m) function to create a static gain MIMO transfer function model.

m = magic(2);
sys = tf(m)

 

Conclusion

The transfer functions indicate a relationship between the output signals as well as input signals for all possible input values. These functions can be visualized using block diagrams where blocks indicate the transfer function and arrows indicate the input and output signals. These functions are used to perform time domain as well as frequency domain analysis and controller design. MATLAB allows us to create transfer function models utilizing the built-in tf() function. The guide has presented different syntaxes of the tf() function and provides examples for each syntax to help us understand the working.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.