I want to determine the phase margin for the following transfer function:
sys_ol = tf([1.225 -1.1 -0.4183 0.3977],[1 -1.36 -0.4119 0.4019 0.9352 -0.565],1)
Its a discrete plant with sample time 1. By analysis of the poles I can see that the system is stable. Also building the closed loop system with unity feedback, by
sys_cl = feedback(sys_ol,1)
the closed loop system is stable. However, if I use Matlab's allmargin command on sys_ol, it returns:
GainMargin: 1.5073
GMFrequency: 1.5206
PhaseMargin: [34.1864 -27.7466 -179.7534]
PMFrequency: [0.6973 2.0242 2.7058]
DelayMargin: [0.8557 2.8648 1.1627 1]
DMFrequency: [0.6973 2.0242 2.7058 3.1416]
Stable: 1
So, according to "allmargin" there are two 0dB crossings that have a negative phase margin (-27.7deg / -179.8deg).
To my understanding a system with negative phase margin is unstable. However pole analysis shows that the system is stable. Also "allmargin" gives "Stable: 1". How does this go together?
You can see these in a simple Nyquist plot
Negative phase margin does not imply anything about stability by itself. You have to be around the -1 point too to go unstable. Similarly with gain margin.
Note that, these are rough indicators of stability. A complex number can push the locus such that it crosses -1 point (compared to a pure phase shift or gain change). That's why it is possible to have seemingly conflicting answers out of these.