(*                                                                           *)
(*  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                                                 *)

(* Theoretical Computation of Near End Cross Talk using                      *)
(* Formulas  In:                                                             *)
(* 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                                                             *)

(* Following Formulas from [Hill, 1984]                             *)
(* Theoretical Computation of Near End Cross Talk S13               *)

(* Start Code                                                     *)

(* Inductance and Capacitance Matrix from                      *)
(* Multiconductor Microstrip Per Unit Parameters               *)
(* Computed Using Mathematica Code by Ardalan Translated from  *)(* Fortran code by  Clayton Paul                               *)
(*                                                             *)
(* See http://www.radiocalc.com for details.                   *)






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}};

L=0.196;  (* Length Meters   *)
Z0=Sqrt[LL[[1,1]]/(Cap[[1,1]])]
Print ["Z0=",Z0];
Clear[transferFunction];
transferFunction={};

PointsN=200
deltaF=50*10^6
freqStart=100*10^6
freq=freqStart
For[ii=0, ii<PointsN, ii++,
Print["freq=",freq];     
w=2*Pi*freq;
gamma0=I*w*Sqrt[(LL[[1,1]]*Cap[[1,1]])];

 Zev=Sqrt[(LL[[1,1]]+LL[[1,2]])/(Cap[[1,1]]+Cap[[1,2]])];
Zodd=Sqrt[(LL[[1,1]]-LL[[1,2]])/(Cap[[1,1]]-Cap[[1,2]])];
                                   Print["Zev=",Zev];
                                  Print["Zodd=",Zodd];
delZ=(Zev-Zodd)/2;
 Print["delZ=",delZ];



delk=w*(LL[[1,2]]+  Cap[[1,2]] *Z0*Z0)/(2*Z0);

Print["delZ=",delZ];
Print["delk=",delk];
              argTrig=2*delk*L;
              cosTerm=Cos[argTrig];
              sinTerm=Sin[argTrig];
Print["cosTerm=",cosTerm];
Print["sinTerm=",sinTerm];

         S31=(delZ/(2*Z0))*(1-(E^(-2*gamma0*L))*(cosTerm+(delZ/Z0)*sinTerm));
        Print["S31=",S31];

AppendTo[transferFunction,Abs[S31]]; 
freq=freq+deltaF;


]
Print[transferFunction];
freq=freqStart
plotPairs={};
For [ii=0, ii<PointsN, ii++ , 

  
transferFuncValues=  transferFunction[[ii]]; 
AppendTo[plotPairs,{freq,transferFuncValues}];
 freq=  freq+deltaF; 
 

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