Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid division by zero at 0 Hz in DistributedCircuit #658

Merged
merged 1 commit into from
May 10, 2022

Conversation

Ttl
Copy link
Collaborator

@Ttl Ttl commented May 10, 2022

Adds small offset to avoid dividing by zero if frequency is zero. DC S-parameters are extremely slightly off since adding the offset adds very small imaginary part when DC S-parameters should be real. It's better than nans though and fixing it properly would need more radical changes.

These changes are enough to avoid nans when both or only either R or G is zero. Just adding offset to Y is not enough when R is zero.

import skrf
from skrf.media import DistributedCircuit
freq = skrf.F(0,0,1)
m = DistributedCircuit(frequency = freq,
                          z0 = 50,
                          C = 93.5e-12,
                          L = 273e-9,
                          R = 0,
                          G = 0)
line = m.line(10, 'm', z0=m.Z0, embed=True)
print(line.s)
Before:

[[[nan+nanj nan+nanj]
  [nan+nanj nan+nanj]]]

After:

[[[-4.4408921e-16-2.499e-10j  1.0000000e+00-2.501e-10j]
  [ 1.0000000e+00-2.501e-10j -4.4408921e-16-2.499e-10j]]]

@github-actions github-actions bot added the Media label May 10, 2022
@jhillairet jhillairet merged commit aecbb5c into scikit-rf:master May 10, 2022
@jhillairet jhillairet mentioned this pull request Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants