Skip to content

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

Description

@Nick-Hemenway

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.

Activity

  1. murrayrm commented on Apr 3, 2020

    @murrayrm
    Member

    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 -:).

  2. changed the title [-]Bode Plot Phase Bounded to Between -180 and 180 Degrees[/-] [+]Allow the initial phase of a bode plot to be specified[/+] on Jul 11, 2020
  3. added this to the 0.9.x milestone on Dec 26, 2020
  4. murrayrm commented on Jan 4, 2021

    @murrayrm
    Member

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

  5. bnavigator commented on Jan 4, 2021

    @bnavigator
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions