Repository navigation
Commit 4f168cd
committed
Fix stability_margins missing a phase crossover at the Nyquist frequency
For a discrete-time loop whose phase reaches -180 degrees exactly at
w = pi/dt, stability_margins returned gm = inf under every method.
For real coefficients L(-1) is always real, so this is a common case:
L(z) = 1/(z-1) has a phase crossover at z = -1 with gm = 2, but
'poly', 'frd' and 'best' all reported gm = inf.
- _z_filter kept only unit-circle roots with 0 <= arg(z) < pi, dropping
the root at z = -1. Now also keep roots whose argument is exactly +pi
or exactly -pi (the root-finder returns an exact imaginary zero for a
real root, with either sign) and report the endpoint frequency via
abs(arg). No tolerance is applied to the angle, so a genuine root
near, but not at, -1 keeps its computed frequency and its lower-half
conjugate stays excluded, exactly as before.
- The 'frd' path detects phase crossovers as sign changes inside the
frequency grid, which excludes w = pi/dt for discrete-time systems.
When a transfer function is converted to FRD, evaluate L(-1) and count
it as a phase crossover if it is real and negative and pi/dt >= epsw.
(Other FRD-detected crossings ignore epsw; that pre-existing behavior
is unchanged.)
This also makes phase_crossover_frequencies include the real-axis
intersection at w = pi/dt for discrete-time systems, matching the w = 0
endpoint that was already returned; one existing test reference is
updated accordingly.
Adds regression tests: gm at the Nyquist endpoint under all three
methods, a loop with L(-1) > 0 that must keep gm = inf, and a _z_filter
unit test covering the exact endpoint and a nearby conjugate root pair.
The new tests fail at baseline and pass with the fix.
Fixes #12671 parent bfe9380 commit 4f168cd
2 files changed
Lines changed: 78 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
| |||
292 | 296 | | |
293 | 297 | | |
294 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
295 | 305 | | |
296 | 306 | | |
297 | 307 | | |
| |||
300 | 310 | | |
301 | 311 | | |
302 | 312 | | |
| 313 | + | |
| 314 | + | |
303 | 315 | | |
304 | 316 | | |
305 | 317 | | |
| |||
310 | 322 | | |
311 | 323 | | |
312 | 324 | | |
| 325 | + | |
| 326 | + | |
313 | 327 | | |
314 | 328 | | |
315 | 329 | | |
| |||
382 | 396 | | |
383 | 397 | | |
384 | 398 | | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
385 | 407 | | |
386 | 408 | | |
387 | 409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
117 | | - | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
152 | 205 | | |
153 | 206 | | |
154 | 207 | | |
| |||
0 commit comments