def convert(self, dest, Tout=False): N = dest(self.N) _, T_s2d, _ = convert(self.N.P, N.P, self.N) C = matrix_multiply(matrix_multiply(T_s2d, self.C), Hconj(T_s2d)) C[..., 0, 0] = C[..., 0, 0].real C[..., 1, 1] = C[..., 1, 1].real if Tout: return NoisyTwoport(N, C), T_s2d else: return NoisyTwoport(N, C)
def convert(fromP, toP, a): """Converts multiports using permutation matrices as described in [#] [#] J. Stenarson and K. Yhland "" IEEE Transactions on Instrumentation and Measurements 2009 vol. x no. 4 pp. xx-yy. """ PB = inv(toP) PA = fromP P = matrix_multiply(PA, PB) tau1 = P[..., :2, :2] sigma1 = P[..., :2, 2:] tau2 = P[..., 2:, :2] sigma2 = P[..., 2:, 2:] A = inv(tau1 - matrix_multiply(a, tau2)) B = -sigma1 + matrix_multiply(a, sigma2) res = matrix_multiply(A, B) return res, A, B
def passive_noise(twoport, Tamb=290): if isinstance(twoport, YArray): C = 2 * k * Tamb * (twoport + Hconj(twoport)) elif isinstance(twoport, ZArray): C = 2 * k * Tamb * (twoport + Hconj(twoport)) elif isinstance(twoport, SArray): eye = hftools.dataset.make_matrix(np.array([[1, 0], [0j, 1]]), dims=tuple()) C = k * Tamb * (eye - matrix_multiply(twoport, Hconj(twoport))) else: raise Exception("Can only convert passive Y, Z, and S to NoisyTwoport") return NoisyTwoport(twoport, C)
def make_passive_svd(S, delta=1e-6): """Force S-parameters in S to be passive. The S-parameters of S are scaled such that the highest eigenvalue of S' becomes |lambda|max < 1 - delta. The scaling is done using SVD. Doshi, et.al, DesignCon 2012, "Fast and Optimal Algorithms for Enforcing Reciprocity, Passivity and Causality in S-parameters" """ svd = np.linalg.svd out = [] for ss in S: ss = np.array(ss, copy=False) u, s, v = svd(ss) s = abs(s) - 1 s[s < 0] = 0 s = np.diag(s) delta = matrix_multiply(matrix_multiply(u, s), v) out.append(ss - delta) return S.__class__(out, dims=S.dims)
def switch_correct(b, a): Sm = matrix_multiply(b, inv(a)) return Sm
def test_3(self): res = hfmath.matrix_multiply(self.m2, self.m) self.assertAllclose(res, np.dot([[1., 2], [3, 4]], [[1., 2], [3, 4]])) self.assertEqual(res.shape, (3, 2, 2)) self.assertEqual(res.dims, (self.J, self.mi, self.mj))