You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stability_margins doesn't find gain=1 crossover frequency correctly for DT systems #523
stability_margins doesn't find gain=1 crossover frequency correctly for DT systems, but it seems to mostly do so for CT systems. I think the probelm may be in how margins.poly_z_mag1_crossing is finding roots, but there were a few steps in that function I couldn't follow, e.g. why H(z)*H(1/z)=1 implies |H(z)| = 1.
Reopening I found another example that seems to confuse the current version: a 4th order system consisting of two slightly-damped resonances in series:
I see. Looks like this may happen any time the nyquist frequency is maybe 3+ orders of magnitude faster than the slowest pole. What do you think about a stopgap solution to detect this by looking at the relative order of magnitudes of numerator and denominator polynomial and either give a warning or revert to the interpolating numerical solution via the FrequencyResponseData class?
I was thinking to use the inaccurate but not completely wrong found crossing frequency as a starting point for a local numerical solve. That way we don't have to evaluate the whole frequency range again.
Unfortunately I have another example where it is nowhere close (they invovle solutions to a class I am teaching so I will have to do some obfuscation before I can post them : )
Using an interpolating FrequencyResponseData system as an intermediary produces pretty good results (see below). Which we could use as a starting point to get a better local numerical result using an optimizer as you suggested. What if I put in the FRD version as a stopgap (which will include some sort of a test for small numerator)? Yeah, it's slow. But it might serve as a starting point to do a better numerical solve?
On option might be to include a method keyword someplace that allows you to tune the behavior of the calculation. So if you specify method='FRD' then you get the behavior above. This could be a way to keep from forcing every usage to be some slow method.
(am hoping to have something working in place for 0.9 for the discrete-time controls class I'm teaching starting March 29. The students will appreciate a working DT margin calculation! : )
@murrayrm sure, a method keyword would make sense. What if I let that override things, but by default revert to the FRD method if it looks like the "old" method isn't going to give good numerical results?
Activity
fix python-control#523: finding z for |H(z)|=1 computed the wrong pol…
bnavigator commentedon Jan 30, 2021
If I am not mistaken, it follows from
|H(z)|² = H(z) * conj(H(z)) = 1. Octave uses the same formulaBut the algorithm had a bug. Thanks for noticing and reporting.
sawyerbfuller commentedon Jan 30, 2021
I see, Makes sense if we are restricting the root search to the unit circle, where 1/z = conj(z).
And it has been a little while but I guess it must be that h(conj(z)) = conj(h(z))
Merge pull request #525 from bnavigator/fix-523
sawyerbfuller commentedon Mar 4, 2021
Reopening I found another example that seems to confuse the current version: a 4th order system consisting of two slightly-damped resonances in series:
This seems to give a reasonable result for the continuous-time case:

ct.bode_plot(sys, margins=True);but not for the discrete-time case:

ct.bode_plot(sysd, margins=True);If I lower the damping ratio to

zeta=0.05it seems to be manage:sawyerbfuller commentedon Mar 9, 2021
@bnagivator any ideas? I tried relaxing the tolerance but that didn't seem to help.
bnavigator commentedon Mar 9, 2021
Numerical issues. The coefficients of the numerator are significantly smaller than those of the denominator.
python-control/control/margins.py
Lines 159 to 172 in 92de12d
The result of
num(z)*num(1/z) - den(z)*den(1/z)is barely affected by the numerator, which gives an inaccurate result for the root. 😒My machine gives me a crossing frequency of 3.08 rad/s for
zeta=0.5too:zoomed in:
sawyerbfuller commentedon Mar 11, 2021
I see. Looks like this may happen any time the nyquist frequency is maybe 3+ orders of magnitude faster than the slowest pole. What do you think about a stopgap solution to detect this by looking at the relative order of magnitudes of numerator and denominator polynomial and either give a warning or revert to the interpolating numerical solution via the FrequencyResponseData class?
bnavigator commentedon Mar 11, 2021
I was thinking to use the inaccurate but not completely wrong found crossing frequency as a starting point for a local numerical solve. That way we don't have to evaluate the whole frequency range again.
sawyerbfuller commentedon Mar 11, 2021
Unfortunately I have another example where it is nowhere close (they invovle solutions to a class I am teaching so I will have to do some obfuscation before I can post them : )
sawyerbfuller commentedon Mar 12, 2021
Using an interpolating
FrequencyResponseDatasystem as an intermediary produces pretty good results (see below). Which we could use as a starting point to get a better local numerical result using an optimizer as you suggested. What if I put in the FRD version as a stopgap (which will include some sort of a test for small numerator)? Yeah, it's slow. But it might serve as a starting point to do a better numerical solve?murrayrm commentedon Mar 12, 2021
On option might be to include a
methodkeyword someplace that allows you to tune the behavior of the calculation. So if you specifymethod='FRD'then you get the behavior above. This could be a way to keep from forcing every usage to be some slow method.sawyerbfuller commentedon Mar 12, 2021
(am hoping to have something working in place for 0.9 for the discrete-time controls class I'm teaching starting March 29. The students will appreciate a working DT margin calculation! : )
murrayrm commentedon Mar 12, 2021
If we can get this sorted out before ~22 March, we can do a 0.9.0 release that week to make it easy for students to install.
sawyerbfuller commentedon Mar 12, 2021
@murrayrm sure, a method keyword would make sense. What if I let that override things, but by default revert to the FRD method if it looks like the "old" method isn't going to give good numerical results?
murrayrm commentedon Mar 12, 2021
Seems fine by me to have the default be something that works well.
You might consider setting up a benchmark file (in
benchmarks/) that lets you see how much of a performance hit there is on some different examples.bnavigator commentedon Mar 12, 2021
In any case there should be a check, whether the current results are accurate enough and give a warning if not.
add the second example from python-control#523 to the tests
merge the second example from python-control#523 into test_stability_…