Generating the Transfer Function in MATLAB (Step-by-
Step)
Step 1: Open MATLAB
Launch MATLAB and open the Command Window or a script file (.m file).
Step 2: Define the Numerator and Denominator
In MATLAB, we represent the numerator and denominator as arrays of coefficients starting
from the highest power of sss.
matlab
CopyEdit
num = [5 3]; % Coefficients of the numerator (5s + 3)
den = [1 4 6]; % Coefficients of the denominator (s^2 + 4s + 6)
Step 3: Create the Transfer Function
Use the tf function to define the transfer function:
matlab
CopyEdit
H = tf(num, den);
disp('Transfer Function:');
disp(H);
This will display the transfer function in the MATLAB console.
Step 4: Analyze the Transfer Function
1. Plot the Step Response
A step response shows how the system reacts to a unit step input.
matlab
CopyEdit
step(H);
title('Step Response of the System');
2. Plot the Impulse Response
An impulse response shows the reaction to a sudden pulse input.
matlab
CopyEdit
impulse(H);
title('Impulse Response of the System');
3. Plot the Bode Plot
A Bode plot helps analyze the frequency response of the system.
matlab
CopyEdit
bode(H);
title('Bode Plot of the System');
4. Plot the Pole-Zero Map
The pole-zero map shows the stability and dynamic behavior of the system.
matlab
CopyEdit
pzmap(H);
title('Pole-Zero Map');
Alternative: Transfer Function from Poles and Zeros
Instead of defining the transfer function using numerator and denominator polynomials, you can
use zero-pole-gain representation:
matlab
CopyEdit
z = [-1 -2]; % Zeros
p = [-3 -4]; % Poles
k = 5; % Gain
H_zpk = zpk(z, p, k); % Define transfer function in zero-pole-gain format
disp(H_zpk);
Step 5: Convert to State-Space Representation (Optional)
You can also convert the transfer function to state-space representation:
matlab
CopyEdit
[A, B, C, D] = tf2ss(num, den);
disp('State-Space Representation:');
disp('A = '); disp(A);
disp('B = '); disp(B);
disp('C = '); disp(C);
disp('D = '); disp(D);
Summary of MATLAB Steps
1. Define the numerator and denominator coefficients
2. Use tf(num, den) to create the transfer function
3. Analyze the system using step response, impulse response, Bode plot, and pole-zero
map
4. (Optional) Convert to zero-pole-gain form or state-space representation