- Notifications
You must be signed in to change notification settings - Fork441
implementation of initial_phase, wrap_phase keywords for bode()#494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
bnavigator merged 3 commits intopython-control:masterfrommurrayrm:bode_initial_wrap_phaseJan 2, 2021
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
85 changes: 73 additions & 12 deletionscontrol/freqplot.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
67 changes: 66 additions & 1 deletioncontrol/tests/freqresp_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,6 +9,7 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from numpy.testing import assert_allclose | ||
import math | ||
import pytest | ||
import control as ctrl | ||
@@ -173,7 +174,7 @@ def test_bode_margin(dB, maginfty1, maginfty2, gminv, | ||
rtol=1e-5) | ||
phase_to_infinity = (np.array([Wcg, Wcg]), | ||
np.array([0, p0])) | ||
assert_allclose(phase_to_infinity, allaxes[1].lines[4].get_data(), | ||
rtol=1e-5) | ||
@@ -271,3 +272,67 @@ def test_options(editsdefaults): | ||
# Make sure we got the right number of points | ||
assert numpoints1 != numpoints3 | ||
assert numpoints3 == 13 | ||
@pytest.mark.parametrize( | ||
"TF, initial_phase, default_phase, expected_phase", | ||
[pytest.param(ctrl.tf([1], [1, 0]), | ||
bnavigator marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
None, -math.pi/2, -math.pi/2, id="order1, default"), | ||
pytest.param(ctrl.tf([1], [1, 0]), | ||
180, -math.pi/2, 3*math.pi/2, id="order1, 180"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0]), | ||
None, -math.pi, -math.pi, id="order2, default"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0]), | ||
180, -math.pi, math.pi, id="order2, 180"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0]), | ||
None, -3*math.pi/2, -3*math.pi/2, id="order2, default"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0]), | ||
180, -3*math.pi/2, math.pi/2, id="order2, 180"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0]), | ||
None, 0, 0, id="order4, default"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0]), | ||
180, 0, 0, id="order4, 180"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0]), | ||
-360, 0, -2*math.pi, id="order4, -360"), | ||
]) | ||
def test_initial_phase(TF, initial_phase, default_phase, expected_phase): | ||
# Check initial phase of standard transfer functions | ||
mag, phase, omega = ctrl.bode(TF) | ||
assert(abs(phase[0] - default_phase) < 0.1) | ||
# Now reset the initial phase to +180 and see if things work | ||
mag, phase, omega = ctrl.bode(TF, initial_phase=initial_phase) | ||
assert(abs(phase[0] - expected_phase) < 0.1) | ||
# Make sure everything works in rad/sec as well | ||
if initial_phase: | ||
plt.clf() # clear previous figure (speeds things up) | ||
mag, phase, omega = ctrl.bode( | ||
TF, initial_phase=initial_phase/180. * math.pi, deg=False) | ||
assert(abs(phase[0] - expected_phase) < 0.1) | ||
@pytest.mark.parametrize( | ||
"TF, wrap_phase, min_phase, max_phase", | ||
[pytest.param(ctrl.tf([1], [1, 0]), | ||
None, -math.pi/2, 0, id="order1, default"), | ||
pytest.param(ctrl.tf([1], [1, 0]), | ||
True, -math.pi, math.pi, id="order1, True"), | ||
pytest.param(ctrl.tf([1], [1, 0]), | ||
-270, -3*math.pi/2, math.pi/2, id="order1, -270"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0]), | ||
None, -3*math.pi/2, 0, id="order3, default"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0]), | ||
True, -math.pi, math.pi, id="order3, True"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0]), | ||
-270, -3*math.pi/2, math.pi/2, id="order3, -270"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0, 0]), | ||
True, -3*math.pi/2, 0, id="order5, default"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0, 0]), | ||
True, -math.pi, math.pi, id="order5, True"), | ||
pytest.param(ctrl.tf([1], [1, 0, 0, 0, 0, 0]), | ||
-270, -3*math.pi/2, math.pi/2, id="order5, -270"), | ||
]) | ||
def test_phase_wrap(TF, wrap_phase, min_phase, max_phase): | ||
mag, phase, omega = ctrl.bode(TF, wrap_phase=wrap_phase) | ||
assert(min(phase) >= min_phase) | ||
assert(max(phase) <= max_phase) |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.