Frequency-Domain Analysis & Stability Margins¶
freq_domain
¶
Frequency-domain analysis and stability margin calculations for LTI systems.
BodeData
dataclass
¶
Frequency response data for Bode diagram analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
NDArray[float64]
|
Frequencies in radians per second (rad/s). |
required |
mag
|
NDArray[float64]
|
Linear magnitude |G(jw)|. |
required |
phase
|
NDArray[float64]
|
Unwrapped phase in degrees. |
required |
mag_db
|
NDArray[float64]
|
Magnitude in decibels: 20 * log10(|G(jw)|). |
required |
phase_rad
|
NDArray[float64]
|
Unwrapped phase in radians. |
required |
response
|
NDArray[complex128]
|
Complex frequency response values G(jw). |
required |
Source code in src/ctrlpy/freq_domain.py
__iter__
¶
Enable unpacking: w, mag, phase = bode_data(sys).
Yields:
| Type | Description |
|---|---|
NDArray[float64]
|
Frequency array |
Source code in src/ctrlpy/freq_domain.py
NyquistData
dataclass
¶
Frequency response data for Nyquist diagram analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
w
|
NDArray[float64]
|
Frequencies in radians per second (rad/s). |
required |
response
|
NDArray[complex128]
|
Complex frequency response values G(jw). |
required |
real
|
NDArray[float64]
|
Real part Re(G(jw)). |
required |
imag
|
NDArray[float64]
|
Imaginary part Im(G(jw)). |
required |
arc_s
|
NDArray[complex128] | None
|
Complex frequencies s along the indented arc around s=0. |
None
|
arc_response
|
NDArray[complex128] | None
|
Complex frequency response G(s) along the indented arc around s=0. |
None
|
Source code in src/ctrlpy/freq_domain.py
__iter__
¶
Enable unpacking: w, response = nyquist_data(sys).
Yields:
| Type | Description |
|---|---|
NDArray[float64] | NDArray[complex128]
|
Frequency array |
Source code in src/ctrlpy/freq_domain.py
RootLocusData
dataclass
¶
Root locus pole trajectory data across varying gains.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gains
|
NDArray[float64]
|
1D array of non-negative feedback gain values k >= 0. |
required |
roots
|
NDArray[complex128]
|
2D array of closed-loop pole locations of shape (n_gains, n_poles). |
required |
poles
|
NDArray[complex128]
|
Open-loop poles (corresponding to k = 0). |
required |
zeros
|
NDArray[complex128]
|
Open-loop zeros. |
required |
Source code in src/ctrlpy/freq_domain.py
__iter__
¶
Enable unpacking: gains, roots = root_locus_data(sys).
Yields:
| Type | Description |
|---|---|
NDArray[float64] | NDArray[complex128]
|
Gains array and roots 2D array. |
Source code in src/ctrlpy/freq_domain.py
StabilityMargins
dataclass
¶
Container for classical stability margins and crossover frequencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gm_db
|
float
|
Gain margin in decibels (dB). Inf if no phase crossover occurs. |
required |
pm_deg
|
float
|
Phase margin in degrees. Inf if no gain crossover occurs. |
required |
wcg
|
float
|
Gain crossover frequency in rad/s (where |G(jw)| = 1 / 0 dB). NaN if no crossover. |
required |
wcp
|
float
|
Phase crossover frequency in rad/s (where phase crosses -180 deg). NaN if no crossover. |
required |
Source code in src/ctrlpy/freq_domain.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
__iter__
¶
Enable unpacking: gm_db, pm_deg, wcg, wcp = margin(sys).
Yields:
| Type | Description |
|---|---|
float
|
gm_db, pm_deg, wcg, wcp. |
Source code in src/ctrlpy/freq_domain.py
bode_data
¶
Calculate frequency response data for Bode diagram analysis.
Evaluates the frequency response:
.. math::
G(j\omega) = |G(j\omega)| e^{j \angle G(j\omega)}
where magnitude in decibels is:
.. math::
|G(j\omega)|_{\text{dB}} = 20 \log_{10} |G(j\omega)|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sys
|
LinearTimeInvariant
|
Linear Time-Invariant system (TransferFunction or StateSpace). |
required |
omega
|
Sequence[float] | NDArray[floating] | None
|
Frequencies \(\omega\) in rad/s. If None, auto-generated based on poles and zeros. |
None
|
Returns:
| Type | Description |
|---|---|
BodeData
|
Dataclass containing frequencies \(\omega\), linear magnitude \(|G(j\omega)|\), unwrapped phase in degrees, magnitude in dB, phase in radians, and complex response \(G(j\omega)\). |
Source code in src/ctrlpy/freq_domain.py
nyquist_data
¶
Calculate complex frequency response data for Nyquist diagram analysis.
Evaluates \(G(j\omega)\) along the imaginary axis and optionally around indented arcs \(s = \epsilon e^{j\theta}\) (\(\theta \in [-\pi/2, \pi/2]\)) for poles at \(s=0\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sys
|
LinearTimeInvariant
|
Linear Time-Invariant system (TransferFunction or StateSpace). |
required |
omega
|
Sequence[float] | NDArray[floating] | None
|
Frequencies \(\omega\) in rad/s. If None, auto-generated based on poles and zeros. |
None
|
n_arc_points
|
int
|
Number of points to evaluate along the indented D-contour around \(s=0\) when an origin pole is present, by default 100. |
100
|
Returns:
| Type | Description |
|---|---|
NyquistData
|
Dataclass containing frequencies \(\omega\), complex frequency response \(G(j\omega)\), real part \(\mathrm{Re}(G(j\omega))\), imaginary part \(\mathrm{Im}(G(j\omega))\), and indented arc data if applicable. |
Source code in src/ctrlpy/freq_domain.py
root_locus_data
¶
Calculate closed-loop root locus trajectories for varying gains \(k \ge 0\).
Computes the roots of the characteristic equation:
.. math::
1 + k \cdot G(s) = 0 \iff D(s) + k \cdot N(s) = 0
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sys
|
LinearTimeInvariant
|
Open-loop SISO LTI system \(G(s) = N(s)/D(s)\). |
required |
gains
|
Sequence[float] | NDArray[floating] | None
|
1D array of non-negative gain values \(k \ge 0\). If None, automatically generated. |
None
|
Returns:
| Type | Description |
|---|---|
RootLocusData
|
Dataclass containing gains, 2D roots array of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If gains array is empty or contains negative values. |
Source code in src/ctrlpy/freq_domain.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | |
margin
¶
Compute gain margin, phase margin, and crossover frequencies for a SISO system.
.. math::
\text{GM} = -20 \log_{10} |G(j\omega_{cp})| \text{ dB}, \quad \angle G(j\omega_{cp}) = -180^\circ
.. math::
\text{PM} = 180^\circ + \angle G(j\omega_{cg}), \quad |G(j\omega_{cg})| = 1 \text{ (0 dB)}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sys
|
LinearTimeInvariant
|
Open-loop SISO LTI system \(G(s)\). |
required |
Returns:
| Type | Description |
|---|---|
StabilityMargins
|
Dataclass containing:
- |
Source code in src/ctrlpy/freq_domain.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | |