To plot a transfer function in MATLAB, first define the system using the Laplace variable s = tf('s') or coefficient vectors with G = tf(num, den) from the Control System Toolbox. You can then generate time-domain responses using step(G) and impulse(G), frequency-domain responses using bode(G) and nyquist(G), or stability plots using rlocus(G) (Root Locus) and pzmap(G) (Pole-Zero Map).
Step 1: Defining the Transfer Function
You can define continuous-time transfer functions using either polynomial coefficients or direct algebraic Laplace expressions:
% Method A: Direct Laplace Variable Notation (Recommended)
s = tf('s');
G = (10 * (s + 2)) / (s^3 + 4*s^2 + 6*s + 10);
% Method B: Numerator and Denominator Coefficient Vectors
% Equivalent to: (10s + 20) / (s^3 + 4s^2 + 6s + 10)
num = [10, 20];
den = [1, 4, 6, 10];
G = tf(num, den);
% Display transfer function in Command Window
disp(G);
Step 2: Time-Domain Analysis Plots
1. Step Response (Transient Metrics: Rise Time, Settling Time, Overshoot)
figure('Name', 'Step Response Analysis', 'Color', 'w');
step(G);
grid on;
title('Step Response of Closed-Loop System');
% Extract numerical step response characteristics
info = stepinfo(G);
fprintf('Rise Time: %.2f s, Settling Time: %.2f s, Overshoot: %.2f%%\n', ...
info.RiseTime, info.SettlingTime, info.Overshoot);
2. Impulse Response & Custom Input Simulation (lsim)
% Impulse Response
figure('Color', 'w');
impulse(G);
grid on;
title('Impulse Response');
% Arbitrary Input Simulation (e.g., Sine Wave Input)
t = 0:0.01:10; % Time vector
u = sin(2 * pi * 0.5 * t); % 0.5 Hz sine wave input
figure('Color', 'w');
lsim(G, u, t);
grid on;
title('Linear Simulation with Sinusoidal Input');
Step 3: Frequency-Domain Analysis Plots
1. Bode Plot (Magnitude & Phase Margins)
figure('Name', 'Bode Analysis', 'Color', 'w');
% margin() plots the Bode diagram and displays Gain Margin (Gm) and Phase Margin (Pm)
margin(G);
grid on;
% Extract stability margins numerically
[Gm, Pm, Wcg, Wcp] = margin(G);
fprintf('Gain Margin: %.2f dB, Phase Margin: %.2f deg\n', 20*log10(Gm), Pm);
2. Nyquist Diagram & Nichols Chart
% Nyquist Plot (Evaluates encirclements of the critical -1+0j point)
figure('Color', 'w');
nyquist(G);
grid on;
title('Nyquist Diagram');
% Nichols Chart (Open-loop to closed-loop gain/phase grid)
figure('Color', 'w');
nichols(G);
grid on;
ngrid; % Overlay closed-loop M and N contours
Step 4: Stability & Pole-Zero Plots
1. Root Locus (Closed-Loop Pole Trajectory vs Gain \(K\))
figure('Color', 'w');
rlocus(G);
grid on;
title('Root Locus Diagram');
sgrid; % Overlay damping ratio (zeta) and natural frequency (wn) lines
2. Pole-Zero Map (pzmap)
figure('Color', 'w');
pzmap(G);
grid on;
title('Open-Loop Pole-Zero Map');
% Check stability directly
is_stable = isstable(G);
if is_stable
disp('The system is open-loop stable.');
else
disp('The system is open-loop unstable (Poles exist in right-half plane).');
end
Interactive Visual GUI: Linear System Analyzer
If you want to view the Step Response, Bode Plot, Nyquist Diagram, and Root Locus simultaneously in an interactive dashboard, launch the Linear System Analyzer by typing:
linearSystemAnalyzer(G);
Essential Transfer Function Plotting Functions
| Command | Type of Plot | Key Engineering Insight |
|---|---|---|
step(G) |
Time Domain | Rise time, settling time, peak overshoot, steady-state error. |
impulse(G) |
Time Domain | Natural system dynamics and exponential decay rates. |
lsim(G, u, t) |
Time Domain | Response to custom inputs (triangular, square, chirp waveforms). |
bode(G) / margin(G) |
Frequency Domain | Bandwidth, cutoff frequency, gain margin, phase margin. |
nyquist(G) |
Frequency Domain | Encirclement stability criteria for open-loop right-half-plane poles. |
rlocus(G) |
Stability Domain | Root locus paths as feedback controller gain \(K\) varies from 0 to \(\infty\). |
pzmap(G) |
Complex Plane | Exact pole and zero coordinates in the \(s\)-plane (Laplace) or \(z\)-plane (Discrete). |
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Explore similar technical troubleshooting questions and verified MATLAB solutions: