Skip to content

Compute phase margins independently of the unwrapped phase - #1094

Open
baggepinnen wants to merge 1 commit into
masterfrom
fix/phase-margin-branch
Open

baggepinnen wants to merge 1 commit into
masterfrom
fix/phase-margin-branch

Conversation

@baggepinnen

Copy link
Copy Markdown
Member

Phase margins depend on the chosen unwrapped Bode phase. For 2.7(s+1)^2/((s-ε)^2*(s+ε)), nonzero ε can produce a phase margin near 413° and a delay margin near 2.403 s, although the relevant values are approximately 53° and 0.309 s.

Compute signed phase margins in [-180°, 180°) directly from the frequency response at each gain crossover. Return the margin closest to zero when allMargins=false. Integrator-based phase adjustment applies only to the unwrapped phase returned for plotting, so changing the integrator classification or initial phase branch does not change the margins.

Delay margins use the smallest nonnegative additional phase lag divided by frequency over all gain crossovers. This also corrects a stable four-crossover example where selecting the smallest phase margin gives 0.588 s instead of the limiting delay of 0.159 s. The documentation states the assumption of nominal closed-loop stability.

The signed convention preserves negative margins and changes an existing unwrapped result near −320° to its equivalent signed value near +40°.

Fixes ControlSystems.jl#1093.

Validation on Linux with Julia 1.13.1: 573 checks pass across test_analysis.jl, test_margin_phase.jl, and test_plots.jl. git diff --check passes. The new regression suite has 148 checks; 34 fail against the previous implementation. Tests include transfer-function, zero-pole-gain, and state-space representations, phase adjustment enabled/disabled, negative margins, multiple crossovers, discrete-time delay units, zero-frequency crossovers, and Padé stability checks on either side of the predicted delay limits.


Host: demeter2; Codex session: 01a15eb9-1234-7a03-a4be-7f8814d35ca2; working directory: /tmp/controlsystems-phase-margin.

@JuliaControlBot

Copy link
Copy Markdown

This is an automated message.
Plots were compared to references. 6/11 images have changed, see differences below.
After pulling this PR, please update the reference images by creating a PR to ControlExamplePlots.jl here.

Difference Reference Image New Image
✔️ 0.0 Reference New
⚠️ 0.021 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
✔️ 0.013 Reference New

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.32%. Comparing base (973f8d1) to head (5391cb5).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1094      +/-   ##
==========================================
+ Coverage   92.29%   92.32%   +0.02%     
==========================================
  Files          42       42              
  Lines        6177     6174       -3     
==========================================
- Hits         5701     5700       -1     
+ Misses        476      474       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

margin and delaymargin are 360° off when rounding splits a multiple integrator into poles off the origin

2 participants