Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the initial phase of a bode plot to be specified #388

Closed
Nick-Hemenway opened this issue Apr 3, 2020 · 3 comments
Closed

Allow the initial phase of a bode plot to be specified #388

Nick-Hemenway opened this issue Apr 3, 2020 · 3 comments
Milestone

Comments

@Nick-Hemenway
Copy link

The output of the bode_plot function is bounded to between -180 degrees and 180 degrees and doesn't account for conditions when the phase should leave these ranges. For example a phase angle of -270 degrees will be represented as 90 degrees on the bode plot. To illustrate this, I've got a simple example below:

import control as ct

m = 2
k = 100_000
Wci = 2*np.pi*500

G1 = ct.TransferFunction([1],[m, 0, -k])
G2 = ct.TransferFunction([1], [1/Wci, 1])
G3 = G1*G2

ct.bode_plot([G1, G2, G3], dB = True, Hz = True)

image

-G1 (blue curve) contains two poles and a DC gain and has a phase angle of -180 degrees.

-G2 (orange curve) is a simple pole with no DC gain and thus has a phase that starts at 0 degrees and goes to -90 degrees

-G3 (green curve) is the product of the two transfer functions which on the bode plot corresponds to adding of the curves. We should see the green curve start at a phase of -180 degrees and go to -270 degrees but it does not do this because of the way that the phase angle is computed.

@murrayrm
Copy link
Member

murrayrm commented Apr 3, 2020

Bode plots can represent phase outside of -180 to 180. For example, if you change your example to have a positive spring constant with some damping, it gives you a more natural plot:

import numpy as np
import control as ct

m = 2
k = 100_000
d = 100
Wci = 2*np.pi*500

G1 = ct.TransferFunction([1],[m, d, k])
G2 = ct.TransferFunction([1], [1/Wci, 1])
G3 = G1*G2

ct.bode_plot([G1, G2, G3], dB = True, Hz = True)

updated_bode

Coming back to your example, the bode_plot function has to make some guesses about what the initial phase is. This is what is causing the problem in your plots. We can probably make things more "natural" here (volunteers to do this are welcome -:). It might also be nice to add a way to set the initial phase of the plot and/or separate the generation of the frequency response from plotting in a better way (see issue #65).

The "fix" I can suggest is to store the return values from bode_plot and then plot by hand (sorry -:).

@murrayrm murrayrm changed the title Bode Plot Phase Bounded to Between -180 and 180 Degrees Allow the initial phase of a bode plot to be specified Jul 11, 2020
@murrayrm murrayrm added this to the 0.9.x milestone Dec 26, 2020
@murrayrm
Copy link
Member

murrayrm commented Jan 4, 2021

This has been fixed in PR #494 (currently pending).

@bnavigator
Copy link
Contributor

It has already been merged 2 days ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants