%% Gain and Phase Margins of Transfer Function
% For this example, create a discrete-time transfer function.

sys = tf([0.04798 0.0464],[1 -1.81 0.9048],0.1)

%
% Compute the gain margin, phase margin and frequencies.

[Gm,Pm,Wcg,Wcp] = margin(sys)

% The results indicate that a gain variation of over 2.05 dB at the phase crossover frequency of 5.43 rad/s would cause the system to be unstable. Similarly a phase variation of over 13.57 degrees at the gain crossover frequency of 4.35 rad/s will cause the system to lose stability.
% Copyright 2012 The MathWorks, Inc.