Transfer Functions in MATLAB
Palavras-chave:
Publicado em: 21/08/2025Transfer Functions in MATLAB
Transfer functions are a fundamental tool in control systems engineering for representing the input-output relationship of a linear, time-invariant (LTI) system in the Laplace domain. This article will guide you through creating, manipulating, and analyzing transfer functions using MATLAB.
Fundamental Concepts / Prerequisites
Before diving into the implementation, it's helpful to have a basic understanding of the following:
- Linear Time-Invariant (LTI) Systems: Systems whose behavior doesn't change over time and obey the superposition principle.
- Laplace Transform: A mathematical transformation that converts a time-domain function into a complex-frequency domain function (s-domain).
- Polynomial Representation: Understanding how to represent polynomials with coefficients is crucial.
- MATLAB Basics: Familiarity with MATLAB syntax and basic commands.
A transfer function, denoted as G(s), is defined as the ratio of the Laplace transform of the output Y(s) to the Laplace transform of the input U(s), assuming zero initial conditions: G(s) = Y(s) / U(s).
Implementation in MATLAB
MATLAB provides a dedicated function, tf()
, to create transfer function objects. Here's how to define a transfer function and perform some basic operations:
% Define the numerator and denominator coefficients
numerator = [1 2]; % Represents the polynomial s + 2
denominator = [1 5 6]; % Represents the polynomial s^2 + 5s + 6
% Create the transfer function object
G = tf(numerator, denominator);
% Display the transfer function
disp('Transfer Function G(s):');
disp(G);
% Evaluate the transfer function at a specific frequency (s = jw, w = 1)
s = 1i; % s = j*w, w=1
value_at_jw = polyval(numerator, s) / polyval(denominator, s);
disp(['Value of G(s) at s = j: ' num2str(value_at_jw)]);
%Find poles and zeros of the transfer function
zeros_val = zero(G);
poles_val = pole(G);
disp('Zeros of G(s)');
disp(zeros_val);
disp('Poles of G(s)');
disp(poles_val);
% Example of creating a transfer function using symbolic variables
s = tf('s'); % Define 's' as a transfer function variable
H = (s + 3) / (s^2 + 7*s + 10);
disp('Transfer Function H(s):');
disp(H);
Code Explanation
The code above demonstrates how to create and manipulate transfer functions in MATLAB. Let's break it down:
Line 2-3: We define the numerator and denominator coefficients as vectors. The order of the coefficients corresponds to descending powers of 's'. For example, numerator = [1 2]
represents the polynomial s + 2, and denominator = [1 5 6]
represents s2 + 5s + 6.
Line 6: The tf(numerator, denominator)
function creates a transfer function object named G
. MATLAB stores this object internally with the numerator and denominator information.
Line 9-10: The disp()
function displays the transfer function in the command window, providing a visual representation.
Line 13-15: Calculates G(s) value at a complex frequency (s = j) using `polyval` which evaluates polynomial at a given value. The numerator and denominator are evaluated at s=j and then divided. This shows how to obtain the magnitude and phase response at a particular frequency.
Line 18-22: `zero(G)` and `pole(G)` functions find the zeros and poles of the transfer function. Zeros and poles are complex numbers where the magnitude of the transfer function are zero and infinity respectively.
Line 25-28: This shows an alternative method using symbolic variables. s = tf('s')
defines 's' as a transfer function variable. Then we can construct the transfer function H
using symbolic expressions, which can be more convenient for complex transfer functions.
Complexity Analysis
The complexity of operations on transfer functions in MATLAB primarily depends on the degree of the numerator and denominator polynomials.
Time Complexity:
- Creating a transfer function using
tf()
: The complexity is approximately O(n + m), where n is the degree of the numerator and m is the degree of the denominator, due to memory allocation and data copying. - Evaluating the transfer function using
polyval()
: The `polyval()` function has a time complexity of O(max(n, m)), where n and m are the degrees of the polynomials being evaluated. - Finding poles and zeros: The
zero()
andpole()
functions rely on root-finding algorithms, which can have a time complexity that scales roughly as O(max(n, m)^3) in the worst case, although in practice they often perform much faster.
Space Complexity:
- Storing a transfer function requires space proportional to the degree of the numerator and denominator polynomials, resulting in a space complexity of O(n + m).
Alternative Approaches
Instead of using the tf()
function with numerator and denominator coefficients, you could also represent transfer functions using their zero-pole-gain (zpk) representation. This can be done using the zpk()
function in MATLAB. The zpk representation can be useful when the zeros and poles of the system are already known, or when analyzing system stability. The trade-off is that converting between tf and zpk representations can be computationally intensive, particularly for high-order systems.
Another alternative is to represent the system in state-space form, using the ss()
function. This is particularly useful when working with MIMO (Multiple-Input Multiple-Output) systems or when dealing with nonlinear systems that have been linearized around an operating point. State-space representations can be more general than transfer functions, but the transformation between state-space and transfer function form might introduce additional computational overhead.
Conclusion
Transfer functions are a powerful tool in MATLAB for analyzing and designing control systems. The tf()
function provides a straightforward way to define and manipulate transfer functions based on their polynomial representation. By understanding how to create, evaluate, and analyze transfer functions, you can gain valuable insights into the behavior of LTI systems. Remember to consider the complexity implications of different operations, especially when dealing with high-order systems. Alternative representations like zpk and state-space may be more appropriate depending on the specific application.