def ReferenceImpedance(S, Z0f, Z0i=None, Kf=None, Ki=None): """Changes the reference impedance and scaling factor @param S s-parameter matrix to convert @param Z0f the reference impedance to convert to @param Z0i (optional) the reference impedance of the s-parameters (assumed 50 Ohms) @param Kf (optional) assumed to be sqrt(Z0f) @param Ki (optional) assumed to be sqrt(Z0i) @return the converted s-parameters @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0f, Kf) = Z0KHelper((Z0f, Kf), len(S)) (Z0i, Ki) = Z0KHelper((Z0i, Ki), len(S)) I = matrix(identity(len(S))) p = (matrix(Z0f) - matrix(Z0i)) * (matrix(Z0f) + matrix(Z0i)).getI() Kf = matrix(Ki) * matrix(Kf).getI() S = matrix(S) return (Kf * (I - p).getI() * (S - p) * (I - p * S).getI() * (I - p) * Kf.getI()).tolist()
def ReferenceImpedance(S,Z0f,Z0i=None,Kf=None,Ki=None): """Changes the reference impedance and scaling factor @param S s-parameter matrix to convert @param Z0f the reference impedance to convert to @param Z0i (optional) the reference impedance of the s-parameters (assumed 50 ohms) @param Kf (optional) assumed to be sqrt(Z0f) @param Ki (optional) assumed to be sqrt(Z0i) @return the converted s-parameters @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0f,Kf)=Z0KHelper((Z0f,Kf),len(S)) (Z0i,Ki)=Z0KHelper((Z0i,Ki),len(S)) I=array(identity(len(S))) p=(array(Z0f)-array(Z0i)).dot(inv(array(Z0f)+array(Z0i))) Kf=array(Ki).dot(inv(array(Kf))) S=array(S) return (Kf.dot(inv(I-p)).dot(S-p).dot( inv(I-p.dot(S))).dot(I-p).dot(inv(Kf))).tolist()
def Z2S(Z, Z0=None, K=None): """Converts Z-parameters to s-parameters @param Z list of list representing Z-parameter matrix to convert @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0, K) = Z0KHelper((Z0, K), len(Z)) Z = array(Z) return (inv(K).dot(Z - Z0).dot(inv(Z + Z0)).dot(K)).tolist()
def S2Z(S, Z0=None, K=None): """Converts s-parameters to Z-parameters @param S list of list representing s-parameter matrix to convert @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0, K) = Z0KHelper((Z0, K), len(S)) I = identity(len(S)) S = array(S) return (K.dot(I + S).dot(inv(I - S)).dot(Z0).dot(inv(K))).tolist()
def S2Y(S,Z0=None,K=None): """Converts s-parameters to Y-parameters @param S list of list representing s-parameter matrix to convert @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0,K)=Z0KHelper((Z0,K),len(S)) I=matrix(identity(len(S))) S=matrix(S) return (K*Z0.getI()*(I-S)*(I+S).getI()*K.getI()).tolist()
def Y2S(Y, Z0=None, K=None): """Converts Y-parameters to s-parameters @param Y list of list representing Y-parameter matrix to convert @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0, K) = Z0KHelper((Z0, K), len(Y)) I = matrix(identity(len(Y))) Y = matrix(Y) return (K.getI() * (I + Z0 * Y).getI() * (I - Z0 * Y) * K).tolist()
def S2ABCD(S,Z0=None,K=None): """Converts s-parameters to ABCD parameters. @param S list of list representing s-parameter matrix to convert @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @note Supports only two-port devices.\n @see Z0KHelper to see how the reference impedance and scaling factor are determined.""" (Z0,K)=Z0KHelper((Z0,K),len(S)) Z01=Z0.item(0,0) Z02=Z0.item(1,1) K1=K.item(0,0) K2=K.item(1,1) C11=matrix([[0,K2],[0,K2/Z02]]) C12=matrix([[0,K2],[0,-K2/Z02]]) C21=matrix([[K1,0],[-K1/Z01,0]]) C22=matrix([[K1,0],[K1/Z01,0]]) return array((C21+C22*S)*((C11+C12*S).getI())).tolist()
def Sp2Sw(Sp,Z0w=None,Z0p=None,Kw=None): """Converts power-wave s-parameters to pseudo-wave s-parameters @param Sp list of list power-wave based s-parameter matrix to convert @param Z0w (optional) the reference impedance of the pseudo-wave based s-parameters (assumed 50 Ohms) @param Z0p (optional) the reference impedance of the power-wave based s-parameters (assumed 50 Ohms) @param Kw (optional) the scaling factor of the pseudo-wave based s-parameters (assumed to be sqrt(Z0w) @return the converted s-parameters in pseudo-waves @see Z0KHelper to see how the reference impedance and scaling factor are determined for pseudo-waves. @see Z0KHelperPW to see the reference impedance and scaling factor are determined for power waves. """ if Z0p is None: Z0p=Z0w (Z0w,Kw)=Z0KHelper((Z0w,Kw),len(Sp)) (Z0p,Kp)=Z0KHelperPW(Z0p,len(Sp)) Sp=matrix(Sp) Sw=(Kw.getI()*Kp*Z0p.real.getI()*((Z0p.conjugate()-Z0w)+(Z0p+Z0w)*Sp)* ((Z0p.conjugate()+Z0w)+(Z0p-Z0w)*Sp).getI()*Kw*Kp.getI()*Z0p.real) return Sw
def Sp2Sw(Sp,Z0w=None,Z0p=None,Kw=None): """Converts power-wave s-parameters to pseudo-wave s-parameters @param Sp list of list power-wave based s-parameter matrix to convert @param Z0w (optional) the reference impedance of the pseudo-wave based s-parameters (assumed 50 ohms) @param Z0p (optional) the reference impedance of the power-wave based s-parameters (assumed 50 ohms) @param Kw (optional) the scaling factor of the pseudo-wave based s-parameters (assumed to be sqrt(Z0w) @return the converted s-parameters in pseudo-waves @see Z0KHelper to see how the reference impedance and scaling factor are determined for pseudo-waves. @see Z0KHelperPW to see the reference impedance and scaling factor are determined for power waves. """ if Z0p is None: Z0p=Z0w (Z0w,Kw)=Z0KHelper((Z0w,Kw),len(Sp)) (Z0p,Kp)=Z0KHelperPW(Z0p,len(Sp)) Sp=array(Sp) Sw=inv(Kw).dot(Kp).dot(inv(Z0p.real)).dot((Z0p.conj()-Z0w)+(Z0p+Z0w).dot(Sp)).dot( inv((Z0p.conj()+Z0w)+(Z0p-Z0w).dot(Sp))).dot(Kw).dot(inv(Kp)).dot(Z0p.real) return Sw.tolist()
def ABCD2S(ABCD, Z0=None, K=None): """Converts ABCD parameters to s-parameters.\n @param ABCD list of list representing ABCD matrix to convert. @param Z0 (optional) float or complex or list of reference impedance (defaults to None). @param K (optional) float or complex or list of scaling factor (defaults to None). @note Supports only two-port devices.\n @see Z0KHelper to see how the reference impedance and scaling factor are determined. """ (Z0, K) = Z0KHelper((Z0, K), len(ABCD)) Z01 = Z0.item(0, 0) Z02 = Z0.item(1, 1) K1 = K.item(0, 0) K2 = K.item(1, 1) C11 = matrix([[0, 0], [1.0 / (2.0 * K2), Z02 / (2.0 * K2)]]) C12 = matrix([[1.0 / (2.0 * K1), -Z01 / (2.0 * K1)], [0, 0]]) C21 = matrix([[0, 0], [1.0 / (2.0 * K2), -Z02 / (2.0 * K2)]]) C22 = matrix([[1.0 / (2.0 * K1), Z01 / (2.0 * K1)], [0, 0]]) return array((C21 + C22 * ABCD) * ((C11 + C12 * ABCD).getI())).tolist()