Skip to content

Unwrap the Bode phase of delay systems on a finer grid - #1096

Open
inayatku wants to merge 1 commit into
JuliaControl:masterfrom
inayatku:bode-delay-phase-unwrap
Open

inayatku wants to merge 1 commit into
JuliaControl:masterfrom
inayatku:bode-delay-phase-unwrap

Conversation

@inayatku

Copy link
Copy Markdown

Fixes #757

A delay τ adds the phase -ωτ. On the default frequency grid, and on any grid that is sparse at high frequencies, the phase then changes by more than 180° between neighbouring frequencies, and unwrapping on the grid itself loses multiples of 360°. For delay(2) / (s + 1), the phase from bode(sys) on the default grid (240 frequencies) was off by up to 8280° (23 turns).

Changes:

  • bode takes the unwrapped phase from a new internal function _unwrapped_phase(sys, w, resp). For systems without delays it does what bode did before (unwrap!(angle.(resp), 3)).
  • For a DelayLtiSystem, _unwrapped_phase inserts frequencies between the given ones, so that the delays (the sum of sys.Tau) change the phase by at most 90° between neighbouring frequencies. It unwraps on that grid and returns the phase at the given frequencies. If more than 100 000 extra frequencies would be needed (for example a delay of 1e5 on the default grid), it unwraps on the given grid as before.
  • bodeplot now takes the unwrapped phase from bode instead of unwrapping again on the plotted grid. Unwrapping again would undo the correction, because the correct phase may change by more than 180° between plotted frequencies. For systems without delays the plotted phase is the same as before (unwrapping and the shift by a multiple of 360° at the start commute).

Tests: a new testset in test_delayed_systems.jl checks delay(2) / (s + 1) on a sparse grid and on the default grid, and two delays in series, against the exact phase. Without the change it fails (error 8280°). I also compared feedback(delay(1) / (s + 1)), a 2x2 system with delays 1 and 3, and delay(10) / (s + 1) with the phase unwrapped on a grid with 50 frequencies per radian of delay phase: they agree. A bode call on these systems takes about 0.03 s.

With the change, test_delayed_systems, test_freqresp, test_analysis, test_autovec and test_plots pass (1054 tests, Julia 1.13.2 on Windows).

)

A delay adds the phase -w*tau, which on a sparse frequency grid changes by
more than 180 degrees between neighbouring frequencies, so unwrapping on the
grid itself lost multiples of 360 degrees. For a DelayLtiSystem, the phase is
now unwrapped on a grid on which the delays change the phase by at most 90
degrees, and read off at the given frequencies. bodeplot uses this phase
instead of unwrapping again on the plotted grid.
@inayatku

Copy link
Copy Markdown
Author

@baggepinnen, a gentle reminder about this pull request, when you have time. The CI workflows have not run yet: they are waiting for approval, as this is my first contribution here.

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.

bode phase incorrect for larger delay

1 participant