bode_margins
Frequency response of an open loop L(s) = gain * num(s)/den(s) * exp(-s T) on a log sweep: gain and phase margins with their crossover frequencies, delay margin, -3 dB bandwidth and resonant peak of L, unity-feedback closed-loop and sensitivity peaks, closed-loop stability by Routh (and delay margin when T > 0); bode.csv and crossovers.csv.
- Field
- Dynamics and control
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.05 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001textbook K/(s(s+1)(s+2)), K=1: phase crossover at sqrt(2) rad/s, gain margin 6/K = 6 = 20 log10 6 = 15.563025 dB (closed form, rel 1e-6)passed
phase_crossover_rad_s1.41421 ± 1.4e-061.41421lockedunder 0.01 % of the tolerance usedgain_margin6 ± 6e-066lockedunder 0.01 % of the tolerance usedgain_margin_dB15.563 ± 1.6e-0515.563lockedunder 0.01 % of the tolerance usedclosed_loop_stable= truetruelockedexact matchr0002Routh limit of K/(s(s+1)(s+2)) is K = 6: at K=10 the closed loop is unstable and the gain margin is 6/K = 0.6 (closed form, rel 1e-6)passed
gain_margin0.6 ± 6e-070.6lockedunder 0.01 % of the tolerance usedphase_crossover_rad_s1.41421 ± 1.4e-061.41421lockedunder 0.01 % of the tolerance usedclosed_loop_stable= falsefalselockedexact matchr0003first-order lag 1/(s+1) at its corner w = 1: -10 log10 2 = -3.0103 dB and -45 deg; -3 dB bandwidth = 1 rad/s (closed form, rel 1e-6)passed
gain_at_w_dB-3.0103 ± 3e-06-3.0103lockedunder 0.01 % of the tolerance usedphase_at_w_deg-45 ± 4.5e-05-45lockedunder 0.01 % of the tolerance usedbandwidth_rad_s1 ± 1e-061lockedunder 0.01 % of the tolerance usedr0004integrator 1/s: |L| = 1 at w = 1 rad/s, phase margin 90 deg, delay margin pi/2 s, no phase crossover (closed form, rel 1e-6)passed
gain_crossover_rad_s1 ± 1e-061lockedunder 0.01 % of the tolerance usedphase_margin_deg90 ± 9e-0590lockedunder 0.01 % of the tolerance useddelay_margin_s1.5708 ± 1.6e-061.5708lockedunder 0.01 % of the tolerance usedphase_crossover_count= 00lockedexact matchr0005integrator with dead time T = 0.5 s: phase margin 90 deg - T rad = 61.352110 deg at w = 1; phase crossover at pi/(2T) = pi rad/s with gain margin pi/(2T) = pi; delay margin pi/2 - T (closed form, rel 1e-6)passed
phase_margin_deg61.3521 ± 6.1e-0561.3521lockedunder 0.01 % of the tolerance usedgain_crossover_rad_s1 ± 1e-061lockedunder 0.01 % of the tolerance usedphase_crossover_rad_s3.14159 ± 3.1e-063.14159lockedunder 0.01 % of the tolerance usedgain_margin3.14159 ± 3.1e-063.14159lockedunder 0.01 % of the tolerance useddelay_margin_s1.0708 ± 1.1e-061.0708lockedunder 0.01 % of the tolerance usedclosed_loop_stable= truetruelockedexact matchr0006second order wn^2/(s^2 + 2 z wn s + wn^2), wn = 2, z = 0.3: resonant peak 1/(2 z sqrt(1-z^2)) = 1.7471414 at wn sqrt(1-2z^2) = 1.8110770 rad/s; bandwidth wn sqrt(1-2z^2+sqrt(4z^4-4z^2+2)) = 2.9073789 rad/s (closed forms, rel 1e-6; the peak frequency is found by golden section, good to ~1e-8 relative)passed
resonant_peak1.74714 ± 1.7e-061.74714lockedunder 0.01 % of the tolerance usedresonant_peak_dB4.84656 ± 4.8e-064.84656lockedunder 0.01 % of the tolerance usedresonant_rad_s1.81108 ± 1.8e-061.81108locked0.33 % of the tolerance usedbandwidth_rad_s2.90738 ± 2.9e-062.90738lockedunder 0.01 % of the tolerance used
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
num | [1] | Numerator coefficients, highest power of s first: [1, 2] is s + 2. Up to degree 30. | |
den | Denominator coefficients, highest power of s first: [1, 3, 2, 0] is s^3 + 3 s^2 + 2 s. Up to degree 30. | ||
gain | 1 | 1.0 | Loop gain K multiplying num/den; any finite non-zero number (negative flips the sign). |
dead_time_s | s | 0.0 | Pure dead time T: the loop is multiplied by exp(-s T). |
w_min_rad_s | rad/s | 0.001 | Lowest sweep frequency. |
w_max_rad_s | rad/s | 1000.0 | Highest sweep frequency (above w_min_rad_s). |
points_per_decade | 1 | 100 | Base sweep density; the sweep is refined further wherever the phase turns fast. |
eval_w_rad_s | rad/s | Optional: one frequency (inside the sweep) at which to report gain and phase of L. |
Readings
| Name | Unit | Meaning |
|---|---|---|
gain_margin | 1 | |
gain_margin_dB | Decibels (20 log10 of the ratio); dB is not in the kernel's unit table, so no unit is declared. | |
phase_crossover_rad_s | rad/s | |
phase_margin_deg | deg | |
gain_crossover_rad_s | rad/s | |
delay_margin_s | s | |
closed_loop_stable | true/false, or null when not decided (see stability_basis). | |
stability_basis | How closed_loop_stable was decided. | |
closed_loop_rhp_poles_no_dead_time | 1 | |
open_loop_rhp_poles | 1 | |
dc_gain | 1 | |
dc_gain_dB | Decibels (20 log10 of the ratio); dB is not in the kernel's unit table, so no unit is declared. | |
bandwidth_rad_s | rad/s | First frequency where |L| falls 3.0103 dB below its DC gain. |
peak_gain | 1 | |
peak_gain_dB | Decibels (20 log10 of the ratio); dB is not in the kernel's unit table, so no unit is declared. | |
resonant_peak | 1 | Largest |L| inside the sweep divided by |L(0)|, when above 1. |
resonant_peak_dB | Decibels (20 log10 of the ratio); dB is not in the kernel's unit table, so no unit is declared. | |
resonant_rad_s | rad/s | |
closed_loop_peak | 1 | Largest |L/(1+L)| in the sweep. |
closed_loop_peak_rad_s | rad/s | |
closed_loop_bandwidth_rad_s | rad/s | |
sensitivity_peak | 1 | Largest |1/(1+L)| in the sweep (Ms). |
sensitivity_peak_rad_s | rad/s | |
gain_at_w | 1 | |
gain_at_w_dB | Decibels (20 log10 of the ratio); dB is not in the kernel's unit table, so no unit is declared. | |
phase_at_w_deg | deg | |
gain_crossover_count | 1 | |
phase_crossover_count | 1 | |
sweep_points | 1 | |
warnings | Caveats in words: crossovers outside the sweep, open-loop right-half-plane poles, undecided stability. | |
crossovers | ||
bode.csv | ||
crossovers.csv |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.