diff --git a/skrf/tests/test_vectorfitting.py b/skrf/tests/test_vectorfitting.py index 785654b13..637212d4d 100644 --- a/skrf/tests/test_vectorfitting.py +++ b/skrf/tests/test_vectorfitting.py @@ -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) diff --git a/skrf/vectorFitting.py b/skrf/vectorFitting.py index 2829e7a7c..8a3cab472 100644 --- a/skrf/vectorFitting.py +++ b/skrf/vectorFitting.py @@ -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 @@ -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