I have a .s3p file with 3-port S-parameters that I would like to cascade into a network with 2-port S-parameters. I am unable to figure out how to put them together in the RF Toolbox.
MATLAB: How to cascade N-port S-parameters using the RF Toolbox
RF Toolbox
Related Solutions
The solution is definitely not unique.
Let the two result matrices be [rab11,0;0,rab22] and [rcd11;0;0;rcd22]
Set rcd22 to any non-zero non-infinite value. Then, except for possible singularities,
rab11 = rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b11+b21*d12*d11*(c11*c22-c12*c21))*a12+a11*b11*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((d12*c21*b22*a22-b12*a21*d22*c22)*b11+d12*b12*b21*(-c21*a22+a21*c22))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))*(c11*c22-c12*c21)*(d11*d22-d12*d21))
rab22 = -rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b12+b22*d12*d11*(c11*c22-c12*c21))*a22+a21*b12*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((b11*d22*c22*a11-d12*c21*a12*b21)*b12-d12*b11*b22*(c22*a11-a12*c21))*a22-a12*a21*c22*b12*(b11*d22-b21*d12))*(c11*c22-c12*c21)*(d11*d22-d12*d21))
rcd11 = -rcd22*((d11*c11*(b11*b22-b12*b21)*a22-a21*c12*b12*(b11*d21-b21*d11))*a12+a11*a22*b11*c12*(b12*d21-d11*b22))/((c21*d12*(b11*b22-b12*b21)*a22-a21*c22*b12*(b11*d22-b21*d12))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))
You can see in this that rcd22 acts as an arbitrary scale factor for the other coefficients.
The X matrix then becomes
X(1,1) = (b22*a22*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b11+b21*d12*d11*(c11*c22-c12*c21))*a12+a11*b11*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((d12*c21*b22*a22-b12*a21*d22*c22)*b11+d12*b12*b21*(-c21*a22+a21*c22))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))*(c11*c22-c12*c21)*(d11*d22-d12*d21))-b22*a12*rab21-b21*a22*rab12-b21*a12*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b12+b22*d12*d11*(c11*c22-c12*c21))*a22+a21*b12*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((b11*d22*c22*a11-d12*c21*a12*b21)*b12-d12*b11*b22*(c22*a11-a12*c21))*a22-a12*a21*c22*b12*(b11*d22-b21*d12))*(c11*c22-c12*c21)*(d11*d22-d12*d21)))/((a11*a22-a12*a21)*(b11*b22-b12*b21))
X(1,2) = -(b12*a22*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b11+b21*d12*d11*(c11*c22-c12*c21))*a12+a11*b11*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((d12*c21*b22*a22-b12*a21*d22*c22)*b11+d12*b12*b21*(-c21*a22+a21*c22))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))*(c11*c22-c12*c21)*(d11*d22-d12*d21))-b12*a12*rab21-b11*a22*rab12-b11*a12*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b12+b22*d12*d11*(c11*c22-c12*c21))*a22+a21*b12*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((b11*d22*c22*a11-d12*c21*a12*b21)*b12-d12*b11*b22*(c22*a11-a12*c21))*a22-a12*a21*c22*b12*(b11*d22-b21*d12))*(c11*c22-c12*c21)*(d11*d22-d12*d21)))/((a11*a22-a12*a21)*(b11*b22-b12*b21))
X(2,1) = -(b22*a21*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b11+b21*d12*d11*(c11*c22-c12*c21))*a12+a11*b11*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((d12*c21*b22*a22-b12*a21*d22*c22)*b11+d12*b12*b21*(-c21*a22+a21*c22))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))*(c11*c22-c12*c21)*(d11*d22-d12*d21))-b22*a11*rab21-b21*a21*rab12-b21*a11*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b12+b22*d12*d11*(c11*c22-c12*c21))*a22+a21*b12*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((b11*d22*c22*a11-d12*c21*a12*b21)*b12-d12*b11*b22*(c22*a11-a12*c21))*a22-a12*a21*c22*b12*(b11*d22-b21*d12))*(c11*c22-c12*c21)*(d11*d22-d12*d21)))/((a11*a22-a12*a21)*(b11*b22-b12*b21))
X(2,2) = -(b22*a21*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b11+b21*d12*d11*(c11*c22-c12*c21))*a12+a11*b11*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((d12*c21*b22*a22-b12*a21*d22*c22)*b11+d12*b12*b21*(-c21*a22+a21*c22))*a12+a11*a22*b11*c22*(-d12*b22+b12*d22))*(c11*c22-c12*c21)*(d11*d22-d12*d21))-b22*a11*rab21-b21*a21*rab12-b21*a11*rcd22*(((c12*c21*d12*d21-c11*c22*d11*d22)*b12+b22*d12*d11*(c11*c22-c12*c21))*a22+a21*b12*c12*c22*(d11*d22-d12*d21))*(a11*a22-a12*a21)*(b11*b22-b12*b21)/((((b11*d22*c22*a11-d12*c21*a12*b21)*b12-d12*b11*b22*(c22*a11-a12*c21))*a22-a12*a21*c22*b12*(b11*d22-b21*d12))*(c11*c22-c12*c21)*(d11*d22-d12*d21)))/((a11*a22-a12*a21)*(b11*b22-b12*b21))
This was calculated using straight-forward linear algebra by multiplying appropriate inverses on both sides to get two isolated X equations, and then solve()'ing for the corresponding components to be the same.
Not all nasty looking, high order nonlinear systems of equations have solutions. vpasolve is a capable numerical solver, but it has limits. One issue is that when working in high precision, things take longer to do. All computations are slower. It will probably happen that vpasolve will return a high precision solution eventually.
So I tried posing this as a problem for fsolve. Working in double precision is far faster. fsolve can sometimes have issues with complex valued functions. But it often does seem to work.
Here is your code, pasted into a function to be used for fsolve.
function eqs = funs(S)S11 = S(1);S22 = S(2);S33 = S(3);S12 = S(4);S13 = S(5);S23 = S(6);A11= 0.2346 + 0.1345i;A21= 0.8550 - 0.4363i;A22= -0.0412 + 0.2931i;B11= 0.2346 + 0.1345i;B21= 0.8550 - 0.4363i;B22= -0.0412 + 0.2931i;D11= 0.2346 + 0.1345i;D21= 0.8550 - 0.4363i;D22= -0.0412 + 0.2931i;c11= 0.169033453278504 + 0.127942837737115i;c22= 0.169951074114244 + 0.148423165394202i;c33= 0.168939745364374 + 0.142538799523638i;c21= -0.00172796568379862 + 0.201091742020021i;c31= -0.00152297772077853 + 0.199585730377658i;c32= -0.00523160858486265 + 0.199472640309087i;eqs = [(A11.*A22.*S11 - A21.^2.*S11 - A11 + A11.*B22.*S22 + A11.*D22.*S33 - A21.^2.*B22.*S12.^2 - A21.^2.*D22.*S13.^2 + A11.*A22.*B22.*S12.^2 + A11.*A22.*D22.*S13.^2 + A11.*B22.*D22.*S23.^2 + A21.^2.*B22.*S11.*S22 + A21.^2.*D22.*S11.*S33 + A21.^2.*B22.*D22.*S11.*S23.^2 + A21.^2.*B22.*D22.*S13.^2.*S22 + A21.^2.*B22.*D22.*S12.^2.*S33 - A11.*A22.*B22.*S11.*S22 - A11.*A22.*D22.*S11.*S33 - A11.*B22.*D22.*S22.*S33 - A11.*A22.*B22.*D22.*S11.*S23.^2 - A11.*A22.*B22.*D22.*S13.^2.*S22 - A11.*A22.*B22.*D22.*S12.^2.*S33 - 2.*A21.^2.*B22.*D22.*S12.*S13.*S23 - A21.^2.*B22.*D22.*S11.*S22.*S33 + 2.*A11.*A22.*B22.*D22.*S12.*S13.*S23 + A11.*A22.*B22.*D22.*S11.*S22.*S33)./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c11; -(A21.*B21.*(S12 + D22.*S13.*S23 - D22.*S12.*S33))./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c21; -(A21.*D21.*(S13 + B22.*S12.*S23 - B22.*S13.*S22))./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c31; (A22.*B11.*S11 - B21.^2.*S22 - B11 + B11.*B22.*S22 + B11.*D22.*S33 - A22.*B21.^2.*S12.^2 - B21.^2.*D22.*S23.^2 + A22.*B11.*B22.*S12.^2 + A22.*B11.*D22.*S13.^2 + B11.*B22.*D22.*S23.^2 + A22.*B21.^2.*S11.*S22 + B21.^2.*D22.*S22.*S33 + A22.*B21.^2.*D22.*S11.*S23.^2 + A22.*B21.^2.*D22.*S13.^2.*S22 + A22.*B21.^2.*D22.*S12.^2.*S33 - A22.*B11.*B22.*S11.*S22 - A22.*B11.*D22.*S11.*S33 - B11.*B22.*D22.*S22.*S33 - A22.*B11.*B22.*D22.*S11.*S23.^2 - A22.*B11.*B22.*D22.*S13.^2.*S22 - A22.*B11.*B22.*D22.*S12.^2.*S33 - 2.*A22.*B21.^2.*D22.*S12.*S13.*S23 - A22.*B21.^2.*D22.*S11.*S22.*S33 + 2.*A22.*B11.*B22.*D22.*S12.*S13.*S23 + A22.*B11.*B22.*D22.*S11.*S22.*S33)./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c22; -(B21.*D21.*(S23 + A22.*S12.*S13 - A22.*S11.*S23))./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c32; (A22.*D11.*S11 - D21.^2.*S33 - D11 + B22.*D11.*S22 + D11.*D22.*S33 - A22.*D21.^2.*S13.^2 - B22.*D21.^2.*S23.^2 + A22.*B22.*D11.*S12.^2 + A22.*D11.*D22.*S13.^2 + B22.*D11.*D22.*S23.^2 + A22.*D21.^2.*S11.*S33 + B22.*D21.^2.*S22.*S33 + A22.*B22.*D21.^2.*S11.*S23.^2 + A22.*B22.*D21.^2.*S13.^2.*S22 + A22.*B22.*D21.^2.*S12.^2.*S33 - A22.*B22.*D11.*S11.*S22 - A22.*D11.*D22.*S11.*S33 - B22.*D11.*D22.*S22.*S33 - A22.*B22.*D11.*D22.*S11.*S23.^2 - A22.*B22.*D11.*D22.*S13.^2.*S22 - A22.*B22.*D11.*D22.*S12.^2.*S33 - 2.*A22.*B22.*D21.^2.*S12.*S13.*S23 - A22.*B22.*D21.^2.*S11.*S22.*S33 + 2.*A22.*B22.*D11.*D22.*S12.*S13.*S23 + A22.*B22.*D11.*D22.*S11.*S22.*S33)./(A22.*S11 + B22.*S22 + D22.*S33 + A22.*B22.*S12.^2 + A22.*D22.*S13.^2 + B22.*D22.*S23.^2 - A22.*B22.*S11.*S22 - A22.*D22.*S11.*S33 - B22.*D22.*S22.*S33 - A22.*B22.*D22.*S11.*S23.^2 - A22.*B22.*D22.*S13.^2.*S22 - A22.*B22.*D22.*S12.^2.*S33 + 2.*A22.*B22.*D22.*S12.*S13.*S23 + A22.*B22.*D22.*S11.*S22.*S33 - 1)-c33];
After saving this function on my search path, I used fsolve, as follows:
format long gSfinal = fsolve(@funs,(1+i)*ones(1,6))Equation solved.fsolve completed because the vector of function values is near zeroas measured by the default value of the function tolerance, andthe problem appears regular as measured by the gradient.<stopping criteria details>Sfinal =Columns 1 through 3 -0.0576463452402932 - 0.0753664180207837i -0.0744682052419572 - 0.0630375797716533i -0.0698118920703255 - 0.0672129482711116iColumns 4 through 6 -0.185173231731065 + 0.109260636702373i -0.183468124937688 + 0.10862578397362i -0.186854054845906 + 0.104967752613526i
As a test that this is a solution in double precision, evaluate funs at that point.
funs(Sfinal)ans = 2.04330996567137e-12 + 8.08547673258886e-13i 2.06829562157673e-12 + 8.28642710004601e-13i 2.07329856408145e-12 + 8.41465785939022e-13i 2.07303618715571e-12 + 7.6394446324457e-13i 2.08355208086708e-12 + 8.14071032806396e-13i 2.05693795329864e-12 + 7.88147325181399e-13i
Note that when calling fsolve, it was necessary to use a complex start point. Even then, I have seen cases where fsolve fails for complex valued problems, though I have not yet pinned down why it may fail. It did seem to work here though.
Related Question
- How to cascade a four port device with a two port device using rfckt objects in RF Toolbox
- How to pass Z-parameters as a parameter input to the plot function of the rfckt.cascade object within the RF Toolbox 2.3 (R2008a)
- Does the “Load Impedance” field in the “Output Port” block accept complex numbers in RF Blockset 2.3 (R2008b)
- Can a complete 4-port S-parameter (including differential and common mode) simulation of a RF broadband system be done using the RF Toolbox 2.5 (R2009a)
Best Answer