#include "parameters.h" using namespace std; Sparam::Sparam(const Tparam &t) { data = Eigen::MatrixXcd(2,2); set(1,1, t.get(1,2) / t.get(2,2)); set(2,1, Type(1) / t.get(2,2)); set(1,2, (t.get(1,1)*t.get(2,2) - t.get(1,2)*t.get(2,1)) / t.get(2,2)); set(2,2, -t.get(2,1) / t.get(2,2)); } Sparam::Sparam(const ABCDparam &a, Type Z01, Type Z02) { data = Eigen::MatrixXcd(2,2); auto denom = a.get(1,1)*Z02+a.get(1,2)+a.get(2,1)*Z01*Z02+a.get(2,2)*Z01; set(1,1, (a.get(1,1)*Z02+a.get(1,2)-a.get(2,1)*conj(Z01)*Z02-a.get(2,2)*conj(Z01)) / denom); set(1,2, (2.0*(a.get(1,1)*a.get(2,2)-a.get(1,2)*a.get(2,1))*sqrt(real(Z01)*real(Z02))) / denom); set(2,1, (2.0*sqrt(real(Z01)*real(Z02))) / denom); set(2,2, (-a.get(1,1)*conj(Z02)+a.get(1,2)-a.get(2,1)*Z01*conj(Z02)+a.get(2,2)*Z01) / denom); } Sparam::Sparam(const ABCDparam &a, Type Z0) : Sparam(a, Z0, Z0) { } Sparam::Sparam(const Zparam &Z, std::vector Z0n) { if(Z.ports() != Z0n.size()) { throw std::runtime_error("number of supplied characteristic impedances does not match number of ports"); } /* general formula for converting S parameters to Z parameters: * S = (sqrt(y)*Z*sqrt(y)-1)*(sqrt(y)*Z*sqrt(y)+1)^-1 * with: * Z = Z parameter matrix * 1 = identity matrix * sqrt(y) = diagonal matrix with the root of characteristic admittances as it non-zero elements */ // create identity matrix auto ident = Eigen::MatrixXcd::Identity(Z.ports(), Z.ports()); // create sqrt(y) matrix Eigen::MatrixXcd sqrty = Eigen::MatrixXcd::Zero(Z.ports(), Z.ports()); // fill with characteristic admittance for(unsigned int i=0;i(Z.ports(), Z0)) { } void Sparam::swapPorts(unsigned int p1, unsigned int p2) { data.col(p1-1).swap(data.col(p2-1)); data.row(p1-1).swap(data.row(p2-1)); } Sparam Sparam::reduceTo(std::vector ports) const { auto ret = Sparam(ports.size()); for(unsigned int from=0;from max_port) { max_port = i; } if(j > max_port) { max_port = j; } } data = Eigen::MatrixXcd(max_port, max_port); for(unsigned int i=0;i(j.value(s_real, 0.0), j.value(s_imag, 0.0)); } else { // no data, set to zero data(i, _j) = 0; } } } } Yparam::Yparam(const Sparam &S, std::vector Z0n) : Yparam(Zparam(S, Z0n)) { } Yparam::Yparam(const Sparam &S, Type Z0) : Yparam(S, std::vector(S.ports(), Z0)) { } Yparam::Yparam(const Zparam &Z) { data = Z.data.inverse(); } Zparam::Zparam(const Sparam &S, std::vector Z0n) { if(S.ports() != Z0n.size()) { throw std::runtime_error("number of supplied characteristic impedances does not match number of ports"); } /* general formula for converting S parameters to Z parameters: * Z = sqrt(z)*(1+S)*(1-S)^-1*sqrt(z) * with: * S = S parameter matrix * 1 = identity matrix * sqrt(z) = diagonal matrix with the root of characteristic impedances as it non-zero elements */ // create identity matrix auto ident = Eigen::MatrixXcd::Identity(S.ports(), S.ports()); // create sqrt(z) matrix Eigen::MatrixXcd sqrtz = Eigen::MatrixXcd::Zero(S.ports(), S.ports()); // fill with characteristic impedance for(unsigned int i=0;i(S.ports(), Z0)) { } Zparam::Zparam(const Yparam &Y) { data = Y.data.inverse(); }