Skip to content

Unexpected Phase Jumps in Bode Plot of Third-Order Systems with Zeros and Poles #1179

Description

@Kreste-111

Version of the control package: 0.10.1

I would like to plot a Bode plot of two third-order systems.
One system has three poles and no zeros. The other system also has three poles and two zeros.
The phase response is step-like due to the lack of damping.
I would have expected the following phase response and verified it with Matlab:
System 1:
Starts at -90° due to the pole at 0. Constant response up to the resonance frequency, then jumps to -270°. I also get this response with the control package.

System 2:
Starts at -90° due to the pole at 0. Constant response up to the frequency of the double zero, then jumps to +90°. Constant curve up to the double pole position and jump to -90°. However, with the control package, I get jumps to -270° and then -450°. The -270° is equivalent to the +90°, but the “direction of rotation,” i.e., how you get there, is not correct.
The code documenting the transfer functions and the rest of the code can be found below. Is it possible to achieve the expected behavior?

Matlab output:
Image

Python control output:
Image

import numpy as np
from scipy import signal
import plotly.graph_objects as go
import sympy as sp
from plotly.subplots import make_subplots
import matplotlib.pyplot as plt
import control

# Parameters
Lafe_val = 3.1e-3
Lg_val = 2e-3
Cf_val = 3.3e-6

# Symbolic Definition
s = sp.symbols('s')
Lafe, Lg, Cf = sp.symbols('Lafe Lg Cf')
G_g = 1 / (Lafe * Lg * Cf * s**3 + (Lafe + Lg) * s)
G_c = (1 + Lg * Cf * s**2) / (Lafe * Lg * Cf * s**3 + (Lafe + Lg) * s)

# Display symbolic transfer functions
print("Symbolic transfer function Gg(s):")
sp.pprint(G_g)
print("Symbolic transfer function Gc(s):")
sp.pprint(G_c)

## Transfer Function 1

# Calculate poles and zeros
# Extract numerator and denominator
num_g_sym, den_g_sym = sp.fraction(G_g)

zeros_g = sp.solve(num_g_sym, s)
poles_g = sp.solve(den_g_sym, s)

# Substitute parameter values
G_g_num = G_g.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val})
zeros_g_num = [z.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val}) for z in zeros_g]
poles_g_num = [p.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val}) for p in poles_g]

# Display zeros
print("\nZeros of the numerator:")
if zeros_g:
    for z_sym, z_num in zip(zeros_g, zeros_g_num):
        print(f"  s = {z_sym}   ≈ {sp.N(z_num, 4)}")
else:
    print("  No zeros (numerator is constant).")

# Display poles
print("\nPoles of the denominator:")
if poles_g:
    for p_sym, p_num in zip(poles_g, poles_g_num):
        print(f"  s = {p_sym}   ≈ {sp.N(p_num, 4)}")
else:
    print("  No poles (denominator is constant).")

# Extract numerator and denominator
num_g, den_g = sp.fraction(G_g_num)

# Calculate coefficients
num_coeffs_g = sp.Poly(num_g, s).all_coeffs()
den_coeffs_g = sp.Poly(den_g, s).all_coeffs()

# Convert to float 
num_coeffs_g = [float(c) for c in num_coeffs_g]
den_coeffs_g = [float(c) for c in den_coeffs_g]

# Transfer function
system_g = control.TransferFunction(num_coeffs_g, den_coeffs_g)

## Transfer Function 2

# Calculate poles and zeros
# Extract numerator and denominator
num_c_sym, den_c_sym = sp.fraction(G_c)

zeros_c = sp.solve(num_c_sym, s)
poles_c = sp.solve(den_c_sym, s)

# Substitute parameter values
G_c_num = G_c.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val})
zeros_c_num = [z.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val}) for z in zeros_c]
poles_c_num = [p.subs({Lafe: Lafe_val, Lg: Lg_val, Cf: Cf_val}) for p in poles_c]

# Display zeros
print("\nZeros of the numerator:")
if zeros_c:
    for z_sym, z_num in zip(zeros_c, zeros_c_num):
        print(f"  s = {z_sym}   ≈ {sp.N(z_num, 4)}")
else:
    print("  No zeros (numerator is constant).")

# Display poles
print("\nPoles of the denominator:")
if poles_c:
    for p_sym, p_num in zip(poles_c, poles_c_num):
        print(f"  s = {p_sym}   ≈ {sp.N(p_num, 4)}")
else:
    print("  No poles (denominator is constant).")

# Extract numerator and denominator
num_c, den_c = sp.fraction(G_c_num)

# Calculate coefficients
num_coeffs_c = sp.Poly(num_c, s).all_coeffs()
den_coeffs_c = sp.Poly(den_c, s).all_coeffs()

# Convert to float 
num_coeffs_c = [float(c) for c in num_coeffs_c]
den_coeffs_c = [float(c) for c in den_coeffs_c]

# Transfer function
system_c = control.TransferFunction(num_coeffs_c, den_coeffs_c)

# Frequency range
frequencies_rad_s = np.logspace(2, 5, num=500)
frequencies_pole = np.linspace(0.99 * float(sp.Abs(poles_c_num[1])), 1.01 * float(sp.Abs(poles_c_num[1])), 100)
frequencies_zero = np.linspace(0.99 * float(sp.Abs(zeros_c_num[1])), 1.01 * float(sp.Abs(zeros_c_num[1])), 100)
combined_frequencies = np.sort(np.unique(np.concatenate((
    frequencies_rad_s,
    frequencies_pole,
    frequencies_zero,
    [float(sp.Abs(poles_c_num[1]))],
    [float(sp.Abs(zeros_c_num[1]))]
))))

# Plot Bode diagram
control.bode_plot([system_g, system_c], combined_frequencies, dB=True, Hz=False, deg=True)
plt.show()

Activity

  1. murrayrm commented on Nov 9, 2025

    @murrayrm
    Member

    The issue here is that you have zeros exactly on the imaginary axis, and so the internal "unwrapping" function doesn't handle things in the same way as MATLAB. As you note, the answer is "correct", just not what you expected.

    The following code shows that if you have a system with just a small amount of damping, you get the expected answer:

    import control as ct
    
    Lafe = 3.1e-3
    Lg = 2e-3
    Cf = 3.3e-6
    
    s = ct.tf('s')
    G_g = 1 / (Lafe * Lg * Cf * s**3 + (Lafe + Lg) * s)
    G_c = (1 + Lg * Cf * s**2) / (Lafe * Lg * Cf * s**3 + (Lafe + Lg) * s)
    
    G_c_stable = ct.zpk(G_c.zeros() - 1e-6, G_c.poles(), 1)
    G_c_stable *= abs(G_c(1j)) / abs(G_c_stable(1j))  # Match the gain
    
    ct.bode_plot([G_g, G_c_stable], label=['G_g', 'G_c'])
    
    Image

    I'm not sure how to get the unwrap function to give a better answer, since there is no information in the frequency response to tell it what the "right" answer is.

    (For developers: this is one of the the places where separating out the "response" from the "plot" makes it hard to give a better solution, since we don't actually know anything in the plotting routine about what the poles and zeros of the system are.)

    I'll leave this issue open, in case someone has some ideas that they want to toss in.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions