def proc_info(info, f, data, fn, noisedata): info_list = info.upper().split() if len(info_list) == 5: info = freq_mult, twoporttype, datatype, rtype, z0 = info_list elif len(info_list) == 3: info = freq_mult, twoporttype, datatype = info_list z0 = 1. else: msg = ("# format should only have 5 values this one has %d" % len(info_list)) raise TouchstoneError(msg) z0 = float(z0) f = f * freqmultdict[freq_mult] if fn is not None: fn = fn * freqmultdict[freq_mult] convfunc = dict(RI=re_im_to_complex, DB=dB_angle_to_complex, MA=mag_angle_to_complex) if datatype not in convfunc: pars = datatype msg = "Unknown dataformat: %s, valid formats: RI, DB, MAG" % pars raise TouchstoneError(msg) out = np.empty((data.shape[0], data.shape[1] // 2), dtype=np.complex128) out[...] = convfunc[datatype](data[:, ::2], data[:, 1::2]) if out.shape[1] == 1: out.shape = (out.shape[0], 1, 1) elif out.shape[1] == 4: out.shape = (out.shape[0], 2, 2) out = out.transpose(0, 2, 1) else: N = int(sqrt(out.shape[1])) out.shape = (out.shape[0], N, N) dims = (DimSweep("freq", f, unit="Hz"), ) if fn is not None and len(f) == len(fn) and np.allclose(f, fn): noisedims = dims elif fn is None: noisedims = None else: noisedims = (DimSweep("freqn", fn, unit="Hz"), ) out = make_matrix(out, dims) f = hfarray(f, dims) db = DataBlock() db[info[1]] = out if noisedata is not None: db.Rn = hfarray(noisedata[..., -1], dims=noisedims) * z0 db.Fmin = 10**(hfarray(noisedata[..., 0], dims=noisedims) / 10) db.Gopt = hfarray(convfunc[datatype](noisedata[:, 1], noisedata[:, 2]), dims=noisedims) db.Z0 = hfarray(z0, unit="Ohm") return db
def proc_info(info, f, data, fn, noisedata): info_list = info.upper().split() if len(info_list) == 5: info = freq_mult, twoporttype, datatype, rtype, z0 = info_list elif len(info_list) == 3: info = freq_mult, twoporttype, datatype = info_list z0 = 1. else: msg = ("# format should only have 5 values this one has %d" % len(info_list)) raise TouchstoneError(msg) z0 = float(z0) f = f * freqmultdict[freq_mult] if fn is not None: fn = fn * freqmultdict[freq_mult] convfunc = dict(RI=re_im_to_complex, DB=dB_angle_to_complex, MA=mag_angle_to_complex) if datatype not in convfunc: pars = datatype msg = "Unknown dataformat: %s, valid formats: RI, DB, MAG" % pars raise TouchstoneError(msg) out = np.empty((data.shape[0], data.shape[1] // 2), dtype=np.complex128) out[...] = convfunc[datatype](data[:, ::2], data[:, 1::2]) if out.shape[1] == 1: out.shape = (out.shape[0], 1, 1) elif out.shape[1] == 4: out.shape = (out.shape[0], 2, 2) out = out.transpose(0, 2, 1) else: N = int(sqrt(out.shape[1])) out.shape = (out.shape[0], N, N) dims = (DimSweep("freq", f, unit="Hz"), ) if fn is not None and len(f) == len(fn) and np.allclose(f, fn): noisedims = dims elif fn is None: noisedims = None else: noisedims = (DimSweep("freqn", fn, unit="Hz"), ) out = make_matrix(out, dims) f = hfarray(f, dims) db = DataBlock() db[info[1]] = out if noisedata is not None: db.Rn = hfarray(noisedata[..., -1], dims=noisedims) * z0 db.Fmin = 10 ** (hfarray(noisedata[..., 0], dims=noisedims) / 10) db.Gopt = hfarray(convfunc[datatype](noisedata[:, 1], noisedata[:, 2]), dims=noisedims) db.Z0 = hfarray(z0, unit="Ohm") return db
def noise_parameters(self, partial=False): db = DataBlock() db.S = SArray(self.N) if isinstance(self.N, ABCDArray): CA = self.C / (2 * k * 290) CA11 = CA[..., 0, 0] CA12 = CA[..., 0, 1] CA22 = CA[..., 1, 1] Rn = CA11.real Yopt = (np.sqrt(CA22 / CA11 - (CA12.imag / CA11) ** 2) + 1j * (CA12.imag / CA11)) Fmin = 1 + (CA12 + CA11 * Yopt.conj()).real if partial: db.CA = CA db.Rn = Rn db.Yopt = Yopt db.Fmin = Fmin db.Gopt = (1 / 50. - Yopt) / (1 / 50. + Yopt) return db N = self.convert(YArray) Y11 = N.N[..., 0, 0] Y21 = N.N[..., 1, 0] C = N.C / (4 * k * 290) CY11 = C[..., 0, 0] CY12 = C[..., 0, 1] CY22 = C[..., 1, 1] Rn = (CY22 / abs(Y21) ** 2).real Ycor = Y11 - CY12 / CY22 * Y21 Gn = (CY11 - abs(Y11 - Ycor) ** 2 * Rn).real Yopt = np.sqrt(Gn / Rn + Ycor.real ** 2) - 1j * Ycor.imag Fmin = 1 + 2 * Rn * (Ycor.real + Yopt.real) db.CY = C db.Gn = Gn db.Ycor = Ycor db.S = SArray(self.N) db.Rn = Rn db.Fmin = Fmin db.Gopt = (1 / 50. - Yopt) / (1 / 50. + Yopt) db.Yopt = Yopt return db