It seems you misunderstood what Gain Over Frequency and phase margin actually means, and it is not the place to explain it. What I assume you actually want, is a way to evaluate a bode-plot without clicking at it. E.g. you want to know magnitude and frequency at the point of -20 phase.
Let's have a look at these three cases:
Case 1: you know the frequency and you're searching for magnitude and phase
The easiest case:
w = 0.363; % specify given frequency
[mag,phase] = bode(Gp,w) % output of according magnitude and phase
returns:
mag =
0.9400
phase =
-19.9509
Case 2: you want to know magnitude and frequency for a certain phase
p = -20;
[mag,phase,wout] = bode(Gp);
mag_p = interp1( squeeze(phase), squeeze(mag), p)
w_p = interp1( squeeze(phase), wout, p)
returns:
mag_p =
0.9394
w_p =
0.3642
Case 3: you want to know phase and frequency for a certain magnitude
m = 0.9394;
[mag,phase,wout] = bode(Gp);
phase_m = interp1( squeeze(mag), squeeze(phase), m)
w_m = interp1( squeeze(mag), wout, m)
returns:
phase_m =
-19.9998
w_m =
0.3642
The squeeze
command is necessary, because bode output a 1x1x...
matrix for phase and magnitude, however. You also may use different interpolation methods of interp1
.
fzero
as described in the answer linked above. For a complete answer the question is way too broad. – Robert Seifert