def TransresistanceAmplifierFourPort(G, Zi, Zo, Z0=50.0):
    """TransresistanceAmplifierFourPort
    Four port transresistance amplifier
    @param G float transresistance gain
    @param Zi float or complex input impedance
    @param Zo float or complex output impedance
    @param Z0 (optional) float reference impedance (defaults to 50 ohms)
    @return list of list s-parameter matrix for a transresistance amplifier
    @remark
    The current sense element senses the current entering port 1 and exiting port 2
    with a series resistance in the current sense path of Zi.

    The voltage generated by the amplifier has the plus terminal at port 4 and 
    and the minus terminal at port 3 with Zo in series.

    """
    S11 = Zi / (Zi + 2.0 * Z0)
    S12 = 2.0 * Z0 / (Zi + 2.0 * Z0)
    S13 = 0
    S14 = 0
    S21 = S12
    S22 = S11
    S23 = 0
    S24 = 0
    S31 = 2.0 * G * Z0 / ((Zi + 2.0 * Z0) * (Zo + 2.0 * Z0))
    S32 = -S31
    S33 = Zo / (Zo + 2.0 * Z0)
    S34 = 2.0 * Z0 / (Zo + 2.0 * Z0)
    S41 = S32
    S42 = S31
    S43 = S34
    S44 = S33
    return [[S11, S12, S13, S14], [S21, S22, S23, S24], [S31, S32, S33, S34
        ], [S41, S42, S43, S44]]
