Skip to content

Commit

Permalink
copied in mag for s params
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevan committed Nov 19, 2024
1 parent a1dda18 commit dd7b0c7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/net/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def test_rollett_stability(self, n2):
k = round(n2.rollett_stability, 2)
assert k == 1.74

def test_max_available_gain(self, n2):
mag = round(n2.max_available_gain,1)
assert mag == 16.1


class TestNetH:
@pytest.fixture
Expand Down
20 changes: 20 additions & 0 deletions ycx_complex_numbers/S.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

from ycx_complex_numbers.complex import Complex, Net
from ycx_complex_numbers.Y import NetY
import ycx_complex_numbers as cn
Expand Down Expand Up @@ -100,3 +102,21 @@ def rollett_stability(self):
return (
1 + abs(self.determinant) ** 2 - abs(self.s11) ** 2 - abs(self.s22) ** 2
) / (2 * abs(self.s21) * abs(self.s12))

@property
def max_available_gain(self):
Ds = self.determinant
K = self.rollett_stability
if K <= 1:
raise ValueError("K must be greater than 1")

B1 = 1 + abs(self.s11) ** 2 - abs(self.s22) ** 2 - abs(Ds) ** 2

if B1 < 0:
k_calc = K + math.sqrt(K**2 - 1)
else:
k_calc = K - math.sqrt(K**2 - 1)

mag_db = 10 * math.log10(abs(self.s21) / abs(self.s12)) + 10 * math.log10(abs(k_calc))

return mag_db

0 comments on commit dd7b0c7

Please sign in to comment.