(*  MultiConductor Modeling and Analysis                                    *)
(*  Copyright (C)2018 Sasan Ardalan                                          *)
(*  This program is free software:you can redistribute it and/or modify      *)
(*  it under the terms of the GNU General Public License as published by     *)
(*  the Free Software Foundation,either version 3 of the License,or          *)
(*  at your option) any later version.This program is distributed            *)
(*  in the hope that it will be useful,but WITHOUT ANY WARRANTY              *)
(*  without even the implied warranty of                                     *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the              *)
(*  GNU General Public License for more details.You should have              *)
(*  received a copy of the GNU General Public License                        *)
(*  along with this program.If not,see<http://www.gnu.org/licenses/>.        *)
(*  Author:Sasan Ardalan                                                     *)
(*  Date:December 8,2018                                                     *)
(*  http://www.radiocalc.com                                                 *)
(*                                                                           *)
(* The formulas for calculating the voltage at any point along a             *)
(* multiconductor system are derived in a report by Dr. Ardalan and          *)
(* Mike Riddle (Masters Electrical Engineering)   NC State University        *)
(* The Report is available at:                                               *)
(* http://www.radiocalc.com/MultiConductorCAD.html                           *)
(* Screen shots from above paper                                             *)
(* This Notebook studies crosstalk with  two Microstrip                      *)
(*         conductors over a ground                                          *)

(*                                                                           *)

(* Inductance and Capacitance Matrices Results from                          *)
(* Per Unit Length Multiconductor Microstrip                                 *)
(* David A.Hill,Kenneth H.Cavcey,Robert T.Johnk,                             *)
(* "Crosstalk Between Microstrip Transmission Lines,"                        *)
(* IEEE TRANSACTIONS ON ELECTROMAGNETIC COMPATIBILITY,VOL.36,NO.4,           *)
(* NOVEMBER 1994                                                             *)

(* w=189 mil Sep=189 mil Length=m 19.6cm, Board Thickness 61 mil  epsiloR=2.2 *)   

(*  Computations  closely match   measurements for Near End Cross Talk        *)
(* Reported in [Hill, 1984]                                                   *)
(* Computations also closely match the Theoretical results in [Hill, 1984]    *)
(* Note Formulas by Ardalan and Rile and Suh are not approximations.          *)

(*  Code matches measurements in [Hill, 1984] for Far  End Cross Talk         *)
(*  Note   We are ignoring losses.                                            *)
(* Straight forward to put in conductor losses.                               *)
 
                










 
 

NN=2 (* Number of Conductors    *)

PI=3.14159265358979323846

  MU =4*PI*1.0*10^(-7)
  EPS =1.0*10^(-9)/36/PI
 MUO2PI =2*1.0*10^(-7)
 RHO =1.72*10^(-6) (* ohms-cm copper *)
SIGMA =58*10^6 (* mho/m copper  *)
TINY =1.0*10^(-20)
epsr=1.0 


(************** STRUCTURE   *********)


L=0.196(* Length Meters *)
  
x=0   (* Near End *)

(*
From [Hill, 1994] 
Length=19.6 cm
epsilon_r=2.2
T (h)= 1.55mm  (61.0236 mils) 
w= 4.8mm  (189 mils)
    sep=4.8mm (189 mils)


*)

 
(************** END STRUCTURE   *********)

(* Start Calculating per Specified Frequency in List    ****)
transferFunction ={}
freqValues ={}

PointsN=200
deltaF=50*10^6
freqStart=100*10^6
freq=freqStart

For [iii=0, iii<PointsN, iii++ ,
Print["freq=",freq];
  
 
Vs={1,0};
R=50;
 


 ZLoad ={{R,0},{0,R}} ;
 ZSource={{R,0 },{0,R }};
 Print["ZLoad",ZLoad];
 
YLoad2=Inverse[ZLoad];
 
 Print["YLoad2"];
 Print[YLoad2];

xdet=Det[YLoad];
Print ["Det YLoad",xdet];



(* Inductance and Capacitance Matrices Results from Per Unit Length Multiconductor Microstrip   *)
(* Based on parameters in [Hill, 1004] Calculated with Mathematica Code by Ardalan Based on   *)
(* Fortran Code by Clayton Paul. See http:/www.radiocalc,com               *)
(* 
Following Calculated Using  Fortran Code:
1 1 2.28919E-07=L(1,1)
1 2 1.17596E-08=L(1,2)
2 2 2.28919E-07=L(2,2)
1 1 9.15542E-11=C(1,1)
1 2-2.21411E-12=C(1,2)
2 2 9.15543E-11=C(2,2)
1 1 4.87332E-11=C0(1,1)
1 2-2.50344E-12=C0(1,2)
2 2 4.87332E-11=C0(2,2)

NUMBER OF LANDS=2
NUMBER OF DIVISIONS PER LAND=50
LAND WIDTH (mils)=1.890E+02
EDGE-TO-EDGE SEPARATION (mils)=1.890E+02
BOARD THICKNESS (mils)=6.100E+01
RELATIVE DIELECTRIC CONSTANT=2.200E+00

*)
(* Following from Mathematica Code   *)

LL={{2.2891769210934534`*^-7,1.1759880574018147`*^-8},{1.1759880574018135`*^-8,2.2891769210934463`*^-7}};
Cap={{9.15542`*^-11,-2.21411*^-12},{-2.21411*^-12,9.15543`*^-11}};


omega=2*PI*freq;

wL=N[omega*LL];

wL=wL*I;

wC=N[omega*Cap];
wC=wC*I;

GammaSqr= wL.wC;
Print["GammaSqr=",GammaSqr];

gammaEVect= Eigenvectors[GammaSqr];
gammaSqrEigenValues= Eigenvalues[GammaSqr];
Print["gamma2EigenVals=",gammaSqrEigenValues];
gammaSqrEigenValuesMatrix=DiagonalMatrix[gammaSqrEigenValues];
gamma=gammaEVect.Sqrt[gammaSqrEigenValuesMatrix].Inverse[gammaEVect];
Print["gamma=",gamma];
gammaEigenVals= Eigenvalues[gamma];
Print["gammaEigenVals=",gammaEigenVals];


Y0=Inverse[wL].gamma;
Z0=Inverse[Y0];
Zly0=ZLoad.Y0;
 


CapGammaL=Inverse[Zly0+IdentityMatrix[2]].(Zly0-IdentityMatrix[2]);
exml=MatrixExp[(x-L)*gamma];
emgx=MatrixExp[(-1)*x*gamma];
emgL=MatrixExp[(-L)*gamma];

Print["emgL=",emgL];

p1=(IdentityMatrix[NN]+exml.CapGammaL.exml);
p2=Inverse[(IdentityMatrix[NN]-emgL.CapGammaL.emgL)];
p3=p1.emgx.p2.Z0;
p4=(IdentityMatrix[NN]+emgL.CapGammaL.emgL);
p5=Inverse[(IdentityMatrix[NN]-emgL.CapGammaL.emgL)];
p6=p4.p5;
p7 =ZSource+p6.Z0;
p8=Inverse[p7];
p9=p8.Vs;
Vx=p3.p9;
Vx1=Vx[[1]];
Vx1a=Abs[Vx1];
Vx2=Vx[[2]];
Vx2a=Abs[Vx2];




Print[freq];
Print[Vx2a];
Print["Vx2=",Vx2];

AppendTo[transferFunction,Abs[Vx2/Vx1 ]];
AppendTo[freqValues,freq]; 
 

freq=freq+deltaF;

]  (* end for loop  *)

Print["transferFunction=",transferFunction];
Print["freqValues=",freqValues];


plotPairs={};
For [ii=0, ii<Length[freqValues], ii++ ,x=ii^2;

  freq=  freqValues[[ii]]; 
transferFuncValues=  transferFunction[[ii+1]]; 
AppendTo[plotPairs,{freq,transferFuncValues}];
Print  [freq*0.9] ;
 Print[x];

] (* End for loop *)
 ListLogLogPlot[plotPairs,Joined->True]


(* Formulas from Ardalan, et al. 1988     *)


Print ["Done!"]

|