Skip to content

Commit

Permalink
Merge pull request scikit-rf#1200 from FranzForstmayr/vectorfit_numpy
Browse files Browse the repository at this point in the history
Use trapezoid rule from scipy
  • Loading branch information
jhillairet authored Nov 11, 2024
2 parents 71f2270 + 8e0a1c7 commit 875e086
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions skrf/tests/test_vectorfitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ def test_passivity_enforcement(self):
# check if model is now passive
self.assertTrue(vf.is_passive())

def test_autofit(self):
vf = skrf.VectorFitting(skrf.data.ring_slot)
vf.auto_fit()

assert vf.get_model_order(vf.poles) == 6
assert np.sum(vf.poles.imag == 0.0) == 0
assert np.sum(vf.poles.imag > 0.0) == 3

assert np.allclose(vf.get_rms_error(), 1.2748979815157275e-06)



suite = unittest.TestLoader().loadTestsFromTestCase(VectorFittingTestCase)
unittest.TextTestRunner(verbosity=2).run(suite)
3 changes: 2 additions & 1 deletion skrf/vectorFitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import TYPE_CHECKING, Any

import numpy as np
from scipy.integrate import trapezoid

try:
from matplotlib.ticker import EngFormatter
Expand Down Expand Up @@ -140,7 +141,7 @@ def get_spurious(poles: np.ndarray, residues: np.ndarray, n_freqs: int = 101, ga
omega_eval = np.linspace(np.min(poles.imag) / 3, np.max(poles.imag) * 3, n_freqs)
h = (residues[:, None, :] / (1j * omega_eval[:, None] - poles)
+ np.conj(residues[:, None, :]) / (1j * omega_eval[:, None] - np.conj(poles)))
norm2 = np.sqrt(np.trapezoid(h.real ** 2 + h.imag ** 2, omega_eval, axis=1))
norm2 = np.sqrt(trapezoid(h.real ** 2 + h.imag ** 2, omega_eval, axis=1))
spurious = np.all(norm2 / np.mean(norm2) < gamma, axis=0)
return spurious

Expand Down

0 comments on commit 875e086

Please sign in to comment.