% Example file of phase and gain margins % Plot Gain and Phase Margins of Transfer Function close all, clc %% First example, create a continuous transfer function Gs = tf(1,[1 2 1 0]) figure, margin(Gs) % plots gain and phase margins [Gm,Pm] = margin(Gs) % returns the values of Gm and Pm figure, nyquist(Gs) % Nyquist diagram plot %% Second example: stable Hs = tf([2 5 1],[1 2 3]) figure, nyquist(Hs) [Gm,Pm] = margin(Hs) %% Third example: marginally stable K = 100; % K = 60 -> marginally stable Ls = tf([0 0 0 K],[1 6 11 6]) figure, nyquist(Ls) [Gm,Pm] = margin(Ls)