├── BraggGratingSolvers ├── Bragg Grating ODE │ ├── Reproduction of fig 5.jpg │ ├── boundaryProblem.m │ ├── bounds.m │ ├── odeSolver.m │ └── odeSystem.m └── Bragg Grating Transfer Matrix Solver │ ├── FDTDUPMLandBragg1DusesMultilayer.m │ ├── FDTDUPMLandBragg1DusesMultilayer2.m │ ├── FDTDUPMLandBragg1DusesMultilayerAnyL.m │ ├── gain.m │ ├── gainFun.m │ ├── gainOptim.m │ ├── gainOptimizerMfile.m │ ├── multiLayer.m │ ├── multidiel.m │ ├── multilayer2.m │ ├── n2r.m │ ├── refl.fig │ ├── toolBox │ ├── Ci.m │ ├── Cin.m │ ├── Gi.m │ ├── I0.m │ ├── Si.m │ ├── ab.m │ ├── abadd.m │ ├── abadd2.m │ ├── abp.m │ ├── abp2.m │ ├── abz.m │ ├── abz2.m │ ├── addbwp.m │ ├── addbwz.m │ ├── addcirc.m │ ├── addline.m │ ├── addray.m │ ├── array.m │ ├── asinhc.m │ ├── binomial.m │ ├── bkwrec.m │ ├── blockmat.m │ ├── brewster.m │ ├── bwidth.m │ ├── c2p.m │ ├── chebarray.m │ ├── chebtr.m │ ├── chebtr2.m │ ├── chebtr3.m │ ├── circint.m │ ├── circtan.m │ ├── contents.m │ ├── d2r.m │ ├── db.m │ ├── dbadd.m │ ├── dbadd2.m │ ├── dbp.m │ ├── dbp2.m │ ├── dbz.m │ ├── dbz2.m │ ├── dguide.m │ ├── diffint.m │ ├── diffr.m │ ├── dipdir.m │ ├── dipole.m │ ├── dmax.m │ ├── dnv.m │ ├── dolph.m │ ├── dolph2.m │ ├── dolph3.m │ ├── dsinc.m │ ├── dslab.m │ ├── dtft.m │ ├── dualband.m │ ├── dualbw.m │ ├── ellipE.m │ ├── ellipK.m │ ├── ellipse.m │ ├── etac.m │ ├── ewa_license.m │ ├── fcs.m │ ├── fcs2.m │ ├── flip.m │ ├── fresnel.m │ ├── frwrec.m │ ├── g2z.m │ ├── gain1d.m │ ├── gain2d.m │ ├── gain2s.m │ ├── gin.m │ ├── gout.m │ ├── gprop.m │ ├── hband.m │ ├── hbasis.m │ ├── hcoupled.m │ ├── hcoupled2.m │ ├── hdelta.m │ ├── heff.m │ ├── hfield.m │ ├── hgain.m │ ├── hmat.m │ ├── hopt.m │ ├── hsigma.m │ ├── hwrap.m │ ├── imped.m │ ├── imped2.m │ ├── impedmat.m │ ├── kernel.m │ ├── king.m │ ├── kingeval.m │ ├── kingfit.m │ ├── kingprime.m │ ├── landenv.m │ ├── lmatch.m │ ├── lmin.m │ ├── movies │ │ ├── RLCmovie.m │ │ ├── TDRmovie.m │ │ ├── dipmovie.m │ │ ├── grv1frame.mat │ │ ├── grv2frame.mat │ │ ├── grvmovie1.m │ │ ├── grvmovie2.m │ │ ├── pulse2movie.m │ │ ├── pulsemovie.m │ │ └── xtalkmovie.m │ ├── mstripa.m │ ├── mstripr.m │ ├── mstrips.m │ ├── multibeam.m │ ├── multidiel.m │ ├── multidiel1.m │ ├── multidiel2.m │ ├── multiline.m │ ├── n2r.m │ ├── nfcirc.m │ ├── nfig.m │ ├── omniband.m │ ├── omniband2.m │ ├── onesect.m │ ├── p2c.m │ ├── pfield.m │ ├── pi2t.m │ ├── pmat.m │ ├── pmatch.m │ ├── poly2.m │ ├── prol.m │ ├── prolmat.m │ ├── quadr.m │ ├── quadr2.m │ ├── quadrs.m │ ├── quadrs2.m │ ├── qwt1.m │ ├── qwt2.m │ ├── qwt3.m │ ├── r2d.m │ ├── r2n.m │ ├── resonant.m │ ├── rhombic.m │ ├── scan.m │ ├── sector.m │ ├── sgain.m │ ├── sgcirc.m │ ├── sinhc.m │ ├── smat.m │ ├── smatch.m │ ├── smith.m │ ├── smithcir.m │ ├── snel.m │ ├── snv.m │ ├── sparam.m │ ├── sqrte.m │ ├── steer.m │ ├── stub1.m │ ├── stub2.m │ ├── stub3.m │ ├── swr.m │ ├── t2pi.m │ ├── taylor1p.m │ ├── taylorbw.m │ ├── taylornb.m │ ├── traveling.m │ ├── tsection.m │ ├── twosect.m │ ├── uniform.m │ ├── upulse.m │ ├── ustep.m │ ├── vee.m │ ├── ville.m │ ├── vprop.m │ ├── wavenum.m │ ├── woodward.m │ ├── yagi.m │ ├── z2g.m │ └── zprop.m │ ├── transferMatrix.m │ ├── transferMatrix2.m │ ├── transferMatrixSolver.m │ ├── transferSim.m │ └── transferSimGainOptimizer.m ├── Coupled1D-SchodingerNewtonMaxwell ├── coupled_schordinger_newton_maxwell_v5.m ├── gramSchmidt.m ├── ground.m ├── nlsSimple.m ├── splineDerivative.m ├── systemEnergy.m └── tridisolve.m ├── CppVersions ├── 2012-07-02-2D_AXISYMMETRIC_FDTD │ ├── 1D_FDTD.cpp │ ├── 2D_AXISYMMETRIC_FDTD.cpp │ ├── FDTDsettings.txt │ ├── ReadMe.txt │ ├── config.cc │ └── config.h ├── 2013-03-05-3D_FDTD │ ├── 3D_FDTD.cpp │ ├── 3D_FDTD.h │ ├── config.cc │ ├── config.h │ ├── destructor.cpp │ ├── functions.cpp │ ├── initializer.cpp │ ├── mathFunctions.cpp │ ├── model.h │ ├── settings.txt │ └── utilityFunctions.cpp ├── 2013-05-15-SchrodingerNewtonMaxwell │ ├── PSI.bin │ ├── RN.bin │ ├── SNM.cpp │ ├── SNM.h │ ├── config.cc │ ├── config.h │ ├── domain.bin │ ├── fdtd.bin │ ├── functions.cpp │ ├── ground │ ├── groundVideo.bin │ ├── ionVid.bin │ ├── mathFunctions.cpp │ ├── model.h │ ├── modelDestructor.cpp │ ├── modelFunctions.cpp │ ├── modelInitializer.cpp │ ├── new.bin │ ├── newIon.bin │ ├── psiVid.bin │ ├── rho.bin │ ├── rhoVid.bin │ ├── settings.txt │ ├── temp.bin │ ├── temp2.bin │ ├── utilityFunctions.cpp │ ├── video.bin │ └── videoIon.bin └── 2013-06-13-SchrodingerNewtonMaxwell-RK4Update │ ├── 3D Data Conv │ ├── D2imp.m │ ├── SN_1D_IMP.m │ └── SN_3D_IMP.m │ ├── SN_3D.cpp │ ├── SN_3D.h │ ├── classDef.h │ ├── classFunctions.cpp │ ├── config.cc │ ├── config.h │ ├── finiteDifference.cpp │ ├── finiteDifference.h │ ├── functions.cpp │ ├── mathFunctions.cpp │ ├── model.h │ ├── modelDestructor.cpp │ ├── settings.txt │ ├── test1D.cpp │ └── utility.cpp ├── FDTD_1D ├── FDTD_1D.m ├── FDTD_1D_2level_atom.m ├── FDTD_1D_inhomogeneous_absorption.m └── OtherVersions │ ├── FDTDGainMed1DGratingSimulation.m │ ├── FDTDLossyMed1DMay21Update.m │ ├── FDTDLossyMed1DMurBoundary.m │ ├── FDTDLossyMed1DWaveletLorentz.m │ ├── FDTDLossyMed1DWaveletSimulation2.m │ ├── FDTDUPMLandBragg1D.m │ └── FDTDUPMLorentz.m ├── FDTD_2D ├── FDTDGaussPulse2DMay17Update.m ├── FDTDGaussPulse2DMay21Update.m ├── FDTD_2D_Cylindrical_Axisymmetric.m └── colorScheme.m ├── FDTD_3D ├── FDTD_3D_Cartesian.m ├── FDTD_3D_Cylindrical.m ├── FDTD_3D_Cylindrical_forced_solution_convergence_check.m └── colorSchemes.m ├── NonlinearSchrodingerSolver1DFD ├── HarmonicOscillator_RungeKuttaFFT.m ├── MultipleWaveFunctions_CrankNicolson_StrangSplitting.m ├── NonlinearSystem_CrankNicolson_StrangSplitting.m ├── convolutionTest.m └── nls.m ├── README.md ├── VECSEL-GA-Optimizer ├── 2nd Transfer Matrix Optimizer │ ├── FDTD Tester │ │ ├── FDTDUPMLandBragg1DusesMultilayerAnyL.m │ │ ├── newData.mat │ │ ├── newData2.mat │ │ ├── newData3.mat │ │ └── transferMatrix.m │ ├── Optimize Gain Sections │ │ ├── TROptim.m │ │ ├── TROptimSum.m │ │ ├── consFun.m │ │ ├── displayResults.m │ │ ├── gainFun.m │ │ ├── gainOptim.m │ │ ├── gainOptimSum.m │ │ ├── gainOptimizerMfile.m │ │ ├── matlab.mat │ │ ├── reOptimize.m │ │ ├── storage.mat │ │ ├── transOptim.m │ │ ├── transferMatrix.m │ │ └── transferMatrixOne.m │ ├── Optimize Gain in an interval │ │ ├── consFun.m │ │ ├── displayResults.m │ │ ├── gainFun.m │ │ ├── gainOptim.m │ │ ├── gainOptimizerMfile.m │ │ ├── phaseOptim.m │ │ ├── phaseOptimizerMfile.m │ │ ├── phaseOptimizerMfile.mat │ │ ├── reOptimize.m │ │ ├── storage.mat │ │ ├── transferMatrix.m │ │ └── transferMatrixOne.m │ ├── Optimize Gain │ │ ├── consFun.m │ │ ├── displayResults.m │ │ ├── gainFun.m │ │ ├── gainOptim.m │ │ ├── gainOptimL.m │ │ ├── gainOptimizerMfile.m │ │ ├── gainOptimizerMfile24well.m │ │ ├── gainOptimizerMfileMini.m │ │ ├── gainOptimizerMfileMini2.m │ │ ├── gainOptimizerMfileNew.m │ │ ├── gainSensitivityAnalysis.m │ │ ├── hs_err_pid4336.log │ │ ├── hs_err_pid516.log │ │ ├── matlab.mat │ │ ├── newData.mat │ │ ├── newData2.mat │ │ ├── newData3.mat │ │ ├── newStorage.mat │ │ ├── reOptimize.m │ │ ├── transferMatrix.m │ │ ├── transferMatrixOne.m │ │ └── weekendRun.mat │ ├── Optimize Group Delay │ │ ├── consFun.m │ │ ├── displayResults.m │ │ ├── gainFun.m │ │ ├── gainOptim.m │ │ ├── hs_err_pid2844.log │ │ ├── phaseOptim.m │ │ ├── phaseOptimizerMfile.m │ │ ├── phaseOptimizerMfile.mat │ │ ├── reOptimize.m │ │ ├── storage.mat │ │ ├── transferMatrix.m │ │ └── transferMatrixOne.m │ └── Optimize phase and gain │ │ ├── [a b] = gainFunNew(L).mat │ │ ├── consFun.m │ │ ├── displayResults.m │ │ ├── gainFun.m │ │ ├── gainOptim.m │ │ ├── optJun11.mat │ │ ├── phaseOptim.m │ │ ├── phaseOptimOne.m │ │ ├── phaseOptimizerMfile.m │ │ ├── reOptimize.m │ │ ├── s.mat │ │ ├── storage.mat │ │ ├── storage2.mat │ │ ├── transferMatrix.m │ │ └── transferMatrixOne.m └── Transfer Matrix Gain Optimizer │ ├── FDTDUPMLandBragg1DusesMultilayerAnyL.m │ ├── consFun.m │ ├── finTunegainOptimizerMfile.m │ ├── gainFun.m │ ├── gainOptim.m │ ├── gainOptimizerMfile.m │ ├── gainSensitivityAnalysis.m │ ├── perturbations.fig │ ├── transferMatrix.m │ └── transferMatrixOne.m └── license.txt /BraggGratingSolvers/Bragg Grating ODE/Reproduction of fig 5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/BraggGratingSolvers/Bragg Grating ODE/Reproduction of fig 5.jpg -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating ODE/boundaryProblem.m: -------------------------------------------------------------------------------- 1 | close all; 2 | clear all; 3 | 4 | N = 10000; 5 | L = 2*10^-3; 6 | kappa = 8/L; 7 | sigma = (20:-.2:-20)/L; 8 | rho = zeros(1,length(sigma)); 9 | options = odeset('RelTol',1e-4,'AbsTol',1e-4); 10 | 11 | % sigmahat*L is between -20 and 20; 12 | % kappa*L = 8; 13 | 14 | 15 | for n = 1:length(sigma); 16 | 17 | meshSize = L/100; 18 | domain = bvpinit(0:meshSize:L,[1, .5]); 19 | sol = bvp4c(@(T,Y)odeSystem(T,Y,kappa,sigma(n)), @bounds, domain, options); 20 | 21 | y1Initial = sol.y(1,1); 22 | y2Initial = sol.y(2,1); 23 | 24 | y1Sltn = y1Initial; 25 | y2Sltn = y2Initial; 26 | 27 | rho(n) = y2Sltn/y1Sltn; 28 | 29 | end 30 | 31 | r = abs(rho).^2; 32 | normalWave = 1./(1+(sigma.*L)/(pi*N)); 33 | 34 | plot(normalWave, r) 35 | 36 | %%% Plots %%% 37 | % figure 38 | % set(1,'outerposition', [1500 200 900 800]) 39 | % 40 | % subplot(2,1,1) 41 | % plot(sol.x, sol.y(1,:), sol.x, sol.y(2,:)) 42 | % legend('R','S') 43 | % 44 | % subplot(2,1,2) 45 | % plot(sol.x, sol.yp(1,:), sol.x, sol.yp(2,:)) 46 | % legend('Rprime','Sprime') 47 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating ODE/bounds.m: -------------------------------------------------------------------------------- 1 | function [ res ] = bounds( y0, y1 ) 2 | %BOUNDS Evaluates residues 3 | 4 | res = [y0(1)-1; y1(2)]; 5 | 6 | end 7 | 8 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating ODE/odeSolver.m: -------------------------------------------------------------------------------- 1 | close all; 2 | clear all; 3 | 4 | options = odeset('RelTol',1e-6,'AbsTol',1e-8); 5 | 6 | L = 4*10^-3; 7 | 8 | 9 | Rinit = 1; % Initial R value 10 | Sinit = -0.1030 + 0.9193i; % Initial S value 11 | L = 4*10^-3; % Final z value 12 | 13 | [T,Y] = ode45(@odeSystem,[0 L],[Rinit Sinit],options); 14 | 15 | 16 | 17 | %%% Plots %%% 18 | figure 19 | set(1,'outerposition', [1500 200 900 800]) 20 | 21 | subplot(2,1,1) 22 | plot(T, Y(:,1)) 23 | title('R') 24 | 25 | subplot(2,1,2) 26 | plot(T, Y(:,2)) 27 | title('S') 28 | 29 | % figure 30 | % subplot(2,1,1) 31 | % plot(T, imag(Y(:,1))) 32 | % title('Im R') 33 | % 34 | % subplot(2,1,2) 35 | % plot(T, imag(Y(:,2))) 36 | % title('Im S') -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating ODE/odeSystem.m: -------------------------------------------------------------------------------- 1 | function [ dS ] = odeSystem(t, S, kappa, sigma ) 2 | % Function of two simple ODE's. 3 | 4 | % S(1) = R S(2) = S 5 | % dS(1) = dR/dz dS(2) = dS/dz 6 | 7 | 8 | dS = zeros(2,1); 9 | dS(1) = sigma*i*S(1) + kappa*i*S(2); 10 | dS(2) = -sigma*i*S(2) - kappa*i*S(1); 11 | 12 | % dS = -i*S; 13 | 14 | end 15 | 16 | %% 17 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/multiLayer.m: -------------------------------------------------------------------------------- 1 | function [ la, Gla, r ] = multiLayer(la0, lambdaMin, lambdaMax, lambdaSteps, nH, nL, N) 2 | %MULTILAYER Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | 6 | na = 1; 7 | nb = 1; % refractive indices 8 | LH = 0.25; LL = 0.25; % optical thicknesses in units of λ0 9 | 10 | la0; % λ0 in units of nm 11 | rho = (nH-nL)/(nH+nL); % reflection coefficient ρ 12 | la2 = pi*(LL+LH)*1/acos(rho) * la0; % Right bandedge 13 | la1 = pi*(LL+LH)*1/acos(-rho) * la0; % left bandedge 14 | Dla = la2-la1; % bandwidth 15 | 16 | N; 17 | n = [na, nH, repmat([nL,nH], 1, N), nb]; % indices for the layers A|H(LH)N |G 18 | L = [LH, repmat([LL,LH], 1, N)]; % Lengths of layers 19 | la = linspace(lambdaMin,lambdaMax,lambdaSteps); % plotting range is 300 ≤ λ ≤ 800 nm 20 | r = multidiel(n,L,la/la0); 21 | Gla = 100*abs(r).^2; 22 | 23 | % 24 | % figure; plot(la,Gla); 25 | % f = linspace(0,6,1201); 26 | % Gf = 100*abs(multidiel(n,L,1./f)).^2; 27 | % figure; plot(f,Gf); 28 | 29 | end 30 | 31 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/multilayer2.m: -------------------------------------------------------------------------------- 1 | na = 1; nb = 1.52; nH = 2.32; nL = 1.00; % refractive indices 2 | LH = 0.25; LL = 0.25; % optical thicknesses in units of λ0 3 | 4 | 5 | la0 = 500; % λ0 in units of nm 6 | rho = (nH-nL)/(nH+nL); % reflection coefficient ρ 7 | la2 = pi*(LL+LH)*1/acos(rho) * la0; % Right bandedge 8 | la1 = pi*(LL+LH)*1/acos(-rho) * la0; % left bandedge 9 | Dla = la2-la1; % bandwidth 10 | 11 | N = 8; 12 | n = [na, nH, repmat([nL,nH], 1, N), nb]; % indices for the layers A|H(LH)N |G 13 | L = [LH, repmat([LL,LH], 1, N)]; % Lengths of layers 14 | la = linspace(300,800,501); % plotting range is 300 ≤ λ ≤ 800 nm 15 | Gla = 100*abs(multidiel(n,L,la/la0)).^2; 16 | 17 | 18 | figure; plot(la,Gla); 19 | f = linspace(0,6,1201); 20 | Gf = 100*abs(multidiel(n,L,1./f)).^2; 21 | figure; plot(f,Gf); 22 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/n2r.m: -------------------------------------------------------------------------------- 1 | % n2r.m - refractive indices to reflection coefficients of M-layer structure 2 | % 3 | % Usage: r = n2r(n) 4 | % 5 | % n = refractive indices = [na,n(1),...,n(M),nb] 6 | % r = reflection coefficients = [r(1),...,r(M+1)] 7 | % 8 | % notes: there are M layers, M+1 interfaces, and M+2 media 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function r = n2r(n) 13 | 14 | if nargin==0, help n2r; return; end 15 | 16 | r = -diff(n) ./ (2*n(1:end-1) + diff(n)); 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/refl.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/refl.fig -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/Ci.m: -------------------------------------------------------------------------------- 1 | % Ci.m - cosine integral Ci(z) 2 | % 3 | % Usage: y = Ci(z) 4 | % 5 | % notes: Ci(z) = gamma + log(z) + \int_0^z (cos(t)-1)/t dt 6 | % Ci(z) = Ci(-z) + i*pi, for z<0 7 | % 8 | % Notes: implemented using expint 9 | % 10 | % see also Si, Cin, Gi 11 | 12 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function y = Ci(z) 15 | 16 | if nargin==0, help Ci; return; end 17 | 18 | y = zeros(size(z)); 19 | 20 | i0 = find(z==0); 21 | i1 = find(z>0); z1 = z(i1); 22 | i2 = find(z<0); z2 = z(i2); 23 | 24 | y(i0) = -Inf; 25 | y(i1) = -(expint(j*z1) + expint(-j*z1))/2; 26 | y(i2) = -(expint(-j*z2) + expint(j*z2))/2 + i*pi; 27 | 28 | 29 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/Cin.m: -------------------------------------------------------------------------------- 1 | % Cin.m - cosine integral Cin 2 | % 3 | % Usage: y = Cin(z) 4 | % 5 | % z = any vector of real numbers 6 | % 7 | % Notes: Cin(z) = \int_0^z (1-cos(t))/t dt 8 | % 9 | % evaluated in terms of Ci(z) using the relationship: 10 | % 11 | % Cin(z) = gamma + log(z) - Ci(z), 12 | % gamma = Euler constant = 0.57721566490153286... 13 | % 14 | % see also Ci, Si, Gi, expint 15 | 16 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function y = Cin(z) 19 | 20 | if nargin==0, help Cin; return; end 21 | 22 | gamma = 0.5772156649; 23 | 24 | y = gamma + log(z) - Ci(z); 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/Gi.m: -------------------------------------------------------------------------------- 1 | % Gi.m - Green's function integral 2 | % 3 | % Usage: J = Gi(d,z0,h,s) 4 | % 5 | % d = distance between parallel z-axes 6 | % z0 = relative displacement along z-axis 7 | % s = +1,-1, for the factor exp(-j*k*s*z) 8 | % h = antenna half-length defines integration range [0,h] 9 | % 10 | % J = value of the integral \int_0^h exp(-j*k*R)/R * exp(-j*k*s*z) dz, 11 | % where R = sqrt(d^2 + (z-z0)^2) 12 | % 13 | % notes: J(d,z0,h,+1) = \int_0^h exp(-j*k*(R+z))/R dz 14 | % J(d,z0,h,-1) = \int_0^h exp(-j*k*(R-z))/R dz 15 | % 16 | % z0,s can be vectors of the same dimension, resulting in a vector of J's 17 | % 18 | % implemented using expint 19 | % 20 | % see also Ci, Cin, Si 21 | % used by imped2 to calculate mutual impedances 22 | 23 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 24 | 25 | function J = Gi(d,z0,h,s) 26 | 27 | if nargin==0, help Gi; return; end 28 | 29 | k = 2*pi; 30 | 31 | v0 = k*(sqrt(d^2 + z0.^2) - s.*z0); 32 | v1 = k*(sqrt(d^2 + (h-z0).^2) + s.*(h-z0)); 33 | 34 | J = s .* exp(-j*k*s.*z0) .* (expint(j*v0) - expint(j*v1)); 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/I0.m: -------------------------------------------------------------------------------- 1 | % I0.m - modified Bessel function of 1st kind and 0th order. 2 | % 3 | % Usage: y = I0(x) 4 | % 5 | % defined only for scalar x >= 0 6 | % 7 | % used by KWIND to calculate Kaiser window, 8 | % based on the I2SP C function I0.c 9 | 10 | % S. J. Orfanidis - 1995 11 | % www.ece.rutgers.edu/~orfanidi/intro2sp 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function y = I0(x) 15 | 16 | if nargin==0, help I0; return; end 17 | 18 | epsilon = 10^(-9); 19 | n=1; y=1; D=1; 20 | 21 | while D > (epsilon * y), 22 | T = x / (2*n); 23 | n = n+1; 24 | D = D * T^2; 25 | y = y + D; 26 | end 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/Si.m: -------------------------------------------------------------------------------- 1 | % Si.m - sine integral Si(z) 2 | % 3 | % Usage: y = Si(z) 4 | % 5 | % z = vector of real values 6 | % y = same size as z 7 | % 8 | % notes: Si(z) = \int_0^z sin(t)/t dt 9 | % Si(-z) = -Si(z) 10 | % 11 | % Notes: implemented using expint 12 | % 13 | % see also Ci, Cin, Gi 14 | 15 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 16 | 17 | function y = Si(z) 18 | 19 | if nargin==0, help Si; return; end 20 | 21 | y = zeros(size(z)); % note also that Si(0) = 0 22 | 23 | i1 = find(z>0); z1 = z(i1); 24 | i2 = find(z<0); z2 = z(i2); 25 | 26 | y(i1) = (expint(j*z1) - expint(-j*z1))/2/j + pi/2; 27 | y(i2) = -(expint(-j*z2) - expint(j*z2))/2/j - pi/2; 28 | 29 | 30 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/ab.m: -------------------------------------------------------------------------------- 1 | % ab.m - dB to absolute units 2 | % 3 | % Usage: Gab = ab(Gdb) 4 | % 5 | % Gdb = power gain in dB 6 | % Gab = power gain in absolute units, Gab = 10^(Gdb/10) 7 | % 8 | % see also Gdb = db(Gab) for the reverse operation 9 | 10 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function Gab = ab(Gdb) 13 | 14 | if nargin==0, help ab; return; end 15 | 16 | Gab = 10.^(Gdb/10); 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/abadd.m: -------------------------------------------------------------------------------- 1 | % abadd.m - add gain in absolute units 2 | % 3 | % Usage: h = abadd(type, style, th, g, rays, width) 4 | % 5 | % type = 1,2 for polar, azimuthal 6 | % style = line style of added gain curve, e.g., '--r' 7 | % 8 | % rest of arguments as in ABPOL and ABZ 9 | % 10 | % use h to add legends: h1 = abz(phi, g1); 11 | % h2 = abadd(2, '--', phi, g2); 12 | % legend([h1,h2], 'gain 1', 'gain 2'); 13 | 14 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function h = abadd(type, style, th, g, rays, width) 17 | 18 | if nargin==0, help abadd; return; end 19 | if nargin<5, rays = 30; end 20 | if nargin<6, width = 1; end 21 | 22 | if type == 1, 23 | x = g .* sin(th); % polar plot 24 | y = g .* cos(th); 25 | h = plot(x, y, style, 'LineWidth', width); 26 | hold on; 27 | plot(-x, y, style, 'LineWidth', width); 28 | else 29 | x = g .* cos(th); % azimuthal plot 30 | y = g .* sin(th); 31 | h = plot(x, y, style, 'LineWidth', width); 32 | hold on; 33 | plot(x, -y, style, 'LineWidth', width); 34 | end 35 | 36 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/abadd2.m: -------------------------------------------------------------------------------- 1 | % abadd2.m - add gain in absolute units - 2pi angle range 2 | % 3 | % Usage: h = abadd2(type, style, th, g, rays, width) 4 | % 5 | % type = 1,2 for polar, azimuthal 6 | % style = line style of added gain curve, e.g., '--r' 7 | % 8 | % rest of arguments as in ABPOL and ABZ 9 | % 10 | % use h to add legends: h1 = abz(phi, g1); 11 | % h2 = abadd2(2, '--', phi, g2); 12 | % legend([h1,h2], 'gain 1', 'gain 2'); 13 | 14 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function h = abadd2(type, style, th, g, rays, width) 17 | 18 | if nargin==0, help abadd2; return; end 19 | if nargin<5, rays = 30; end 20 | if nargin<6, width = 1; end 21 | 22 | if type == 1, 23 | x = g .* sin(th); % polar plot 24 | y = g .* cos(th); 25 | h = plot(x, y, style, 'LineWidth', width); 26 | else 27 | x = g .* cos(th); % azimuthal plot 28 | y = g .* sin(th); 29 | h = plot(x, y, style, 'LineWidth', width); 30 | end 31 | 32 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/addbwp.m: -------------------------------------------------------------------------------- 1 | % addbwp.m - add 3-dB angle width in polar plots 2 | % 3 | % Usage: addbwp(Dth, style) 4 | % addbwp(Dth) (equivalent to style = '--') 5 | % 6 | % Dth = desired polar angle in degrees 7 | % style = linestyle, e.g., '--' 8 | % 9 | % see also ADDCIRC, ADDLINE 10 | 11 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function addbwp(Dth, style) 14 | 15 | if nargin==0, help addbwp; return; end 16 | if nargin==1, style = '--'; end 17 | 18 | addray(90-Dth/2,style); 19 | addray(90+Dth/2,style); 20 | 21 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/addbwz.m: -------------------------------------------------------------------------------- 1 | % addbwz.m - add 3-dB angle width in azimuthal plots 2 | % 3 | % Usage: addbwz(Dphi, style) 4 | % addbwz(Dphi) (equivalent to style = '--') 5 | % 6 | % Dphi = desired azimuthal angle in degrees 7 | % style = linestyle, e.g., '--' 8 | % 9 | % see also ADDCIRC, ADDLINE 10 | 11 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function addbwz(Dphi, style) 14 | 15 | if nargin==0, help addbwz; return; end 16 | if nargin==1, style = '--'; end 17 | 18 | addray(-Dphi/2,style); 19 | addray(Dphi/2,style); 20 | 21 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/addcirc.m: -------------------------------------------------------------------------------- 1 | % addcirc.m - add grid circle in polar or azimuthal plots 2 | % 3 | % Usage: addcirc(R, Rm, style) 4 | % addcirc(R, Rm) (equivalent to style='--') 5 | % addcirc(R) (equivalent to Rm=40, style='--') 6 | % 7 | % R = radius (R<1 in absolute units) 8 | % Rm = minimum dB level, 9 | % for dB units use Rm>0, 10 | % for absolute units use Rm=0 11 | % style = linestyle, e.g., '--' 12 | % 13 | % Rm must have the same value as that used in the main DBZ or DBP plot 14 | % 15 | % examples: addcirc(0.7, 0) dashed circle of radius R=0.7 in absolute units 16 | % addcirc(0.7, 0, '-r') radius R=0.7, absolute units, red solid line 17 | % addcirc(30, 40) 30-dB dashed circle with Rm=40 18 | % addcirc(30, 60, '-') 30-dB solid-line circle with Rm=60 19 | % 20 | % see also ADDRAY, ADDLINE 21 | 22 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 23 | 24 | function addcirc(R, Rm, style) 25 | 26 | if nargin==0, help addcirc; return; end 27 | if nargin<2, Rm = 40; end 28 | if nargin<3, style = '--'; end 29 | 30 | if Rm>0, 31 | R = (Rm - R)/Rm; 32 | end 33 | 34 | N0 = 400; 35 | th0 = (0:N0) * 2 * pi / N0; 36 | x0 = R * cos(th0); 37 | y0 = R * sin(th0); 38 | 39 | plot(x0, y0, style); 40 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/addline.m: -------------------------------------------------------------------------------- 1 | % addline.m - add grid ray line in azimuthal or polar plots 2 | % 3 | % Usage: addline(phi, style) 4 | % 5 | % phi = desired azimuthal angle in degrees 6 | % style = linestyle, e.g., '--' 7 | % 8 | % see also ADDCIRC, ADDRAY 9 | 10 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function addline(phi, style) 13 | 14 | if nargin==0, help addline; return; end 15 | if nargin==1, style = '--'; end 16 | 17 | x1 = cos(pi*phi/180); 18 | y1 = sin(pi*phi/180); 19 | 20 | line([-x1,x1], [-y1,y1], 'linestyle', style); 21 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/addray.m: -------------------------------------------------------------------------------- 1 | % addray.m - add ray in azimuthal or polar plots 2 | % 3 | % Usage: addray(phi, style) 4 | % addray(phi) (equivalent to style = '--') 5 | % 6 | % phi = desired azimuthal angle in degrees 7 | % style = linestyle, e.g., '--' 8 | % 9 | % see also ADDCIRC, ADDLINE 10 | 11 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function addray(phi, style) 14 | 15 | if nargin==0, help addray; return; end 16 | if nargin==1, style = '--'; end 17 | 18 | x1 = cos(pi*phi/180); 19 | y1 = sin(pi*phi/180); 20 | 21 | line([0,x1], [0,y1], 'linestyle', style); 22 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/array.m: -------------------------------------------------------------------------------- 1 | % gain1d.m - normalized gain computation for 1D equally-spaced isotropic array 2 | % 3 | % Usage: [g, phi] = gain1d(d, a, N); 4 | % 5 | % d = array spacing in units of lambda 6 | % a = row vector of array weights 7 | % N = number of azimuthal angles in [0,pi] (actually, N+1 angles) 8 | % 9 | % g = row vector of gain values evaluated at phi 10 | % phi = row vector of (N+1) equally-spaced angles over [0, pi] (in radians) 11 | % 12 | % notes: computes g(phi) = |A(psi)|^2, where A(psi) = \sum_n a(n)z^n, 13 | % with z = e^(j*psi) and psi = 2*pi*d*cos(phi), 14 | % 15 | % normalizes g to unity maximum, 16 | % [g,phi] can be passed into gain plotting functions DBZ,ABZ 17 | % e.g., dbz(phi,g), abz(phi,g) 18 | % 19 | % to compute the gain of a scanned array use SCAN or STEER first, e.g. 20 | % [g, phi] = gain1d(d, scan(a,psi0), N); 21 | % [g, phi] = gain1d(d, steer(d,a,phi0), N); 22 | % 23 | % uses the I2SP function DTFT 24 | % 25 | % (this function replaces an earlier pre-2005 version called ARRAY) 26 | % 27 | % see also UNIFORM, BINOMIAL, TAYLOR, DOLPH, SECTOR, MULTIBEAM 28 | 29 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 30 | 31 | function [g, phi] = gain1d(d, a, N) 32 | 33 | if nargin==0, help gain1d; return; end 34 | 35 | phi = (0 : N) * pi / N; % equally-spaced over [0,pi] 36 | 37 | psi = 2 * pi * d * cos(phi); 38 | 39 | A = dtft(a, -psi); % array factor, note dsft(a,psi)=dtft(a,-psi) 40 | g = abs(A).^2; % power gain 41 | g = g/max(g); % normalized to unity maximum 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/asinhc.m: -------------------------------------------------------------------------------- 1 | % asinhc.m - inverse hyperbolic sinc function 2 | % 3 | % Usage: [x,err] = asinhc(y) 4 | % 5 | % y = array of real numbers such that y>=1 6 | % 7 | % x = solution of y = sinhc(x) = sinh(pi*x)/(pi*x), same size as y 8 | % err = error defined as norm(y-sinh(pi*x)/(pi*x)) 9 | % 10 | % Notes: both x and -x are solutions 11 | % 12 | % see also sinhc, taylorbw 13 | 14 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function [x,err] = asinhc(y) 17 | 18 | if nargin==0, help asinhc; return; end 19 | 20 | x = zeros(size(y)); 21 | 22 | epsi = 1e-3; 23 | % for y's near y=1, use the approximation, 24 | i0 = find(y-1 <= epsi); % y = sinh(t)/t = 1 + t^2/6 + t^4/120, t small 25 | x(i0) = sqrt(sqrt(100 + 120*(y(i0)-1)) - 10)/pi; % t=pi*x is the solution of 1 + t^2/6 + t^4/120 = y 26 | 27 | i1 = find(y-1 > epsi); 28 | if ~isempty(i1), 29 | y1 = y(i1); 30 | x1 = ones(size(y1)); 31 | xnew = zeros(size(y1)); 32 | 33 | n = 1; % for y's not near y=1, use the iteration, 34 | while 1, % sinh(pi * x(n+1)) = y * pi * x(n), n=0,1,2,.. 35 | xnew = asinh(pi*x1.*y1)/pi; 36 | if norm(xnew-x1) < eps * norm(x1); break; end 37 | x1 = xnew; 38 | n = n+1; 39 | if n>2000; disp('asinhc: failed to converge in 2000 iterations'); return; end 40 | end 41 | 42 | x(i1) = x1; 43 | end 44 | 45 | err = max(abs(y-sinhc(x))); 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/binomial.m: -------------------------------------------------------------------------------- 1 | % binomial.m - binomial array weights 2 | % 3 | % Usage: [a, dph] = binomial(d, ph0, N) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees 7 | % N = number of array elements 8 | % 9 | % a = row vector of array weights (steered toward ph0) 10 | % dph = 3-dB beamwidth in degrees 11 | % 12 | % see also UNIFORM, DOLPH, TAYLOR 13 | 14 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function [a, dph] = binomial(d, ph0, N) 17 | 18 | if nargin==0, help binomial; return; end 19 | 20 | N1 = N - 1; % filter order 21 | 22 | a = 1; 23 | 24 | for i=1:N1, 25 | a = conv(a,[1,1]); % convolve N1-times: [1,1]*[1,1]*...*[1,1] 26 | end 27 | 28 | a = steer(d, a, ph0); % steer toward ph0 29 | 30 | dps = 4 * acos(2^(-0.5/N1)); % 3-dB width in psi-space 31 | 32 | dph = bwidth(d, ph0, dps); % 3-dB width in phi-space 33 | 34 | 35 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/bkwrec.m: -------------------------------------------------------------------------------- 1 | % bkwrec.m - order-decreasing backward layer recursion - from a,b to r 2 | % 3 | % Usage: [r,A,B] = bkwrec(a,b) 4 | % 5 | % a,b = order-M reflection polynomials, M = number of layers 6 | % 7 | % r = reflection coefficients = [r(1),...,r(M+1)] 8 | % A,B = (M+1)x(M+1) matrices whose columns are the reflection polynomials 9 | 10 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function [r,A,B] = bkwrec(a,b) 13 | 14 | if nargin==0, help bkwrec; return; end 15 | 16 | M = length(a)-1; 17 | 18 | A = zeros(M+1,M+1); 19 | B = zeros(M+1,M+1); 20 | 21 | A(:,1) = a(:); 22 | B(:,1) = b(:); 23 | 24 | for i=1:M, 25 | r = B(1,i); 26 | A(1:M+1-i, i+1) = (A(1:M+1-i, i) - r * B(1:M+1-i, i)) / (1 - r^2); 27 | B(1:M+1-i, i+1) = (-r * A(2:M+2-i, i) + B(2:M+2-i, i)) / (1 - r^2); 28 | end 29 | 30 | r = B(1,:); 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/blockmat.m: -------------------------------------------------------------------------------- 1 | % blockmat.m - manipulate block matrices 2 | % 3 | % Usage: Z = blockmat(d1,d2,N,M) create a (d1*N)x(d2*M) matrix of zeros 4 | % A = blockmat(d1,d2,n,m,Z) extract (n,m) submatrix of Z 5 | % Y = blockmat(d1,d2,n,m,Z,A) put A into (n,m) submatrix of Z 6 | % 7 | % notes: Y,Z have d1xd2 subblocks of size NxM each. Initially, Z can be created 8 | % by a call Z = blockmat(d1,d2,N,M) and then fill its d1xd2 submatrices. 9 | % 10 | % A must be NxM and is inserted into or extracted from the (n,m) subblock of Z 11 | % 12 | % the indices (n,m) must be in the ranges 1:d1,1:d2 13 | 14 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | 17 | function Y = blockmat(d1,d2,n,m,Z,A) 18 | 19 | if nargin==0, help blockmat; return; end 20 | 21 | if nargin==4, 22 | Y = zeros(d1*n,d2*m); 23 | end 24 | 25 | if nargin==5, 26 | N = size(Z,1)/d1; 27 | M = size(Z,2)/d2; 28 | Y = Z(1+(n-1)*N : n*N, 1+(m-1)*M : m*M); 29 | end 30 | 31 | if nargin==6, 32 | Y = Z; 33 | N = size(Z,1)/d1; 34 | M = size(Z,2)/d2; 35 | Y(1+(n-1)*N : n*N, 1+(m-1)*M : m*M) = A; 36 | end 37 | 38 | 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/bwidth.m: -------------------------------------------------------------------------------- 1 | % bwidth.m - beamwidth mapping from psi-space to phi-space 2 | % 3 | % Usage: dphi = bwidth(d, ph0, dpsi) 4 | % 5 | % d = array spacing in units of lambda 6 | % ph0 = beam steering angle in degrees 7 | % dpsi = beamwidth in psi-space (in radians) 8 | % 9 | % dphi = beamwidth in degrees 10 | % 11 | % notes: uses the transformation dpsi=2*pi*d*sin(ph0)*dphi, which follows 12 | % from differentiating psi=2*pi*d*(cos(phi) - cos(phi0)), 13 | % usually, dpsi inpuit is calculated from dpsi=b*0.886*2*pi/N 14 | % where b is the broadening factor depending on the window design method 15 | 16 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function dphi = bwidth(d, ph0, dpsi) 19 | 20 | if nargin==0, help bwidth; return; end 21 | 22 | ph0 = ph0 * pi / 180; 23 | 24 | if abs(sin(ph0)) < eps, 25 | dphi = sqrt(2*dpsi / (pi*d)); % endfire 26 | else 27 | dphi = dpsi / (2 * pi * d * sin(ph0)); % broadside 28 | end 29 | 30 | dphi = dphi * 180 / pi; 31 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/c2p.m: -------------------------------------------------------------------------------- 1 | % c2p.m - complex number to phasor form 2 | % 3 | % Usage: p = c2p(z) 4 | % 5 | % z = vector of complex numbers 6 | % 7 | % p = [abs(z), angle(z)*180/pi] 8 | 9 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 10 | 11 | function p = c2p(z) 12 | 13 | if nargin==0, help c2p; return; end 14 | 15 | p = [abs(z), angle(z)*180/pi]; 16 | 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/chebarray.m: -------------------------------------------------------------------------------- 1 | function coefs = chebarray(M, sldb) 2 | %CHEBARRAY Compute chebyshev excitation coefficients for a linear array. 3 | % 4 | % Calling sequence: coefs = chebarray(M, sldb) 5 | % 6 | % Input arguments: 7 | % M The number of elements in the array. 8 | % sldb The sidelobe level in dB. Note sldb > 0. 9 | % 10 | % Output arguments: 11 | % coefs A vector of length M containing the real excitation 12 | % coefficients of the array. They are normalized so that the end 13 | % elements' excitation is unity. 14 | % 15 | 16 | % Language: Matlab 6.x 17 | % Author: Peter S. Simon 18 | % Date: 12/21/2003 19 | % Reference: A. D. Bresler, "A new algorithm for calculating the current 20 | % distributions of Dolph-Chebyshev arrays," IEEE Trans. 21 | % Antennas Propagat., vol. AP-28, no. 6, November 1980. 22 | % 23 | % Copyright 2003 Peter S. Simon, peter_simon@ieee.org 24 | % This routine may be used by anyone for any purpose. I simply ask 25 | % that acknowledgement be made to me. 26 | 27 | 28 | if (sldb <= 0) 29 | error('sldb must be positive!') 30 | end 31 | 32 | N = floor(M/2); 33 | Meven = (M == 2*N); % True if even # elements in array. 34 | sigma = 10^(sldb/20); % Side lobe level as a voltage ratio. 35 | Q = acosh(sigma); 36 | beta = (cosh(Q/(M-1)))^2; 37 | alpha = 1 - 1/beta; 38 | if Meven 39 | nend = N-1; 40 | I = zeros(1,N); % Storage for half the array coefficients. 41 | else 42 | nend = N; 43 | I = zeros(1,N+1); % Storage for half the array coefficients. 44 | end 45 | I(1) = 1; 46 | 47 | for n = 1:nend 48 | np = 1; 49 | for m = 1:(n-1) 50 | f_m = m * (M-1-2*n + m) / ((n-m) * (n+1-m)); 51 | np = np * alpha * f_m + 1; 52 | end 53 | I(n+1) = (M-1)*alpha * np; 54 | end 55 | 56 | if Meven 57 | coefs = [I fliplr(I)]; 58 | else 59 | coefs = [I(1:end-1) fliplr(I)]; 60 | end 61 | 62 | return 63 | 64 | 65 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/circint.m: -------------------------------------------------------------------------------- 1 | % circint.m - circle intersection on Gamma-plane 2 | % 3 | % Usage: Gamma = circint(c1,r1,c2,r2) 4 | % 5 | % c1,r1 = center and radius of circle 1 6 | % c2,r2 = center and radius of circle 2 7 | % 8 | % Gamma = point of intersection of the two circles (two points) 9 | 10 | % Sophocles J. Orfanidis - 1997-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function Gamma = circint(c1,r1,c2,r2) 13 | 14 | if nargin==0, help circint; return; end 15 | 16 | th = acos((r1^2 + r2^2 - abs(c1-c2)^2)/(2*r1*r2)) * [1; -1]; % th = ph2-phi1 17 | 18 | if ~isreal(th), 19 | fprintf('\nno intersection exists\n\n'); 20 | return; 21 | end 22 | 23 | z1 = (c2 - c1) ./ (r1 - r2*exp(j*th)); % z1 = exp(j*ph1) 24 | 25 | Gamma = c1 + r1 * z1; 26 | 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/circtan.m: -------------------------------------------------------------------------------- 1 | % circtan.m - point of tangency between the two circles 2 | % 3 | % Usage: [Gamma,r2] = circtan(c1,r1,c2) 4 | % 5 | % c1,r1 = center and radius of circle 1 6 | % c2 = center and of circle 2 7 | % 8 | % Gamma = point of tangency between the two circles 9 | % r2 = radius of circle 2 10 | 11 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function [Gamma,r2] = circtan(c1,r1,c2) 14 | 15 | if nargin==0, help circtan; return; end 16 | 17 | c21 = c2-c1; % vector from c1 to c2 18 | z21 = c21 / abs(c21); % unit vector from c1 to c2 19 | 20 | r2 = abs(r1-abs(c21)); % c2 could be inside or outside the c1,r1 circle 21 | 22 | Gamma = c1 + r1 * z21; 23 | 24 | 25 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/d2r.m: -------------------------------------------------------------------------------- 1 | % d2r.m - degrees to radians 2 | % 3 | % Usage: y = d2r(x) 4 | % 5 | % see also r2d.m 6 | 7 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 8 | 9 | function y=d2r(x) 10 | 11 | if nargin==0, help d2r; return; end 12 | 13 | y = x * pi / 180; 14 | 15 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/db.m: -------------------------------------------------------------------------------- 1 | % db.m - absolute to dB units 2 | % 3 | % Usage: Gdb = db(Gab) 4 | % 5 | % Gab = power gain in absolute units 6 | % Gdb = power gain in dB, Gdb = 10*log10(Gab) 7 | % 8 | % see also Gab = ab(Gdb) for the reverse operation 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function Gdb = db(Gab) 13 | 14 | if nargin==0, help db; return; end 15 | 16 | Gdb = 10*log10(Gab); 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dbadd.m: -------------------------------------------------------------------------------- 1 | % dbadd.m - add gain in dB 2 | % 3 | % Usage: h = dbadd(type, style, th, g, rays, Rm, width) 4 | % 5 | % type = 1, 2 for polar, azimuthal 6 | % style = line style of added gain curve, e.g., '--' 7 | % 8 | % use h to add legends: h1 = dbz(phi, g1); 9 | % h2 = dbadd(2, '--', phi, g2); 10 | % legend([h1,h2], 'gain 1', 'gain 2'); 11 | % 12 | % rest of arguments as in DBP and DBZ 13 | 14 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function h = dbadd(type, style, th, g, rays, Rm, width) 17 | 18 | if nargin==0, help dbadd; return; end 19 | if nargin<5, rays = 30; end 20 | if nargin<6, Rm = 40; end 21 | if nargin<7, width = 1; end 22 | 23 | gdb = g .* (g > eps) + eps * (g <= eps); 24 | gdb = 10 * log10(gdb); 25 | gdb = gdb .* (gdb > -Rm) + (-Rm) * (gdb <= -Rm); 26 | gdb = (gdb + Rm)/Rm; 27 | 28 | if type == 1, % polar plot 29 | x = gdb .* sin(th); 30 | y = gdb .* cos(th); 31 | h = plot(x, y, style, 'LineWidth', width); 32 | hold on; 33 | plot(-x, y, style, 'LineWidth', width); 34 | else % azimuthal plot 35 | x = gdb .* cos(th); 36 | y = gdb .* sin(th); 37 | h = plot(x, y, style, 'LineWidth', width); 38 | hold on; 39 | plot(x, -y, style, 'LineWidth', width); 40 | end 41 | 42 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dbadd2.m: -------------------------------------------------------------------------------- 1 | % dbadd2.m - add gain in dB - 2pi angle range 2 | % 3 | % Usage: h = dbadd2(type, style, th, g, rays, Rm, width) 4 | % 5 | % type = 1, 2 for polar, azimuthal 6 | % style = line style of added gain curve, e.g., '--' 7 | % 8 | % use h to add legends: h1 = dbz(phi, g1); 9 | % h2 = dbadd2(2, '--', phi, g2); 10 | % legend([h1,h2], 'gain 1', 'gain 2'); 11 | % 12 | % rest of arguments as in DBP and DBZ 13 | 14 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function h = dbadd2(type, style, th, g, rays, Rm, width) 17 | 18 | if nargin==0, help dbadd2; return; end 19 | if nargin<5, rays = 30; end 20 | if nargin<6, Rm = 40; end 21 | if nargin<7, width = 1; end 22 | 23 | gdb = g .* (g > eps) + eps * (g <= eps); 24 | gdb = 10 * log10(gdb); 25 | gdb = gdb .* (gdb > -Rm) + (-Rm) * (gdb <= -Rm); 26 | gdb = (gdb + Rm)/Rm; 27 | 28 | if type == 1, % polar plot 29 | x = gdb .* sin(th); 30 | y = gdb .* cos(th); 31 | h = plot(x, y, style, 'LineWidth', width); 32 | else % azimuthal plot 33 | x = gdb .* cos(th); 34 | y = gdb .* sin(th); 35 | h = plot(x, y, style, 'LineWidth', width); 36 | end 37 | 38 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dguide.m: -------------------------------------------------------------------------------- 1 | % dguide.m - TE modes in dielectric slab waveguide 2 | % 3 | % Usage: [be,kc,ac,fc,err] = dguide(f,a,n1,n2,Nit) 4 | % [be,kc,ac,fc,err] = dguide(f,a,n1,n2) (equivalent to Nit=3) 5 | % 6 | % f = frequency in GHz 7 | % a = half-width of slab in cm 8 | % n1,n2 = refractive indices of slab and cladding (n1>n2) 9 | % Nit = number of Newton iterations (default Nit=3) 10 | % 11 | % be = propagatioin wavenumbers of the supported TE modes in rads/cm 12 | % kc = cutoff wavenumbers inside slab in rad/cm 13 | % ac = cutoff wavenumbers outside slab in nepers/cm 14 | % fc = cutoff frequencies below f in GHz 15 | % err = approximation error in determining kc,ac 16 | % 17 | % calls DSLAB to solve for kc,ac 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function [be,kc,ac,fc,err] = dguide(f,a,n1,n2,Nit) 22 | 23 | if nargin==0, help dguide; return; end 24 | if nargin==4, Nit=3; end; 25 | 26 | c0 = 30; % c0 in GHz x cm 27 | k0 = 2*pi*f/c0; % free-space wavenumber 28 | NA = sqrt(n1^2 - n2^2); % numerical aperture 29 | R = k0*a*NA; % circle radius 30 | M = floor(2*R/pi); % number of modes = M+1 31 | m = 0:M; % mode numbers 32 | Rc = m*pi/2; % cutoff radii 33 | fc = c0*Rc/(2*pi*a*NA); % cutoff frequencies in GHz 34 | 35 | [u,v,err] = dslab(R,Nit); 36 | 37 | kc = u/a; 38 | ac = v/a; 39 | 40 | be = sqrt(n1^2*k0^2 - kc.*kc); % propagation wavenumbers 41 | 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/diffr.m: -------------------------------------------------------------------------------- 1 | % diffr.m - knife-edge diffraction coefficient 2 | % 3 | % Usage: D = diffr(v) 4 | % 5 | % v = vector of normalized Fresnel diffraction variables 6 | % D = vector of difraction coefficients 7 | % 8 | % notes: it calculates D = (F(v) + (1-j)/2)/(1-j), 9 | % where F(v) = C(v) - jS(v) = complex Fresnel function 10 | % and F(v) is calculated using fcs(v) 11 | % 12 | % v = sqrt(2/lambda*F) * b, 13 | % where b = clearance distance from edge and 14 | % 1/F = 1/r1 + 1/r2 or F = r1*r2/(r1+r2) 15 | % 16 | % diffraction loss is L = -20*log10(abs(D)) 17 | 18 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 19 | 20 | function D = diffr(v) 21 | 22 | if nargin==0, help diffr; return; end 23 | 24 | D = (fcs(v) + (1-j)/2) / (1-j); 25 | 26 | 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dipdir.m: -------------------------------------------------------------------------------- 1 | % dipdir.m - dipole directivity 2 | % 3 | % Usage: [Rpeak,Dmax,thmax,cn] = dipdir(L); 4 | % 5 | % L = dipole length in wavelengths 6 | % 7 | % Rpeak = input resistance at current maximum 8 | % Dmax = directivity 9 | % thmax = angle of maximum gain in degrees 10 | % cn = gain normalization constant 11 | % 12 | % Notes: finds the maximum of the function 13 | % G(th) = cos(pi*L*cos(th)) - cos(pi*L)).^2./sin(th).^2 14 | % Gmax = G(thmax), note 180-thmax is also a maximum 15 | % 16 | % normalizes g(th) = G(th)/Gmax, cn = 1/Gmax 17 | % 18 | % Rpeak = eta/pi * A 19 | % where A = 1/2 * (Cin(kl) + 1/2 * cos(kl) * (2*Cin(kl) - Cin(2*kl)) + ... 20 | % 1/2 * sin(kl) * (Si(2*kl) - 2*Si(kl))); 21 | % 22 | % directivity D = eta/(pi*Rpeak)/cn = 1/(cn*A) 23 | % 24 | % see also dmax, dipole, Cin, Si 25 | 26 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 27 | 28 | function [Rpeak,Dmax,thmax,cn] = dipdir(L) 29 | 30 | if nargin==0, help dipdir; return; end 31 | 32 | G = inline('(cos(pi*L*cos(th)) - cos(pi*L)).^2./sin(th).^2', 'L', 'th'); % un-normalized gain 33 | 34 | N = 2000; 35 | th = linspace(0,pi, N+1); th([1,end]) =[]; 36 | [Gmax,imax] = max(G(L,th)); 37 | thmax = imax*180/N; 38 | cn = 1/Gmax; 39 | 40 | kl = 2*pi*L; 41 | 42 | A = 1/2 * (Cin(kl) + 1/2 * cos(kl) * (2*Cin(kl) - Cin(2*kl)) + ... 43 | 1/2 * sin(kl) * (Si(2*kl) - 2*Si(kl))); 44 | 45 | Rpeak = etac(1)/pi * A; 46 | 47 | Dmax = 1/(A*cn); 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dipole.m: -------------------------------------------------------------------------------- 1 | % dipole.m - gain of center-fed linear dipole of length L 2 | % 3 | % Usage: [g, th, c] = dipole(L, Nth); 4 | % 5 | % L = antenna length in units of lambda 6 | % 7 | % g = power gain evaluated at th 8 | % th = (Nth+1) equally-spaced polar angles in [0,pi] 9 | % 10 | % notes: computes g(th) = c * [(cos(pi*L*cos(th)) - cos(pi*L)) / sin(th)]^2, 11 | % where c normalizes to unity maximum, 12 | % 13 | % Hertzian dipole: L=0 14 | % Half-wave dipole: L=1/2 15 | % 16 | % see also TRAVEL, RHOMBIC, VEE 17 | 18 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 19 | 20 | function [g, th, c] = dipole(L, Nth) 21 | 22 | if nargin==0, help dipole; return; end 23 | 24 | th = (1:Nth-1) * pi/Nth; % exclude th=0 and th=pi 25 | 26 | if L == 0, 27 | g = sin(th).^2; 28 | else 29 | g = ((cos(pi*L*cos(th)) - cos(pi*L))./sin(th)).^2; 30 | end 31 | 32 | c = 1 / max(g); 33 | 34 | th = [0, th, pi]; % add th=0 and th=pi 35 | g = [0, c*g, 0]; 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dmax.m: -------------------------------------------------------------------------------- 1 | % dmax.m - computes directivity and beam solid angle of g(th) gain 2 | % 3 | % Usage: [D, Om] = dmax(th, g) 4 | % 5 | % th = row vector of equally-spaced polar angles in [0,pi] 6 | % g = power gain evaluated at th 7 | % 8 | % D = directivity 9 | % Om = beam solid angle 10 | % 11 | % notes: D = 4*pi/Om 12 | % g must be normalized to unity maximum 13 | % g can be obtained from DIPOLE, TRAVEL, RHOMBIC, VEE 14 | 15 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 16 | 17 | function [D, Om] = dmax(th, g) 18 | 19 | if nargin==0, help dmax; return; end 20 | 21 | N = size(th(:), 1) - 1; 22 | 23 | Om = 2 * pi * sum(g .* sin(th)) * pi / N; 24 | 25 | D = 4 * pi / Om; 26 | 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dnv.m: -------------------------------------------------------------------------------- 1 | % dnv.m - dn elliptic function at a vector of moduli 2 | % 3 | % Usage: w = dnv(u,k) 4 | % 5 | % u = Lx1 column vector of complex numbers on the u-plane 6 | % k = 1xN row vector of elliptic moduli 7 | % 8 | % w = LxN matrix of values of dn(u*K,k), where K=K(k) 9 | % 10 | % Notes: u is in units of the quarterperiod K 11 | % 12 | % in terms of the elliptic function dn(z,k), the ij-th matrix element is 13 | % w(i,j) = dn(u(i)*K(j), k(j)) 14 | % where K(j) = K(k(j)) is the quarter period of the j-th modulus k(j) 15 | % 16 | % the j-th column w(:,j) is equivalent to the call w(:,j) = dne(u,k(j)) 17 | % 18 | % k may not be equal to 1 19 | % 20 | % Based on the function DNE of the reference: 21 | % Sophocles J. Orfanidis, "High-Order Digital Parametric Equalizer Design", 22 | % J. Audio Eng. Soc., vol.53, pp. 1026-1046, November 2005. 23 | % see also, http://www.ece.rutgers.edu/~orfanidi/hpeq/ 24 | % 25 | % uses vectorized the version SNV of SNE from this reference 26 | % used in KERNEL 27 | 28 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 29 | 30 | function w = dnv(u,k) 31 | 32 | if nargin==0, help dnv; return; end 33 | 34 | for i=1:length(u), 35 | w(i,:) = sqrt(1 - k.^2 .* snv(u(i),k).^2); 36 | end 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dolph.m: -------------------------------------------------------------------------------- 1 | % dolph.m - Dolph-Chebyshev array weights 2 | % 3 | % Usage: [a, dph] = dolph(d, ph0, N, R) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees (broadside ph0=90) 7 | % N = number of array elements (even or odd) 8 | % R = relative sidelobe level in dB, (e.g. R = 30) 9 | % 10 | % a = row vector of array weights (steered towards ph0) 11 | % dph = 3-dB beamwidth in degrees 12 | % 13 | % note: array factor is Chebyshev A(psi) = T_{N-1}(x), x = x0 * cos(psi/2), 14 | % 15 | % see also UNIFORM, BINOMIAL, TAYLOR, SECTOR, DOLPH2, DOLPH3 16 | 17 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 18 | 19 | function [a, dph] = dolph(d, ph0, N, R) 20 | 21 | if nargin==0, help dolph; return; end 22 | 23 | N1 = N - 1; % number of pattern zeros 24 | Ra = 10^(R/20); % sidelobe level in absolute units 25 | x0 = cosh(acosh(Ra)/N1); % scaling factor 26 | 27 | dmax = acos(-1/x0)/pi; % maximum element spacing 28 | 29 | if d>dmax, 30 | fprintf('maximum allowed spacing is dmax = %.4f\n', dmax); 31 | return; 32 | end 33 | 34 | i = 1:N1; 35 | x = cos(pi*(i-0.5)/N1); % N1 zeros of Chebyshev polynomial T_N1(x) 36 | psi = 2 * acos(x/x0); % N1 array pattern zeros in psi-space 37 | z = exp(j*psi); % N1 zeros of array polynomial 38 | 39 | a = real(poly2(z)); % zeros-to-polynomial form, N1+1 = N coefficients 40 | 41 | a = steer(d, a, ph0); % steer towards ph0 42 | 43 | x3 = cosh(acosh(Ra/sqrt(2))/N1); % 3-dB Chebyshev variable x 44 | psi3 = 2*acos(x3/x0); % exact 3-dB frequency 45 | dps = 2*psi3; % 3-dB width 46 | 47 | dph = bwidth(d, ph0, dps); % 3-dB width in phi-space 48 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dsinc.m: -------------------------------------------------------------------------------- 1 | % dsinc.m - the double-sinc function cos(pi*x)/(1-4*x^2) 2 | % 3 | % Usage: y = dsinc(x) 4 | % 5 | % x = any real-valued array or matrix 6 | % y = result of same size as x 7 | % 8 | % notes: even function of x 9 | % x = 0.5, y = pi/4 10 | % x = 0.5945, y = 1/sqrt(2) (3-dB point) 11 | % x = 1.5, y = 0 (first null) 12 | % x = 1.8894, y = 0.0708 = -22.9987 dB (first sidelobe) 13 | % 14 | % it uses the built-in SINC from the SP toolbox 15 | 16 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function y = dsinc(x) 19 | 20 | if nargin==0, help dsinc; return; end 21 | 22 | y = (sinc(x+0.5) + sinc(x-0.5)) * pi/4; 23 | 24 | % it can also be constructed directly as follows: 25 | % 26 | % y = ones(size(x) * pi/4; 27 | % i = find(abs(x)-0.5); 28 | % y(i) = cos(pi*x(i)) ./ (1 - 4*x(i).^2); 29 | 30 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dtft.m: -------------------------------------------------------------------------------- 1 | % dtft.m - DTFT of a signal x at a frequency vector w 2 | % 3 | % Usage: X = dtft(x, w); 4 | % 5 | % x = length-L vector of time samples, x = [x(0),x(1),...,x(L-1)] 6 | % w = length-N vector of frequencies in rads/sample, w = [w1,w2,...,wN] 7 | % 8 | % X = length-N row vector of DTFT values, X = [X(w1),X(w2),...,X(wN)] 9 | % 10 | % notes: evaluates z-transform of x on the unit-circle: 11 | % X(z) = \sum_{n=0}^{L-1} x(n)z^{-n}, where z=e^{j\omega} 12 | % 13 | % x,w can be entered row-wise or column-wise, they are internally 14 | % converted to row vectors 15 | % 16 | % w is in units of radians/sample, w = 2*pi*f/fs 17 | % 18 | % based on and replaces both dtft.c and dtftr.c of 19 | % the "Introduction to Signal Processing" book 20 | 21 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 22 | 23 | function X = dtft(x, w) 24 | 25 | if nargin==0, help dtft; return; end 26 | 27 | x = x(:).'; % make x a row w/o conjugation 28 | w = w(:)'; % make w a row 29 | 30 | L = length(x); 31 | 32 | z = exp(-j*w); % unit-circle points 33 | 34 | X = 0; % evaluate z-transform using H\"orner's rule 35 | for n = L-1:-1:0, 36 | X = x(n+1) + z .* X; 37 | end 38 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/dualbw.m: -------------------------------------------------------------------------------- 1 | % dualbw.m - two-section dual-band transformer bandwidths 2 | % 3 | % Usage: [f1L,f1R,f2L,f2R] = dualbw(Z0,ZL,r,GB); 4 | % 5 | % Z0 = main line impedance 6 | % ZL = load impedance (real-valued) 7 | % r = harmonic number (arbitrary real number, r>1) 8 | % GB = reflection-coefficient bandwidth level 9 | % 10 | % f1L,f1R = left and right bandwidth edge frequencies about f1 (in units of f1) 11 | % f2L,f2R = left and right bandwidth edge frequencies about f2 (in units of f1) 12 | % 13 | % Notes: f1L and f2R lie symmetrically about f0, i.e., f1L + f2R = 2f0 14 | % f1R and f2L lie symmetrically about f0, i.e., f1R + f2L = 2f0 15 | % 16 | % SWR over the bandwidth is SB = (1+GB)/(1-GB) => GB = (SB-1)/(SB+1) 17 | % 18 | % see also DUALBAND 19 | 20 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 21 | 22 | function [f1L,f1R,f2L,f2R] = dualbw(ZL,Z0,r,GB) 23 | 24 | if nargin==0, help dualbw; return; end 25 | 26 | delta1 = pi/(r+1); 27 | 28 | GL = (ZL-Z0)/(ZL+Z0); 29 | 30 | a = sqrt(GB^2/(1-GB^2) * (1-GL^2)/GL^2); 31 | 32 | f1L = (r+1)/pi * asin(sin(delta1) * sqrt(1-a)); 33 | f1R = (r+1)/pi * asin(sin(delta1) * sqrt(1+a)); 34 | 35 | f2L = r + 1 - f1R; 36 | f2R = r + 1 - f1L; 37 | 38 | 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/ellipE.m: -------------------------------------------------------------------------------- 1 | % ellipE - complete elliptic integral of second kind at a vector of moduli 2 | % 3 | % Usage: E = ellipE(k,M) 4 | % E = ellipE(k) (equivalent to M=7) 5 | % 6 | % k = row vector of elliptic moduli 7 | % M = fixed number of Landen iterations, (default M=7) 8 | % 9 | % K = row vector of quarter periods K(k) 10 | % 11 | % Notes: first it constructs the Landen vector of descending moduli, v = landv(k), 12 | % and then it computes K = prod(1+v)) * pi/2 13 | % 14 | % produces the same answer as the built-in function ELLIPKE, K = ellipke(k^2) 15 | % 16 | % k can be entered as a column, but it's turned into a row 17 | % 18 | % Based on the function ELLIPK of the reference: 19 | % Sophocles J. Orfanidis, "High-Order Digital Parametric Equalizer Design", 20 | % J. Audio Eng. Soc., vol.53, pp. 1026-1046, November 2005. 21 | % see also, http://www.ece.rutgers.edu/~orfanidi/hpeq/ 22 | % 23 | % uses the vectorized the version LANDENV of LANDEN from this reference 24 | % used by KERNEL 25 | 26 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 27 | 28 | function E = ellipE(k,M) 29 | 30 | if nargin==0, help ellipE; return; end 31 | if nargin==1, M=7; end 32 | 33 | kmin = 1e-7; 34 | kmax = sqrt(1-kmin^2); % kmax = 0.99999999999999500 35 | 36 | dim = size(k); 37 | 38 | k = k(:)'; 39 | 40 | E = zeros(size(k)); 41 | 42 | v = landenv(k,M); 43 | 44 | E = ones(1,length(k)) * pi/2; 45 | K = E; 46 | 47 | for n=M:-1:1, 48 | kn = v(n,:); 49 | E = 2*E./(1+kn) - (1-kn).*K; 50 | K = (1+kn).*K; 51 | end 52 | 53 | i = find(k>kmax); 54 | E(i) = 1; 55 | 56 | E = reshape(E,dim); 57 | 58 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/ellipse.m: -------------------------------------------------------------------------------- 1 | % ellipse.m - polarization ellipse parameters 2 | % 3 | % Usage: [a,b,th] = ellipse(A,B,phi) 4 | % 5 | % A = magnitude of E-field x-component 6 | % B = magnitude of E-field y-component 7 | % phi = relative phase angle (in degrees) between x- and y-components (phi = phi_a - phi_b) 8 | % 9 | % a = x-semiaxis 10 | % b = y-semiaxis 11 | % th = tilt angle (in degrees) of polarization ellipse measured from x-axis 12 | 13 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 14 | 15 | function [a,b,th] = ellipse(A,B,phi) 16 | 17 | if nargin==0, help ellipse; return; end 18 | 19 | a = zeros(size(A)); 20 | b = zeros(size(A)); 21 | th = zeros(size(A)); 22 | 23 | phi = phi * pi/180; 24 | 25 | r = cos(phi); 26 | 27 | i = find(A~=B); 28 | 29 | a(i) = sqrt((A(i).^2 + B(i).^2 + sign(A(i)-B(i)) .* sqrt((A(i).^2 - B(i).^2).^2 + 4 * r(i).^2 .* A(i).^2 .* B(i).^2))/2); 30 | b(i) = sqrt((A(i).^2 + B(i).^2 - sign(A(i)-B(i)) .* sqrt((A(i).^2 - B(i).^2).^2 + 4 * r(i).^2 .* A(i).^2 .* B(i).^2))/2); 31 | 32 | th(i) = atan(2*A(i).*B(i).*r(i) ./ (A(i).^2 - B(i).^2))/2; 33 | 34 | i = find(A==B); 35 | 36 | a(i) = A(i) .* sqrt(1 + r(i)); 37 | b(i) = A(i) .* sqrt(1 - r(i)); 38 | 39 | th(i) = pi/4; 40 | 41 | th = th * 180/pi; 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/etac.m: -------------------------------------------------------------------------------- 1 | % etac.m - eta and c 2 | % 3 | % Usage: [eta,c] = etac(n) 4 | % 5 | % n = vector of refractive indices = [n1,...,nM] 6 | % 7 | % eta = vector of characteristic impedances = [eta1,...,etaM] 8 | % c = vector of speeds of light = [c1,...,cM] 9 | % 10 | % notes: mu = eta/c, epsilon = 1/eta/c 11 | % 12 | % [eta0,c0] = etac(1) generates the vacuum values 13 | % 14 | % the values of the physical constants are from: 15 | % E. R. Cohen, ``The 1986 CODATA Recommended Values of the Fundamental 16 | % Physical Constants,'' J. Res. Natl. Bur. Stand., vol.92, p.85, (1987). 17 | 18 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 19 | 20 | function [eta,c] = etac(n) 21 | 22 | if nargin==0, help etac; return; end 23 | 24 | c0 = 299792458; 25 | mu0 = 4*pi*1e-7; % eps0 = 1/mu0/c0^2 = 8.854187817e-12 26 | 27 | eta0 = mu0 * c0; % eta0 = 376.7303 ohms 28 | 29 | c = c0./n; 30 | eta = eta0./n; 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/ewa_license.m: -------------------------------------------------------------------------------- 1 | % -------------------------------------------------------------------------- 2 | % Electromagnetic Waves & Antennas Toolbox 3 | % -------------------------------------------------------------------------- 4 | % Copyright (c) 1996-2008 by S. J. Orfanidis 5 | % -------------------------------------------------------------------------- 6 | % Sophocles J. Orfanidis 7 | % ECE Department 8 | % Rutgers University 9 | % 94 Brett Road 10 | % Piscataway, NJ 08854-8058 11 | % 12 | % Tel.: 732-445-5017 13 | % e-mail: orfanidi@ece.rutgers.edu 14 | % -------------------------------------------------------------------------- 15 | % Last revision date: February 3, 2008 16 | % -------------------------------------------------------------------------- 17 | % The functions may be downloaded from the book's web page: 18 | % http://www.ece.rutgers.edu/~orfanidi/ewa 19 | % -------------------------------------------------------------------------- 20 | % License 21 | % ------- 22 | % These programs are for educational use only. They were designed to illustrate 23 | % the concepts in the author's book on "Electromagnetic Waves and Antennas". Their 24 | % usage is explained in examples throughout this book. 25 | % 26 | % The author makes no warranties of any kind, expressed or implied, with regard 27 | % to these programs or their documentation. The author shall not be liable in any 28 | % event for incidental or consequential damages in connection with, or arising 29 | % out of, the furnishing performance, or the use of these programs. 30 | % 31 | % These programs may be distributed freely for educational purposes only, as long 32 | % as they are not modified in any way and this licence/copyright notice is 33 | % included. Commercial use requires permission of the author. 34 | % -------------------------------------------------------------------------- 35 | 36 | function ewa_license 37 | 38 | help ewa_license; 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/fcs.m: -------------------------------------------------------------------------------- 1 | % fcs.m - Fresnel integrals C(x) and S(x) 2 | % 3 | % Usage: F = fcs(x) 4 | % 5 | % x = vector or matrix of real numbers 6 | % F = C(x) - jS(x) of same size as x 7 | % 8 | % notes: F(x) = C(x) - j*S(x) = int_0^x exp(-j*pi*t^2/2) dt 9 | % 10 | % C(x), S(x) are evaluated in terms of the type-2 Fresnel integrals: 11 | % 12 | % C(x) = C2(pi*x^2/2), S(x) = S2(pi*x^2/2), if x>=0 13 | % C(x) = -C2(pi*x^2/2), S(x) = -S2(pi*x^2/2), if x<=0 (they are odd functions) 14 | % 15 | % where C2(x) - j*S2(x) = int_0^x exp(-j*t)/sqrt(2*pi*t) dt 16 | % 17 | % and C2(x), S2(x) are evaluated by Boersma's approximation 18 | % 19 | % references: J. Boersma, "Computation of Fresnel Integrals", 20 | % Math. Comp., vol.14, p.380, (1960). 21 | % 22 | % M. Abramowitz and I. Stegun, 23 | % Handbook of Mathematical Functions, 24 | % Dover Publications, New York, 1965, 25 | % Sec. 7.1.29, p.299 26 | % 27 | % example: x C(x)=real(F) S(x)=-imag(F) 28 | % --------------------------------- 29 | % 0.0 0.000000 0.000000 30 | % 0.5 0.492344 0.064732 31 | % 1.0 0.779893 0.438259 32 | % 1.5 0.445261 0.697505 33 | % 2.0 0.488253 0.343416 34 | % 2.5 0.457413 0.619182 35 | 36 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 37 | 38 | function F = fcs(x) 39 | 40 | if nargin==0, help fcs; return; end 41 | 42 | F = zeros(size(x)); % defines the size of F 43 | 44 | F = fcs2(pi*x.^2/2); 45 | 46 | i = find(x<0); 47 | F(i) = -F(i); % F(x) is an odd function 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/flip.m: -------------------------------------------------------------------------------- 1 | % flip.m - flip a column, a row, or both 2 | % 3 | % Usage: y = flip(x) 4 | % 5 | % equivalent to: 6 | % y = fliplr(x) if x is a row vector 7 | % y = flipud(x), if x is a column vector 8 | % y = flipud(fliplr(x)), if x is a matrix 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function y = flip(x) 13 | 14 | if nargin==0, help flip; return; end 15 | 16 | y = x(end:-1:1, end:-1:1); 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/frwrec.m: -------------------------------------------------------------------------------- 1 | % frwrec.m - order-increasing forward layer recursion - from r to A,B 2 | % 3 | % Usage: [A,B] = frwrec(r) 4 | % 5 | % r = reflection coefficients = [r(1),...,r(M+1)], M = number of layers 6 | % A,B = (M+1)x(M+1) matrices whose columns are the reflection polynomials 7 | 8 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 9 | 10 | function [A,B] = frwrec(r) 11 | 12 | if nargin==0, help frwrec; return; end 13 | 14 | M = length(r)-1; 15 | 16 | A = zeros(M+1,M+1); 17 | B = zeros(M+1,M+1); 18 | 19 | A(1,M+1) = 1; 20 | B(1,M+1) = r(M+1); 21 | 22 | for i=M:-1:1, 23 | A(1:M+2-i, i) = [A(1:M+1-i, i+1); 0] + r(i) * [0; B(1:M+1-i, i+1)]; 24 | B(1:M+2-i, i) = r(i) * [A(1:M+1-i, i+1);0] + [0; B(1:M+1-i, i+1)]; 25 | end 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/g2z.m: -------------------------------------------------------------------------------- 1 | % g2z.m - reflection coefficient to impedance transformation 2 | % 3 | % Usage: Z = g2z(Gamma,Z0) 4 | % Z = g2z(Gamma) (equivalent to Z0=1, i.e, normalized impedances) 5 | % 6 | % Gamma = vector of reflection coefficients 7 | % Z0 = line impedance 8 | % 9 | % Z = vector of impedances 10 | % 11 | % notes: if Gamma=1, it returns Z=inf 12 | % 13 | 14 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function Z = g2z(Gamma,Z0) 17 | 18 | if nargin==0, help g2z; return; end 19 | if nargin==1, Z0=1; end 20 | 21 | Z = Z0*(1+Gamma)./(1-Gamma); 22 | 23 | 24 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/gain1d.m: -------------------------------------------------------------------------------- 1 | % gain1d.m - normalized gain computation for 1D equally-spaced isotropic array 2 | % 3 | % Usage: [g, phi] = gain1d(d, a, N); 4 | % 5 | % d = array spacing in units of lambda 6 | % a = row vector of array weights 7 | % N = number of azimuthal angles in [0,pi] (actually, N+1 angles) 8 | % 9 | % g = row vector of gain values evaluated at phi 10 | % phi = row vector of (N+1) equally-spaced angles over [0, pi] (in radians) 11 | % 12 | % notes: computes g(phi) = |A(psi)|^2, where A(psi) = \sum_n a(n)z^n, 13 | % with z = e^(j*psi) and psi = 2*pi*d*cos(phi), 14 | % 15 | % normalizes g to unity maximum, 16 | % [g,phi] can be passed into gain plotting functions DBZ,ABZ 17 | % e.g., dbz(phi,g), abz(phi,g) 18 | % 19 | % to compute the gain of a scanned array use SCAN or STEER first, e.g. 20 | % [g, phi] = gain1d(d, scan(a,psi0), N); 21 | % [g, phi] = gain1d(d, steer(d,a,phi0), N); 22 | % 23 | % uses the I2SP function DTFT 24 | % 25 | % (this function replaces an earlier pre-2005 version called ARRAY) 26 | % 27 | % see also UNIFORM, BINOMIAL, TAYLOR, DOLPH, SECTOR, MULTIBEAM 28 | 29 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 30 | 31 | function [g, phi] = gain1d(d, a, N) 32 | 33 | if nargin==0, help gain1d; return; end 34 | 35 | phi = (0 : N) * pi / N; % equally-spaced over [0,pi] 36 | 37 | psi = 2 * pi * d * cos(phi); 38 | 39 | A = dtft(a, -psi); % array factor, note dsft(a,psi)=dtft(a,-psi) 40 | g = abs(A).^2; % power gain 41 | g = g/max(g); % normalized to unity maximum 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/gin.m: -------------------------------------------------------------------------------- 1 | % gin.m - input reflection coefficient in terms of S-parameters 2 | % 3 | % Usage: gamma = gin(S,gL) 4 | % 5 | % S = 2x2 S-matrix 6 | % gL = load reflection coefficient 7 | % 8 | % gamma = input reflection coefficient 9 | % 10 | % notes: computes gamma_in = S11 + S12*S21*gL/(1-S22*gL) 11 | 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function gamma = gin(S,gL) 15 | 16 | if nargin==0, help gin; return; end 17 | 18 | gamma = S(1,1) + S(1,2)*S(2,1)*gL ./ (1-S(2,2)*gL); 19 | 20 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/gout.m: -------------------------------------------------------------------------------- 1 | % gout.m - output reflection coefficient in terms of S-parameters 2 | % 3 | % Usage: gamma = gout(S,gG) 4 | % 5 | % S = 2x2 S-matrix 6 | % gG = generator reflection coefficient 7 | % 8 | % gamma = output reflection coefficient 9 | % 10 | % notes: computes gamma_out = S22 + S12*S21*gG/(1-S11*gG) 11 | 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function gamma = gout(S,gG) 15 | 16 | if nargout==0, help gout; return; end 17 | 18 | gamma = S(2,2) + S(1,2)*S(2,1)*gG ./ (1-S(1,1)*gG); 19 | 20 | 21 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/gprop.m: -------------------------------------------------------------------------------- 1 | % gprop.m - reflection coefficient propagation 2 | % 3 | % --------|-------------|---------- 4 | % generator Gamma1 l Gamma2 load 5 | % --------|-------------|---------- 6 | % 7 | % Usage: G1 = gprop(G2,bl) 8 | % 9 | % G2 = reflection coefficient 10 | % bl = phase length in radians = beta*l = 2*pi*l/lambda 11 | % 12 | % G1 = reflection coefficient 13 | % 14 | % notes: for a lossy line bl can also be complex, i.e., bl-j*al 15 | 16 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function G1 = gprop(G2,bl) 19 | 20 | if nargin==0, help gprop; return; end 21 | 22 | G1 = G2 * exp(-2*j*bl); 23 | 24 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/heff.m: -------------------------------------------------------------------------------- 1 | % heff.m - aperture efficiency of horn antenna 2 | % 3 | % Usage: ea = heff(sa,sb) 4 | % 5 | % sa,sb = sigma parameters, e.g., sa = sqrt(4*Sa) = A/sqrt(2*lambda*Ra) 6 | % 7 | % ea = aperture efficiency 8 | % 9 | % notes: evaluates the quantity ea = abs(diffint(0,sa,1)*diffint(0,sb,0))^2 / 8 10 | 11 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function ea = heff(sa,sb) 14 | 15 | if nargin==0, help heff; return; end 16 | 17 | ea = abs(diffint(0,sa,1)*diffint(0,sb,0))^2 / 8; 18 | 19 | 20 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/hopt.m: -------------------------------------------------------------------------------- 1 | % hopt.m - optimum horn antenna design 2 | % 3 | % Usage: [A,B,R,err] = hopt(G,a,b,sa,sb,N) 4 | % [A,B,R,err] = hopt(G,a,b,sa,sb) (assumes N=100) 5 | % [A,B,R,err] = hopt(G,a,b) (assumes optimum values sa=1.2593, sb=1.0246) 6 | % 7 | % G = required gain in dB 8 | % a,b = waveguide sides in units of lambda 9 | % sa,sb = sigma phase parameters 10 | % N = maximum number of iterations 11 | % 12 | % A,B = horn sides 13 | % R = axial length from waveguide end to horn plane (R = RA = RB) 14 | % err = design error 15 | % 16 | % notes: uses Newton's method to solve the system of equations: 17 | % 18 | % f = [B - 0.5*(b + sqrt(b^2 + 4*c*A*(A-a))); A*B - G/(4*pi*e)] = 0 19 | % 20 | % design error is err=norm(f) after convergence 21 | % 22 | % coverges very fast in about N = 3-5 iterations 23 | % 24 | % use N = 0 to output the initial values, which are the same as in the constant-r case 25 | 26 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 27 | 28 | function [A,B,R,err] = hopt(G,a,b,sa,sb,N) 29 | 30 | if nargin==0, help hopt; return; end 31 | if nargin<=5, N=10; end 32 | if nargin==3, [sa,sb] = hsigma(0); end 33 | 34 | G = 10^(G/10); 35 | 36 | e = heff(sa,sb); 37 | 38 | c = sb^2/sa^2; 39 | 40 | A = sqrt(G/(4*pi*e) * sa/sb); % initial values 41 | B = sqrt(G/(4*pi*e) * sb/sa); 42 | f = [B - 0.5*(b + sqrt(b^2 + 4*c*A*(A-a))); A*B - G/(4*pi*e)]; 43 | 44 | for i=1:N, 45 | f = [B - 0.5*(b + sqrt(b^2 + 4*c*A*(A-a))); A*B - G/(4*pi*e)]; 46 | M = [-c*(2*A-a)/(2*B-b), 1; B, A]; 47 | Dx = -M\f; 48 | A = A + Dx(1); 49 | B = B + Dx(2); 50 | end 51 | 52 | err = norm(f); 53 | 54 | R = A*(A-a)/(2*sa^2); 55 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/hsigma.m: -------------------------------------------------------------------------------- 1 | % hsigma.m - optimum sigma parametes for horn antenna 2 | % 3 | % Usage: [sa,sb] = hsigma(r) 4 | % [sa,sb] = hsigma(0) (generates sa=1.2593, sb=1.0246) 5 | % 6 | % r = desired apect ratio a/b 7 | % sa,sb = optimum sigma parameters (sb = r*sa) 8 | % 9 | % notes: computes the optimum sigma parameters for constant aspect ratio r = A/B = a/b 10 | % 11 | % if r = 0, it finds the maxima of the functions in the interval 0.25 <= s <=2.75: 12 | % 13 | % fa(s) = s .* abs(diffint(0,s,1)).^2 --> sa = 1.2593 14 | % fb(s) = s .* abs(diffint(0,s,0)).^2 --> sb = 1.0246 15 | % 16 | % if r > 0, it finds the maximum of the function: 17 | % 18 | % fr(s) = fa(s) * fb(r*s) --> sa, and sets sb = r*s 19 | % 20 | % uses DIFFINT to define the functions, and MATLAB's FMINBND to find their maxima 21 | 22 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 23 | 24 | function [sa,sb] = hsigma(r) 25 | 26 | if nargin==0, help hsigma; return; end 27 | 28 | fa = inline('-s .* abs(diffint(0,s,1)).^2'); 29 | fb = inline('-s .* abs(diffint(0,s,0)).^2'); 30 | fr = inline('-abs(s .* diffint(0,s,1) .* diffint(0,r*s,0)).^2','s','r'); 31 | 32 | if r==0, 33 | sa = fminbnd(fa,0.25,2.75,optimset('display','off')); 34 | sb = fminbnd(fb,0.25,2.75,optimset('display','off')); 35 | else 36 | sa = fminbnd(fr,0.25,2.75,optimset('display','off'),r); 37 | sb = r * sa; 38 | end 39 | 40 | 41 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/hwrap.m: -------------------------------------------------------------------------------- 1 | % hwrap.m - wraps a Toeplitz impedance matrix to half its size 2 | % 3 | % Usage: Zwrap = hwrap(Z) 4 | % 5 | % Z = (2M+1)x(2M+1) impedance matrix 6 | % 7 | % Zwrap = (M+1)x(M+1) wrapped version of Z, to be used for symmetric current distributions 8 | 9 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 10 | 11 | function Zwrap = hwrap(Z) 12 | 13 | if nargin==0, help hwrap; return; end 14 | 15 | N = size(Z,1); 16 | if rem(N,2)~=1, fprintf('hwrap: Z must have odd dimension\n'); return; end 17 | M = (N-1)/2; 18 | 19 | c = Z(1,1:M+1); % becomes the first column of Toeplitz and Hankel parts 20 | r = Z(1,M+1:end); % becomes the last row of Hankel part 21 | 22 | Zwrap = toeplitz(c,c) + hankel(c,r); % hwrap impedance matrix 23 | Zwrap(:,1) = Zwrap(:,1)/2; 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/kingeval.m: -------------------------------------------------------------------------------- 1 | % kingeval.m - evaluate King's 3-term sinusoidal current approximation 2 | % 3 | % Usage: I = kingeval(L,A,z) 4 | % 5 | % L = antenna length in wavelengths 6 | % A = coefficient vector for sinusoidal terms A = [A1] or [A1,A2] or [A1,A2,A3] 7 | % z = points at which to evaluate the current I(z) 8 | % 9 | % I = current values of the 3-term expression at z 10 | % 11 | % notes: evaluates King's 1-term, 2-term, 3-term, or 4-term sinusoidal approximation, 12 | % at a given set of z-points: 13 | % 14 | % 1-term : I1 = A1 * sin(k*(h-abs(z))) 15 | % 2-term : I2 = A1 * (sin(k*abs(z))-sin(k*h)) + A2 * (cos(k*z)-cos(k*h)) 16 | % 3-term : I3 = A1 * (sin(k*abs(z))-sin(k*h)) + A2 * (cos(k*z)-cos(k*h)) + A3 * (cos(k*z/2)-cos(k*h/2)) 17 | % 4-term : I4 = A1 * (sin(k*abs(z))-sin(k*h)) + A2 * (cos(k*z)-cos(k*h)) + ... 18 | % + A3 * (cos(k*z/4)-cos(k*h/4)) + A4 * (cos(3*k*z/4)-cos(3*k*h/4)) 19 | % 20 | % the coefficients A are obtaind from KING or KINGFIT, e.g., A = kingfit(L,In,zn,p), p=1,2,3,4 21 | % se also KINGPRIME for converting the A-coefficients to their primed form 22 | 23 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 24 | 25 | function I = kingeval(L,A,z) 26 | 27 | if nargin==0, help kingeval; return; end 28 | 29 | dim = size(z); 30 | 31 | A = A(:); 32 | z = z(:); 33 | 34 | h = L/2; 35 | k = 2*pi; 36 | 37 | p = length(A); 38 | 39 | if p==1, 40 | S = sin(k*(h-abs(z))); 41 | end 42 | 43 | if p>=2, 44 | S = [sin(k*abs(z))-sin(k*h), cos(k*z)-cos(k*h)]; 45 | end 46 | 47 | if p==3, 48 | S = [S, cos(k*z/2)-cos(k*h/2)]; 49 | end 50 | 51 | if p==4, 52 | S = [S, cos(k*z/4)-cos(k*h/4), cos(3*k*z/4)-cos(3*k*h/4)]; 53 | end 54 | 55 | I = S*A; 56 | 57 | I = reshape(I,dim); 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/kingprime.m: -------------------------------------------------------------------------------- 1 | % kingprime.m - converts King's 3-term coefficients from unprimed to primed form 2 | % 3 | % Usage: Aprime = kingprime(L,A) 4 | % 5 | % L = antenna length in wavelengths 6 | % A = coefficients of the sinusoidal terms, A = [A1], [A1,A2], [A1,A2,A3], or [A1,A2,A3,A4] 7 | % 8 | % Aprime = the primed coefficients 9 | % 10 | % Notes: converts King's 3-term coefficients from unprimed to primed form, that is, 11 | % 12 | % from I(z) = A1 * (sin(k|z|)-sin(kh)) + A2 * (cos(kz)-cos(kh)) + higher terms, 13 | % to I(z) = A1' * sin(k(h-|z|)) + A2' * (cos(kz)-cos(kh)) + higher terms 14 | % 15 | % applies only to p=2,3,4 terms, the 1-term is already in the unprimed form 16 | % 17 | % the unprimed coefficients are the outputs of KING or KINGFIT 18 | % 19 | % L may not be an odd-multiple of lambda/2 (e.g., a half-wave dipole) 20 | % 21 | % see also KING, KIGNFIT, KINGEVAL 22 | 23 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 24 | 25 | function Aprime = kingprime(L,A) 26 | 27 | if nargin==0, help kingprime; return; end 28 | if length(A)==1, fprintf('\nkingprime: not applicable for 1-term approximation\n'); Aprime=[]; return; end 29 | 30 | k = 2*pi; 31 | dim = size(A); 32 | A = A(:); 33 | Aprime = A; 34 | 35 | if rem(2*L,2)==1, 36 | fprintf('\nnot applicable when L is an odd multiple of lambda/2\n'); Aprime = []; return; 37 | else 38 | Aprime(1:2) = [-1/cos(k*L/2), 0; tan(k*L/2), 1] * A(1:2); 39 | end 40 | 41 | Aprime = reshape(Aprime,dim); 42 | 43 | 44 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/landenv.m: -------------------------------------------------------------------------------- 1 | % landenv.m - Landen transformations of a vector of elliptic moduli 2 | % 3 | % Usage: v = landenv(k,M) (M = integer) 4 | % v = landenv(k) (uses default value M=7) 5 | % 6 | % k = 1xL row vector of elliptic moduli 7 | % M = fixed number of Landen iterations (default M=7) 8 | % 9 | % v = MxL matrix of Landen vectors of descending moduli 10 | % 11 | % Notes: The descending Landen transformation is computed by the recurrence: 12 | % v(n) = F(v(n-1)), for n = 2,3,...,M 13 | % inialized to v(1) = k, where F(x) = [x/(1+sqrt(1-x^2))]^2 14 | % 15 | % i-th column v(:,i) contains to the Landen iterations of the i-th modulus k(i) 16 | 17 | % Based on the function LANDEN of the reference: 18 | % Sophocles J. Orfanidis, "High-Order Digital Parametric Equalizer Design", 19 | % J. Audio Eng. Soc., vol.53, pp. 1026-1046, November 2005. 20 | % see also, http://www.ece.rutgers.edu/~orfanidi/hpeq/ 21 | % 22 | % used by ELLIPK, ELLIPE, and SNV 23 | 24 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 25 | 26 | function v = landenv(k,M) 27 | 28 | if nargin==0, help landenv; return; end 29 | if nargin==1, M=7; end 30 | 31 | k = k(:)'; 32 | v = []; 33 | 34 | for n=1:M, 35 | k = (k./(1+sqrt(1-k.^2))).^2; 36 | v = [v; k]; 37 | end 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/lmin.m: -------------------------------------------------------------------------------- 1 | % lmin.m - find locations of voltage minima and maxima 2 | % 3 | % Usage: [lm,Zm] = lmin(ZL,Z0,type) 4 | % [lm,Zm] = lmin(ZL,Z0) (equivalent to type='min') 5 | % 6 | % ZL = load impedance 7 | % Z0 = line impedance 8 | % type = 'min', 'max' (default 'min') 9 | % 10 | % lm = location in wavelengths 11 | % Zm = real-valued wave impedance at lm 12 | % 13 | % notes: calculate G = z2g(ZL,Z0), S = swr(G), th = angle(G), then 14 | % 15 | % lmin = (th + pi)/4/pi, Zmin = Z0/S, 16 | % 17 | % lmax = th/4/pi (or, (th+2*pi)/4/pi, if th<0), Zmax = S*Z0 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function [lm,Zm] = lmin(ZL,Z0,type) 22 | 23 | if nargin==0, help lmin; return; end 24 | if nargin==2, type='min'; end 25 | 26 | G = z2g(ZL,Z0); 27 | S = swr(G); 28 | th = angle(G); 29 | 30 | if type=='min', 31 | lm = (th + pi)/4/pi; 32 | Zm = Z0/S; 33 | else 34 | if th<0, th = th+2*pi, end 35 | lm = th/4/pi; 36 | Zm = S*Z0; 37 | end 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/RLCmovie.m: -------------------------------------------------------------------------------- 1 | % RLCmovie.m - Movie of step-signal getting reflected from reactive termination. 2 | % based on Example 9.15.2 and Problem 9.30 3 | 4 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewaa 5 | 6 | clear all; 7 | 8 | d = 1; c = 1; T = d/c; 9 | 10 | Z0 = 50; R = 150; gR = z2g(R,Z0); 11 | 12 | a = 1; 13 | 14 | type = input('enter type = 1,2,3,4 for series R-L, parallel R-L, series R-C, parallel R-C \n type = '); 15 | 16 | if type==1, 17 | b0 = 1; b1 = a*gR; 18 | elseif type==2, 19 | b0 = gR; b1 = -a; 20 | elseif type==3, 21 | b0 = gR; b1 = a; 22 | elseif type==4, 23 | b0 = -1; b1 = a*gR; 24 | else 25 | disp('wrong type'); return; 26 | end 27 | 28 | t = 0 : T/10 : 5*T; 29 | z = 0 : d/100 : d; 30 | 31 | V = zeros(size(z)); 32 | 33 | for i=1:length(t), 34 | for k=1:length(z), 35 | V(k) = ustep(t(i)-z(k)/c) + (b1/a + (b0-b1/a)*exp(-a*(t(i)+z(k)/c-2*T)))*ustep(t(i)+z(k)/c-2*T); 36 | end 37 | 38 | plot(z, V, 'r'); 39 | 40 | xlim([0,d]); ylim([0,2.1]); xtick(0:0.25:1); 41 | xlabel('z'); 42 | grid; 43 | 44 | F(i) = getframe; 45 | end 46 | 47 | movie(F,1,4); 48 | 49 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/TDRmovie.m: -------------------------------------------------------------------------------- 1 | % TDRmovie.m - fault location by time-domain reflectometry 2 | % based on Problem 9.31 3 | % 4 | 5 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 6 | 7 | clear all; 8 | 9 | d1 = 6; c = 1; T1 = d1/c; 10 | d2 = 4; T2 = d2/c; 11 | 12 | T = T1+T2; 13 | d = d1+d2; 14 | 15 | a = 1; 16 | 17 | type = input('enter type = 1,2,3,4,5,6 for shunt C, series C, shunt L, series L, shunt R, series R \n type = '); 18 | 19 | if type==1, 20 | b0 = -1; b1 = 0; q = 1; p = 1; % p = 1 for shunt, -1 for series 21 | elseif type==2, 22 | b0 = 0; b1 = a; q = 1; p = -1; % q = 1 for C,L and q=0 for R 23 | elseif type==3, 24 | b0 = 0; b1 = -a; q = 1; p = 1; 25 | elseif type==4, 26 | b0 = 1; b1 = 0; q = 1; p = -1; 27 | elseif type==5, 28 | b0 = -1; b1 = 0; q = 0; p = 1; 29 | elseif type==6, 30 | b0 = 1; b1 = 0; q=0; p = 1; 31 | else 32 | disp('wrong type'); return; 33 | end 34 | 35 | 36 | t = 0 : T/40 : 3*T; 37 | z = 0 : d/100 : d; 38 | 39 | V = zeros(size(z)); 40 | 41 | for i=1:length(t), 42 | for k=1:length(z), 43 | if z(k) <= d1, 44 | V(k) = ustep(t(i)-z(k)/c) + (b1/a + (b0-b1/a)*exp(-q*a*(t(i)+z(k)/c-2*T1)))*ustep(t(i)+z(k)/c-2*T1); 45 | else 46 | V(k) = (1+p*b1/a + p*(b0-b1/a)*exp(-q*a*(t(i)-z(k)/c))) * ustep(t(i)-z(k)/c); 47 | end 48 | end 49 | 50 | plot(z, V, 'b'); 51 | 52 | xlim([0,d]); ylim([0,4]); xtick(0:1:d); ytick(0:1:4); 53 | xlabel('z'); 54 | 55 | line([d1,d1],[0,4],'linestyle', '--'); 56 | 57 | F(i) = getframe; 58 | end 59 | 60 | movie(F,1,4); 61 | 62 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/dipmovie.m: -------------------------------------------------------------------------------- 1 | % dipmovie.m - dipole radiation movie 2 | % based on Example 13.5.1 3 | 4 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 5 | 6 | [r,th] = meshgrid(linspace(1/8,3,61), linspace(0,pi,61)); 7 | 8 | u = 2*pi*r; 9 | [z,x] = pol2cart(th,r); 10 | 11 | for i=0:63, 12 | d = 2*pi*i/64; % one period [0,T] in increments of T/64 13 | 14 | C = (cos(u-d)./u + sin(u-d)) .* sin(th).^2; % contour levels 15 | contour([-x; x], [z; z], [C; C], 8); % 8 levels 16 | 17 | colormap([0,0,0]); axis('square'); 18 | xlim([-3,3]); ylim([-3,3]); 19 | xtick(-3:3); ytick(-3:3); 20 | line([0,0],[-1/16,1/16],'linewidth',2); 21 | 22 | M(i+1) = getframe; 23 | end 24 | 25 | movie(M,8); % play movie 8 times - equivalent to 8 periods 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grv1frame.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grv1frame.mat -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grv2frame.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grv2frame.mat -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grvmovie1.m: -------------------------------------------------------------------------------- 1 | % grvmovie1.m - movie of pulse propagating through regions of subluminal and 2 | % negative group velocity (vg<0) 3 | % 4 | % described in Section 3.9 of the text 5 | 6 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 7 | % 8 | % requires MATLAB v.7 9 | % 10 | % generated with grvmov1.m 11 | 12 | load grv1frame; 13 | 14 | figure; 15 | 16 | xlim([-2,6]); xtick([0,1,3,4]); 17 | ylim([0, 1]); ytick(0:1:1); 18 | 19 | movie(grv1frame,4,8); 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/grvmovie2.m: -------------------------------------------------------------------------------- 1 | % grvmovie2.m - movie of pulse propagating through regions of subluminal and 2 | % superluminal group velocity (vg>c) 3 | % 4 | % described in Section 3.9 of the text 5 | 6 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 7 | % 8 | % requires MATLAB v.7 9 | % 10 | % generated with grvmov2.m 11 | 12 | load grv2frame; 13 | 14 | figure; 15 | 16 | xlim([-2,6]); xtick([0,1,3,4]); 17 | ylim([0, 1]); ytick(0:1:1); 18 | 19 | movie(grv2frame,4,8); 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/movies/pulsemovie.m: -------------------------------------------------------------------------------- 1 | % pulsemovie.m - movie of step or pulse propagating along a terminated line 2 | % based on Example 9.15.1 3 | 4 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 5 | 6 | clear all; 7 | 8 | d = 1; c=1; T = d/c; 9 | 10 | p = input('\nenter 0,1,2,3 for unit-step, rectangular, trapezoidal, or triangular pulse input = '); 11 | 12 | if p==0, 13 | td = 0; tr = 0; 14 | elseif p==1, 15 | td = T/10; tr = 0; 16 | elseif p==2, 17 | td = T/10; tr = T/10; 18 | else 19 | td = 0; tr = T/10; 20 | end 21 | 22 | VG = 10; 23 | Z0 = 50; ZG = 450; ZL = 150; 24 | V0 = VG * Z0 / (ZG+Z0); 25 | Vinf = VG * ZL / (ZG + ZL); 26 | gG = z2g(ZG,Z0); gL = z2g(ZL,Z0); 27 | 28 | t = 0 : T/10 : 10*T; 29 | z = 0 : d/100 : d; 30 | 31 | V = zeros(size(z)); 32 | 33 | for i=1:length(t), 34 | for k=1:length(z), 35 | M = floor((t(i)-z(k)/c)/(2*T)); 36 | N = floor((t(i)+z(k)/c - 2*T)/(2*T)); 37 | if M >=0, % forward wave 38 | m = 0:M; 39 | V(k) = V0 * sum((gG * gL).^m .* upulse(t(i)-2*m*T - z(k)/c, td, tr)); 40 | end 41 | if N >= 0, % backward wave 42 | n = 0:N; 43 | V(k) = V(k) + gL * V0 * sum((gG * gL).^n .* upulse(t(i)-2*n*T - 2*T + z(k)/c, td, tr)); 44 | end 45 | end 46 | 47 | plot(z, V, 'b-'); 48 | 49 | xlim([0,d]); ylim([-3,3]); xtick(0:d/2:d); 50 | xlabel('z'); 51 | line([0,d], [Vinf,Vinf], 'linestyle', '--'); 52 | 53 | F(i) = getframe; 54 | end 55 | 56 | movie(F,1,4); % play movie once at 4 frames/sec 57 | 58 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/mstripa.m: -------------------------------------------------------------------------------- 1 | % mstripa.m - microstrip analysis (calculates Z,eff from w/h) 2 | % 3 | % Usage: [eff,Z] = mstripa(er,u) 4 | % 5 | % er = relative permittivity of substrate 6 | % u = width-to-height ratio = w/h 7 | % 8 | % eff = effective permittivity 9 | % Z = characteristic impedance of line 10 | % 11 | % notes: velocity factor = 1/sqrt(eff) 12 | % 13 | % can calculate a vector of Z's and eff's from a vector of u's 14 | % 15 | % uses Hammerstad and Jensen emprical formulas from Ref.: 16 | % E. O. Hammerstad and O. Jensen, 17 | % "Accurate Models for Microstrip Computer-Aided Design", 18 | % IEEE MTT-S Digest Int. Microwave Symp., 1980, p.407. 19 | % 20 | % accuracy is better than 0.2% over 0.01 <= u <= 100 and er <= 128 21 | % 22 | % see also mstrips for microstrip synthesis 23 | 24 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 25 | 26 | function [eff,Z] = mstripa(er,u) 27 | 28 | if nargin==0, help mstripa; return; end 29 | 30 | eta = etac(1); 31 | 32 | a = 1 + log((u.^4 + (u/52).^2)./(u.^4 + 0.432))/49 + log(1 + (u/18.1).^3)/18.7; 33 | b = 0.564*((er-0.9)/(er+3))^0.053; 34 | F = 6 + (2*pi-6)*exp(-(30.666./u).^0.7528); 35 | 36 | eff = 0.5*(er+1) + 0.5*(er-1)*(1 + 10./u).^(-a*b); 37 | 38 | Z = eta/(2*pi) * log(F./u + sqrt(1+(2./u).^2)) ./sqrt(eff); 39 | 40 | 41 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/mstripr.m: -------------------------------------------------------------------------------- 1 | % mstripr.m - microstrip synthesis with refinement (calculates w/h from Z) 2 | % 3 | % Usage: [u,N] = mstripr(er,Z0,per) 4 | % [u,N] = mstripr(er,Z0) (equivalent to per=0.2) 5 | % 6 | % er = relative permittivity of substrate 7 | % Z0 = desired characteristic impedance 8 | % per = percent accuracy for Z0 and u, typically, 0.1 per, 31 | if Z<=Z0, % Z is a decreasing function of u 32 | u = (1-per)*u; % corrected u 33 | else 34 | u = (1+per)*u; 35 | end 36 | [eff,Z] = mstripa(er,u); % corrected Z 37 | N = N+1; 38 | if N>Nmax, 39 | u = mstrips(er,Z0); % convergence failed, use initial value 40 | break; 41 | end 42 | end 43 | 44 | 45 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/mstrips.m: -------------------------------------------------------------------------------- 1 | % mstrips.m - microstrip synthesis (calculates w/h from Z) 2 | % 3 | % Usage: u = mstrips(er,Z) 4 | % 5 | % er = relative permittivity of substrate 6 | % Z = desired characteristic impedance 7 | % 8 | % u = width-to-height ratio = w/h 9 | % 10 | % notes: can calculate a vector of u's from a vector of Z's 11 | % 12 | % accuracy is better than 1% 13 | % 14 | % see also mstripa for microstrip analysis 15 | 16 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function u = mstrips(er,Z) 19 | 20 | if nargin==0, help mstrips; return; end 21 | 22 | eta = etac(1); 23 | 24 | A = pi*sqrt(2*(er+1)) * Z/eta + (er-1)/(er+1) * (0.23 + 0.11/er); 25 | B = pi*eta./(2*Z*sqrt(er)); 26 | 27 | u1 = 4./(exp(A)/2 - exp(-A)); 28 | u2 = (er-1)/(pi*er) * (log(B-1) + 0.39 - 0.61/er) + 2/pi * (B - 1 - log(2*B-1)); 29 | 30 | u = u1.*(u1<=2) + u2.*(u2>2); 31 | 32 | 33 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/multibeam.m: -------------------------------------------------------------------------------- 1 | % multibeam.m - multi-beam array 2 | % 3 | % Usage: a = multibeam(d, w, A, ph0) 4 | % 5 | % d = element spacing in units of lambda 6 | % w = row vector of window weights (even or odd length N) 7 | % A = row vector of relative beam amplitudes (L amplitudes) 8 | % ph0 = row vector of beam angles in degrees (L angles) 9 | % 10 | % a = multi-beam array weight vector (length N) 11 | % 12 | % notes: a is already scanned towards the various ph0's, 13 | % the weights w can be built with UNIFORM, BINOMIAL, TAYLOR, DOLPH, 14 | % essentially, the DSP equivalent of multiple sinusoids 15 | % 16 | % example: w = dolph(0.5, 90, 21, 30); 17 | % a = multibeam(0.5, w, [1,1,1], [60, 90, 150]); 18 | % [g,phi] = array(0.5, a, Nph); 19 | % dbz(phi,g); 20 | 21 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 22 | 23 | function a = multibeam(d, w, A, ph0) 24 | 25 | if nargin==0, help multibeam; return; end 26 | 27 | N = length(w); % number of array elements 28 | L = length(A); % number of beams 29 | 30 | a = zeros(1, N); 31 | 32 | for i=1:L, 33 | a = a + A(i) * steer(d, w, ph0(i)); % accumulate steered w's 34 | end 35 | 36 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/n2r.m: -------------------------------------------------------------------------------- 1 | % n2r.m - refractive indices to reflection coefficients of M-layer structure 2 | % 3 | % Usage: r = n2r(n) 4 | % 5 | % n = refractive indices = [na,n(1),...,n(M),nb] 6 | % r = reflection coefficients = [r(1),...,r(M+1)] 7 | % 8 | % notes: there are M layers, M+1 interfaces, and M+2 media 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function r = n2r(n) 13 | 14 | if nargin==0, help n2r; return; end 15 | 16 | r = -diff(n) ./ (2*n(1:end-1) + diff(n)); 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/nfcirc.m: -------------------------------------------------------------------------------- 1 | % nfcirc.m - constant noise figure circle 2 | % 3 | % Usage: [c,r] = nfcirc(F,Fmin,rn,gGopt) 4 | % 5 | % F = desired noise figure in dB (must be F>=Fmin) 6 | % Fmin = minimum noise figure in dB 7 | % rn = normalized noise resistance Rn/Z0 8 | % gGopt = optimum source reflection coefficient corresponding to Fmin 9 | % 10 | % c,r = center and radius of constant noise figure circle 11 | 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function [c,r] = nfcirc(F,Fmin,rn,gGopt) 15 | 16 | if nargin==0, help nfcirc; return; end 17 | 18 | F = 10^(F/10); Fmin = 10^(Fmin/10); 19 | 20 | N = (F-Fmin) * abs(1+gGopt)^2 / (4*rn); 21 | 22 | c = gGopt / (N+1); 23 | 24 | r = sqrt(N^2+N*(1-abs(gGopt)^2)) / (N+1); 25 | 26 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/nfig.m: -------------------------------------------------------------------------------- 1 | % nfig.m - noise figure of two-port 2 | % 3 | % Usage: F = nfig(Fmin, rn, gGopt, gG); 4 | % 5 | % Fmin = minimum noise figure in dB 6 | % rn = normalized noise resistance Rn/Z0 7 | % gGopt = optimum source reflection coefficient corresponding to Fmin 8 | % gG = actual source reflection coefficient 9 | % 10 | % F = noise figure in dB 11 | 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function F = nfig(Fmin, rn, gGopt, gG) 15 | 16 | if nargin==0, help nfig; return; end 17 | 18 | Fmin = 10^(Fmin/10); 19 | 20 | F = Fmin + 4*rn*abs(gG - gGopt).^2 ./ (abs(1+gGopt)^2*(1-abs(gG).^2)); 21 | 22 | F = 10*log10(F); 23 | 24 | 25 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/onesect.m: -------------------------------------------------------------------------------- 1 | % onesect.m - one-section impedance transformer 2 | % 3 | % -----------------=====L1=====| 4 | % main line Z0 Z1 ZL 5 | % -----------------============| 6 | % 7 | % Usage: [Z1,L1] = onesect(ZL,Z0) 8 | % 9 | % ZL = complex load impedance = RL + jXL 10 | % Z0 = main line impedance 11 | % 12 | % Z1 = section impedance 13 | % L1 = electrical length of section 14 | % 15 | % notes: a solution with real Z1 always exists if ZL is real 16 | % 17 | % no real Z1 exists if Z0 is in the interval [RL, RL + XL^2/RL] 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function [Z1,L1] = onesect(ZL,Z0) 22 | 23 | if nargin==0, help onesect; return; end 24 | 25 | RL = real(ZL); 26 | XL = imag(ZL); 27 | 28 | if (Z0 >= RL) & (Z0 <= RL + XL^2/RL), 29 | fprintf('\nno solution exists\n\n'); 30 | return; 31 | end 32 | 33 | Z1 = sqrt(Z0*RL - Z0*XL^2/(Z0-RL)); 34 | 35 | L1 = atan(Z1*(Z0-RL)/Z0/XL)/2/pi; 36 | 37 | L1 = mod(L1,0.5); 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/p2c.m: -------------------------------------------------------------------------------- 1 | % p2c.m - phasor form to complex number 2 | % 3 | % Usage: z = p2c(mag,phase) 4 | % 5 | % mag = magnitudes of the vector of z's (column or row) 6 | % phase = phases of z's in degrees (column or row) 7 | % 8 | % z = vector of complex numbers (column) 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function z = p2c(mag,phase) 13 | 14 | if nargin==0, help p2c; return; end 15 | 16 | z = mag(:) .* exp(j*phase(:)*pi/180); 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/pi2t.m: -------------------------------------------------------------------------------- 1 | % pi2t.m - Pi to T transformation 2 | % 3 | % Usage: Zabc = pi2t(Z123) 4 | % 5 | % Z123 = impedances of Pi network = [Z1,Z2,Z3] 6 | % Zabc = impedances of T network = [Za,Zb,Zc] 7 | % 8 | % notes: Z123 and Zabc are Lx3 matrices, for transforming several cases at once 9 | % 10 | % the transformation equations are: 11 | % 12 | % Za = Z2*Z3/U, Zb = Z3*Z1/U, Zc = Z1*Z2/U, where U = Z1 + Z2 + Z3 13 | % 14 | % Z1 = V/Za, Z2 = V/Zb, Z3 = V/Zc, where V = Za*Zb + Zb*Zc + Zc*Za 15 | % 16 | % ---|----[Z2]----|--- ---[Zc]----|----[Za]--- 17 | % | | | 18 | % [Z1] [Z3] ==> [Zb] 19 | % | | | 20 | % ---|------------|--- -----------|------------ 21 | % 22 | % see also t2pi for the reverse transformation 23 | 24 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 25 | 26 | function Zabc = pi2t(Z123) 27 | 28 | if nargin==0, help pi2t; return; end 29 | 30 | Z1 = Z123(:,1); Z2 = Z123(:,2); Z3 = Z123(:,3); 31 | 32 | U = Z1 + Z2 + Z3; 33 | 34 | Za = Z2.*Z3./U; 35 | Zb = Z3.*Z1./U; 36 | Zc = Z1.*Z2./U; 37 | 38 | Zabc = [Za,Zb,Zc]; 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/pmat.m: -------------------------------------------------------------------------------- 1 | % pmat.m - Pocklington impedance matrix with method of moments and point-matching 2 | % 3 | % Usage: [Zbar,B] = pmat(L,a,M,ker,basis) 4 | % 5 | % L = antenna length in wavelengths 6 | % a = antenna radius in wavelengths 7 | % M = defines the number of segments to be N = 2M+1 8 | % ker = 'e' or 'a , for exact or approximate kernel 9 | % basis = 'p', 't', 'n', 'd', for pulse, triangular, NEC, or delta-function basis 10 | % 11 | % Zbar = (2M-1)x(2M-1) impedance matrix Zbar(n,m) 12 | % B = (2M+1)x(2M+1) tridiagonal basis-transformation matrix (relevant in NEC basis only) 13 | % 14 | % see pfield for solving Pocklington's equation (pfield includes pmat's code explictly) 15 | 16 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function [Zbar,B] = pmat(L,a,M,ker,basis) 19 | 20 | if nargin==0, help pmat; return; end 21 | if nargin==3, ker='e'; basis='p'; end 22 | if nargin==4, basis='p'; end 23 | 24 | k = 2*pi; % k = 2*pi/lambda, (lambda=1 units) 25 | N = 2*M+1; 26 | 27 | if basis=='t', 28 | D = L/(2*M); % sample spacing for triangular basis 29 | else 30 | D = L/(2*M+1); % sample spacing for pulse and NEC bases 31 | end 32 | 33 | [Z,B] = hmat(L,a,M,ker,basis); % Hallen impedance matrix Z, 34 | % basis transformation matrix B 35 | alpha = k^2*D^2 - 2; 36 | d = 2*k*D^2; 37 | u1 = ones(1,N-2); 38 | A = alpha * diag([0,u1,0],0) + diag([0,u1],1) + diag([u1,0],-1); 39 | 40 | Zbar = A*Z/B; 41 | 42 | Zbar = Zbar(2:N-1,2:N-1); % extract middle portion 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/pmatch.m: -------------------------------------------------------------------------------- 1 | % pmatch.m - Pi-section reactive conjugate matching network 2 | % 3 | % Usage: X123 = pmatch(ZG,ZL,Z) 4 | % 5 | % ZG = generator impedance = RG+jXG 6 | % ZL = load impedance = RL+jXL 7 | % Z = reference impedance = R+jX, must have R < min(RG,RL) 8 | % 9 | % X123 = [X1,X2,X3] = 4x3 matrix of reactances of Pi network (four solutions) 10 | % 11 | % notes: matching network has input impedance Zin = conj(ZG), 12 | % 13 | % o-----|----[jX2]----|-------| 14 | % | | | 15 | % Zin -> [jX1] [jX3] [ZL] 16 | % | | | 17 | % o-----|-------------|-------| 18 | % 19 | % calculate R in terms of Q, or the improved Q0, as follows: 20 | % R = max(RG,RL)/(Q^2+1), or, 21 | % R = (RG-RL)^2/((RG+RL)*Q0 - 2*Q0*sqrt(RG*RL*Q0^2-(RG-RL)^2)) 22 | 23 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 24 | 25 | function X123 = pmatch(ZG,ZL,Z) 26 | 27 | if nargin==0, help pmatch; return; end 28 | 29 | if real(Z) >= min(real(ZG), real(ZL)), 30 | fprintf('\nmust have R < min(RG,RL)\n\n'); 31 | return; 32 | end 33 | 34 | X14 = lmatch(ZG,Z,'n'); 35 | X35 = lmatch(conj(Z),ZL,'r'); 36 | 37 | X123 = [X14(1,1), X14(1,2) + X35(1,2), X35(1,1); ... 38 | X14(2,1), X14(2,2) + X35(2,2), X35(2,1); ... 39 | X14(1,1), X14(1,2) + X35(2,2), X35(2,1); ... 40 | X14(2,1), X14(2,2) + X35(1,2), X35(1,1)]; 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/poly2.m: -------------------------------------------------------------------------------- 1 | % poly2.m - specialized version of poly 2 | % 3 | % Usage: a=poly2(z) 4 | % 5 | % z = row vector of zeros 6 | % a = row vector of coefficients of polynomial with zeros z 7 | % 8 | % notes: functionally equivalent to a = poly(z), but with increased 9 | % accuracy when used in Chebyshev transformer and Chebyshev array designs 10 | % 11 | % used in chebtr, chebtr2, chebtr3, dolph, dolph2, dolph3 12 | % 13 | % poly is accurate up to order of about 50-60 in such designs, 14 | % whereas poly2's accuracy is up to order of about 3000 15 | % 16 | % because in Chebyshev designs the corresponding zeros are almost 17 | % equally-spaced around the unit circle and successive zeros get closer 18 | % to each other with increasing order, poly2's strategy is to regroup the 19 | % zeros in subgroups of length up to 50 such that within each subgroup the 20 | % zeros are not as close to each other, then compute the polynomials of 21 | % each subgroup using poly, and convolve them to get the overall polynomial 22 | 23 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 24 | 25 | function a = poly2(z) 26 | 27 | if nargin==0, help poly2; return; end 28 | 29 | M = length(z); 30 | 31 | r = ceil(M/50); % number of subgroups of zeros 32 | 33 | a=1; 34 | 35 | for i=1:r, % get subgroup polynomials and 36 | a = conv(a, poly(z(i:r:end))); % convolve them with each other 37 | end 38 | 39 | 40 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/prol.m: -------------------------------------------------------------------------------- 1 | % prol.m - prolate array design 2 | % 3 | % Usage: [a,dph] = prol(d,ph0,N,R) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees (broadside ph0=90) 7 | % N = number of array elements (odd or even) 8 | % R = relative sidelobe level in dB (13 0, use 1/8 shorted, or, 3/8 opened (Ystub = -jY2) 25 | % Z2 < 0, use 3/8 shorted, or, 1/8 opened (Ystub = jY2) 26 | % 27 | % for a balanced stub use impedance 2*Z2 for each stub leg 28 | 29 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 30 | 31 | function [Z1,Z2] = qwt2(ZL,Z0) 32 | 33 | if nargin==0, help qwt2; return; end 34 | 35 | GL = real(1/ZL); 36 | BL = imag(1/ZL); 37 | 38 | Z1 = sqrt(Z0/GL); 39 | Z2 = 1/BL; 40 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/qwt3.m: -------------------------------------------------------------------------------- 1 | % qwt3.m - quarter wavelength transformer with shunt stub of adjustable length 2 | % 3 | % ---------------==========----|--| 4 | % main line Z0 Z1 | ZL 5 | % ---------------==========-|--|--| 6 | % L1=1/4 | | 7 | % |Z2| d 8 | % |__| shorted or opened 9 | % 10 | % Usage: [Z1,d] = qwt3(ZL,Z0,Z2,type) 11 | % [Z1,d] = qwt3(ZL,Z0,Z2) (equivalent to type='s') 12 | % 13 | % ZL = complex load impedance 14 | % Z0 = impedance of main line 15 | % Z2 = impedance of shunt stub (usually Z2=Z0) 16 | % type = 's','o' for shorted or opened stub 17 | % 18 | % Z1 = impedance of 1/4-wavelength segment 19 | % d = stub length (in units of lambda) 20 | % 21 | % notes: Stub susceptance cancels load susceptance 22 | % 23 | % Design method: 24 | % Y = YL+Ystub = (GL+jBL) - jYd*cot(bd), (or, Y = GL+jBL + jYd*tan(bd) for opened stub) 25 | % cot(bd) = BL*Z2, (or, tan(bd) = -BL*Z2) 26 | % Z1 = sqrt(Z0/GL) 27 | % 28 | % for a balanced stub, the length of each leg is: 29 | % d_bal = acot(cot(2*pi*d)/2) (shorted), d_bal = atan(tan(2*pi*d)/2) (opened) 30 | 31 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewaa 32 | 33 | function [Z1,d] = qwt3(ZL,Z0,Z2,type) 34 | 35 | if nargin==0, help qwt3; return; end 36 | if nargin==3, type='s'; end 37 | 38 | GL = real(1/ZL); 39 | BL = imag(1/ZL); 40 | 41 | if type=='s', 42 | d = acot(BL*Z2)/(2*pi); 43 | else 44 | d = atan(-BL*Z2)/(2*pi); 45 | end 46 | 47 | d = mod(d,0.5); 48 | 49 | Z1 = sqrt(Z0/GL); 50 | 51 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/r2d.m: -------------------------------------------------------------------------------- 1 | % r2d.m - radians to degrees 2 | % 3 | % y = r2d(x) 4 | % 5 | % see also d2r.m 6 | 7 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 8 | 9 | function y=r2d(x) 10 | 11 | if nargin==0, help r2d; return; end 12 | 13 | y = x * 180 / pi; 14 | 15 | 16 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/r2n.m: -------------------------------------------------------------------------------- 1 | % r2n.m - reflection coefficients to refractive indices of M-layer structure 2 | % 3 | % Usage: n = r2n(r) 4 | % 5 | % r = reflection coefficients = [r(1),...,r(M+1)] 6 | % n = refractive indices = [na,n(1),...,n(M),nb] 7 | % 8 | % notes: there are M layers, M+1 interfaces, and M+2 media 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function n = r2n(r) 13 | 14 | if nargin==0, help r2n; return; end 15 | 16 | M = length(r)-1; % number of layers 17 | 18 | n = 1; 19 | ni = 1; 20 | 21 | for i=1:M+1, 22 | ni = ni * (1-r(i))/(1+r(i)); 23 | n = [n,ni]; 24 | end 25 | 26 | 27 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/resonant.m: -------------------------------------------------------------------------------- 1 | % resonant.m - length of resonant dipole antenna 2 | % 3 | % Usage: [L,Z] = resonant(a) 4 | % 5 | % a = radius of dipole (in wavelengths) 6 | % 7 | % L = length of dipole (in wavelengths) 8 | % Z = resistive self-impedance 9 | % 10 | % notes: Given the radius a, it finds the length L, such that 11 | % the dipole impedance Z = R+jX = imped(L,a) has zero 12 | % reactive part, X=0 13 | % 14 | % works only for antenna lengths near half-wavelength 15 | % 16 | % it uses the function IMPED and does binary search 17 | % in the interval [0.4,0.5] 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewaa 20 | 21 | 22 | function [L,Z] = resonant(a) 23 | 24 | if nargin==0, help resonant; return; end 25 | 26 | La = 0.4; Lb = 0.5; 27 | 28 | N = 64; 29 | 30 | for i=1:N, 31 | L = (La+Lb)/2; 32 | Z = imped(L,a); 33 | if imag(Z) > 0, Lb = L; else, La = L; end 34 | end 35 | 36 | Z = real(Z); 37 | 38 | 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/rhombic.m: -------------------------------------------------------------------------------- 1 | % rhombic.m - gain of traveling-wave rhombic antenna 2 | % 3 | % Usage: [g, th, c, th0] = rhombic(L, alpha, Nth); 4 | % 5 | % L is in units of lambda (L=0 not allowed) 6 | % alpha = vee half-angle in degrees 7 | % 8 | % g = g(th) 9 | % th = Nth+1 equally-spaced polar angles in [0,pi] = (0:Nth)*pi/Nth 10 | % c = unity-max normalization constant 11 | % th0 = acos(1 - 0.371/L) = direction of main lobe in degrees. 12 | % 13 | % (alpha*Nth/360 must not be an integer) 14 | % 15 | % see also DIPOLE, TRAVEL, VEE 16 | 17 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 18 | 19 | function [g, th, c, th0] = rhombic(L, alpha, Nth) 20 | 21 | if nargin==0, help rhombic; return; end 22 | 23 | th = (0 : Nth) * pi / Nth; 24 | 25 | alpha = alpha * pi / 180; 26 | 27 | th1 = th - alpha; 28 | th2 = th + alpha; 29 | 30 | F1 = sin(th1) .* (1 - exp(-j*2*pi*L*(1-cos(th1)))) ./ (1 - cos(th1)); 31 | F2 = sin(th2) .* (1 - exp(-j*2*pi*L*(1-cos(th2)))) ./ (1 - cos(th2)); 32 | 33 | F3 = exp(j*2*pi*L*cos(th2)) .* F1; % arm-3 is parallel to arm-1 34 | F4 = exp(j*2*pi*L*cos(th1)) .* F2; % arm-4 is parallel to arm-2 35 | 36 | g = abs(F2 - F1 + F3 - F4).^2; 37 | 38 | c = 1 / max(g); 39 | 40 | g = c * g; 41 | 42 | th0 = acos(1 - 0.371/L) * 180 / pi; 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/scan.m: -------------------------------------------------------------------------------- 1 | % scan.m - scan array with given scanning phase 2 | % 3 | % Usage: ascan = scan(a, ps0) 4 | % 5 | % a = array weights to be scanned (must be row vector) 6 | % ps0 = scanning phase in radians 7 | % 8 | % ascan = scanned weights (row vector) 9 | % 10 | % notes: multiplies array weights by progressive phase, 11 | % ascan(n) = a(n) * exp(-j*(n-(N-1)/2)*ps0), n = 0,1,...,N-1 12 | % ps0 can be any phase, even outside visible region, 13 | % STEER is a special case of SCAN, that is, 14 | % steer(d, a, ph0) = scan(a, 2*pi*d*cos(ph0)) 15 | % 16 | % see also STEER, ARRAY 17 | 18 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 19 | 20 | function ascan = scan(a, ps0) 21 | 22 | if nargin==0, help scan; return; end 23 | 24 | N = length(a); 25 | 26 | m = (0:N-1) - (N-1)/2; % m varies over [-(N-1)/2, (N-1)/2] 27 | 28 | ascan = a .* exp(-j*m*ps0); 29 | 30 | 31 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/sinhc.m: -------------------------------------------------------------------------------- 1 | % sinhc.m - hyperbolic sinc function 2 | % 3 | % y = sinhc(x) 4 | % 5 | % evaluates the function y = sinh(pi*x)/(pi*x) 6 | % at any vector of x's 7 | % 8 | % Notes: needed in Taylor 1-parameter array design 9 | % 10 | % see als its inverse, asinhc 11 | 12 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 13 | 14 | function y = sinhc(x) 15 | 16 | if nargin==0, help sinhc; return; end 17 | 18 | y = ones(size(x)); 19 | 20 | i = find(x~=0); 21 | 22 | y(i) = sinh(pi*x(i))./(pi*x(i)); 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/smat.m: -------------------------------------------------------------------------------- 1 | % smat.m - S-parameters to S-matrix 2 | % 3 | % Usage: S = smat(sparam) 4 | % 5 | % sparam = [mag11, ang11, mag21, ang21, mag12, ang12, mag22, ang22] 6 | % = magnitudes (in absolute units) and angles (in degrees) 7 | % 8 | % S = 2x2 scattering matrix 9 | % 10 | % notes: S-parameters usually listed in the above order in data sheets 11 | % 12 | % S21 is listed before S12 13 | % 14 | % reshapes sparam as follows: 15 | % 16 | % [mag11, ang11 [mag11 * exp(j*ang11*pi/180) 17 | % mag21, ang21 ==> mag21 * exp(j*ang21*pi/180) ==> 2x2 S-matrix 18 | % mag12, ang12 mag12 * exp(j*ang12*pi/180) 19 | % mag22, ang22] mag22 * exp(j*ang22*pi/180)] 20 | 21 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 22 | 23 | function S = smat(sparam) 24 | 25 | if nargin==0, help smat; return; end 26 | 27 | sparam = reshape(sparam,2,4)'; 28 | 29 | S = reshape(sparam(:,1).*exp(j*sparam(:,2)*pi/180), 2,2); 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/smatch.m: -------------------------------------------------------------------------------- 1 | % smatch.m - simultaneous conjugate match of a two-port 2 | % 3 | % Usage: [gG,gL] = smatch(S) 4 | % 5 | % S = 2x2 scattering matrix of two-port (must be unconditionally stable) 6 | % 7 | % gG,gL = generator and load reflection coefficients 8 | % 9 | % notes: ZG and ZL can be computed from ZG = g2z(gG,Z0), ZL = g2z(gL,Z0) 10 | 11 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function [gG,gL] = smatch(S) 14 | 15 | if nargin==0, help smatch; return; end 16 | 17 | D = det(S); 18 | 19 | [K,mu,D,B1,B2,C1,C2] = sparam(S); 20 | 21 | if K < 1, 22 | fprintf('\nsimultaneous conjugate match does not exist\n\n'); 23 | return; 24 | end 25 | 26 | gG = (B1 - sign(B1) * sqrt(B1^2 - 4*abs(C1)^2)) / (2*C1); 27 | gL = (B2 - sign(B2) * sqrt(B2^2 - 4*abs(C2)^2)) / (2*C2); 28 | 29 | 30 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/smith.m: -------------------------------------------------------------------------------- 1 | % smith.m - draw basic Smith chart 2 | % 3 | % Usage: smith(n) 4 | % smith (equivalent to n=3) 5 | % 6 | % n = 1,2,3,4, number of resistance/reactance circles (default n=3) 7 | % 8 | % notes: uses smitchcir to draw all circles 9 | 10 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 11 | 12 | function smith(n) 13 | 14 | if nargin==0, n=3; end 15 | 16 | clf; axis('equal'); axis('off'); hold on; 17 | 18 | maxG=1; width=1; % maxG=1 keeps all circles inside unit-circle 19 | 20 | switch n, 21 | case 1, 22 | r = 1; 23 | x = 1; 24 | case 2, 25 | r = [1, 2]; 26 | x = [1, 2]; 27 | case 3, 28 | r = [1/3, 1, 3]; 29 | x = [sqrt(2)-1, 1, 1+sqrt(2)]; 30 | case 4, 31 | r = [0.2, 0.5, 1, 2]; 32 | x = [0.2, 0.5, 1, 2]; 33 | otherwise 34 | disp('use n=1,2,3,4 only'); close; return; 35 | end 36 | 37 | x = [x, -x]; % positive and negative reactances 38 | 39 | Cr = r./(1+r); % centers and radii of resistance circles 40 | Rr = 1./(1+r); 41 | maxGr = ones(1,length(Cr)); 42 | 43 | Cx = 1 + j./x; % centers and radii of reactance cricles 44 | Rx = 1./abs(x); 45 | maxGx = ones(1,length(Cx)); 46 | 47 | smithcir(0,1,maxG,width); % add unit-circle 48 | smithcir(Cr,Rr,maxGr,width); % add resistance circles 49 | smithcir(Cx,Rx,maxGx,width) % add reactance circles 50 | 51 | line([-1,1], [0,0]); % add horizontal axis 52 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/smithcir.m: -------------------------------------------------------------------------------- 1 | % smithcir.m - add stability and constant gain circles on Smith chart 2 | % 3 | % Usage: smithcir(c,r,maxG,width) 4 | % smithcir(c,r,maxG) (equivalent to width=1) 5 | % smithcir(c,r) (equivalent to width=1, maxG=r+|c|) 6 | % 7 | % c,r = vectors of centers and radii of circles 8 | % maxG = display portion of circle with |Gamma| <= maxG, must have same dimension as c and r 9 | % 10 | % notes: a basic Smith chart must be drawn first, e.g., with smith 11 | % then smithcir can be called to draw a gain or stability circle 12 | % 13 | % maxG = r+|c| draws entire circle 14 | % 15 | % center can be displayed by plot(c,'.') 16 | % 17 | % join c to origin with line([0,real(c)],[0,imag(c)]) 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function smithcir(c,r,maxG,width) 22 | 23 | if nargin==0, help smithcir; return; end 24 | if nargin<=3, width=1; end 25 | if nargin==2, maxG = r+abs(c); end 26 | 27 | phi = linspace(0, 2*pi, 1800); % spacing at 1/5 of a degree 28 | z = exp(j*phi); 29 | 30 | for i=1:length(c), 31 | gamma = c(i) + r(i)*z; % points around i-th circle 32 | k = find(abs(gamma)<=maxG(i)); % find subset of gamma's to plot 33 | gamma = gamma(k); 34 | plot(gamma,'linewidth',width); % plot portion of circle with |gamma| <= maxG 35 | end 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/snel.m: -------------------------------------------------------------------------------- 1 | % snel.m - Calculates refraction angles from Snel's law for birefringent media 2 | % 3 | % Usage: thb = snel(na,nb,tha,pol) 4 | % thb = snel(na,nb,tha) (equivalent to pol='te') 5 | % 6 | % na,nb = refractive index vectors of (birefringent) media a,b, e.g., na = [na1,na2,na3] 7 | % tha = vector of angles of incidence in degrees from medium a 8 | % pol = 'te' or 'tm', for perpendicular or parallel (s or p) polarization 9 | % 10 | % thb = angles of refraction in medium b, in degrees 11 | % 12 | % notes: solves Snel's law Na*sin(tha) = Nb*sin(thb) for thb, 13 | % where Na,Nb are the effective indices, which are angle-dependent 14 | % for TM or p-polarization in non-isotropic media 15 | % 16 | % the media a,b do not have to be adjacent, 17 | % as long as they are part of the same multilayer structure 18 | % 19 | % the polarization type is the same in both media a,b 20 | % 21 | % for isotropic media, thb is the same for both polarizations 22 | % 23 | % see FRESNEL and BIREFR for coordinate and polarization conventions 24 | 25 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 26 | 27 | function thb = snel(na,nb,tha,pol) 28 | 29 | if nargin==0, help snel; return; end 30 | 31 | na = na(:); nb = nb(:); 32 | 33 | if length(na)==1, na=[na; na; na]; end % isotropic case 34 | if length(na)==2, na=[na(1);na(1); na(2)]; end % uniaxial case 35 | if length(nb)==1, nb=[nb; nb; nb]; end 36 | if length(nb)==2, nb=[nb(1); nb(1); nb(2)]; end 37 | 38 | tha = tha * pi/180; 39 | 40 | if pol=='tm', 41 | A = nb(1)^2 * nb(3)^2 * (na(1)^2 - na(3)^2) - na(1)^2 * na(3)^2 * (nb(1)^2 - nb(3)^2); 42 | B = nb(1)^2 * nb(3)^2 * na(3)^2; 43 | thb = asin(na(1)*na(3)*nb(3)*sin(tha)./sqrt(A*sin(tha).^2 + B)); 44 | else 45 | thb = asin(na(2)*sin(tha)/nb(2)); 46 | end 47 | 48 | thb = thb * 180/pi; 49 | 50 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/snv.m: -------------------------------------------------------------------------------- 1 | % snv.m - sn elliptic function at a vector of moduli 2 | % 3 | % Usage: w = snv(u,k) 4 | % 5 | % u = Lx1 column vector of complex numbers on the u-plane 6 | % k = 1xN row vector of elliptic moduli 7 | % 8 | % w = LxN matrix of values of sn(u*K,k), where K=K(k) 9 | % 10 | % Notes: u is in units of the quarterperiod K 11 | % 12 | % in terms of the elliptic function sn(z,k), the ij-th matrix element is 13 | % w(i,j) = sn(u(i)*K(j), k(j)) 14 | % where K(j) = K(k(j)) is the quarter period of the j-th modulus k(j) 15 | % 16 | % it uses the Landen/Gauss transformation of ascending moduli 17 | % with M=7 iterations to build the answer from w = sin(u*pi/2) 18 | % 19 | % k may not be equal to 1 20 | 21 | % Based on the function SNE of the reference: 22 | % Sophocles J. Orfanidis, "High-Order Digital Parametric Equalizer Design", 23 | % J. Audio Eng. Soc., vol.53, pp. 1026-1046, November 2005. 24 | % see also, http://www.ece.rutgers.edu/~orfanidi/hpeq/ 25 | % 26 | % uses vectorized the version LANDENV of LANDEN from this reference 27 | % 28 | % the j-th column w(:,j) is equivalent to the call w(:,j) = sne(u,k(j)) 29 | 30 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 31 | 32 | function w = snv(u,k) 33 | 34 | if nargin==0, help snv; return; end 35 | 36 | u = u(:); k = k(:)'; % u = column, k = row 37 | 38 | M = 7; 39 | 40 | v = landenv(k,M); % descending Landen moduli 41 | 42 | w = repmat(sin(u*pi/2), 1, length(k)); 43 | 44 | for i = 1:length(u), 45 | for n = M:-1:1, % ascending Landen/Gauss transformation 46 | w(i,:) = (1+v(n,:)).*w(i,:) ./ (1+v(n,:).*w(i,:).^2); 47 | end 48 | end 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/sparam.m: -------------------------------------------------------------------------------- 1 | % sparam.m - stability parameters of two-port 2 | % 3 | % Usage: [K,mu,D,B1,B2,C1,C2,D1,D2] = sparam(S) 4 | % 5 | % S = 2x2 scattering matrix of two-port 6 | % 7 | % K,mu,B1,B2 = stability parameters 8 | % D = abs(det(S)) 9 | % C1,C2,D1,D2 = related parameters 10 | % 11 | % notes: necessary and sufficient conditions for stability: 12 | % mu > 1, or 13 | % K > 1 and B1 > 0, or 14 | % K > 1 and B2 > 0, or 15 | % K > 1 and |D| < 1, D = det(S), or 16 | % K > 1 and |S12*S21| < 1-|S11|^2, or 17 | % K > 1 and |S12*S21| < 1-|S22|^2, or 18 | % 19 | % M. L. Edwards and J. H. Sinsky, "A New Criterion for Linear 2-Port Stability Using a Single 20 | % Geometrically-Derived Parameter," IEEE Trans. Microwave Th. Tech, MTT-40, 2303 (1992). 21 | 22 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 23 | 24 | function [K,mu,D,B1,B2,C1,C2,D1,D2] = sparam(S) 25 | 26 | if nargin==0, help sparam; return; end 27 | 28 | D = det(S); 29 | 30 | mu = (1 - abs(S(1,1))^2) / (abs(S(2,2) - D*conj(S(1,1))) + abs(S(1,2)*S(2,1))); 31 | 32 | B1 = 1 + abs(S(1,1))^2 - abs(S(2,2))^2 - abs(D)^2; 33 | 34 | B2 = 1 + abs(S(2,2))^2 - abs(S(1,1))^2 - abs(D)^2; 35 | 36 | if abs(S(1,2)*S(2,1))==0, 37 | K = Inf; 38 | else 39 | K = (1 - abs(S(1,1))^2 - abs(S(2,2))^2 + abs(D)^2)/abs(2*S(1,2)*S(2,1)); 40 | end 41 | 42 | C1 = S(1,1) - D * conj(S(2,2)); 43 | C2 = S(2,2) - D * conj(S(1,1)); 44 | 45 | D1 = abs(S(1,1))^2 - abs(D)^2; 46 | D2 = abs(S(2,2))^2 - abs(D)^2; 47 | 48 | D = abs(D); 49 | 50 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/sqrte.m: -------------------------------------------------------------------------------- 1 | % sqrte.m - evanescent SQRT for waves problems 2 | % 3 | % Usage: y = sqrte(z) 4 | % 5 | % z = array of complex numbers 6 | % y = square root of z 7 | % 8 | % Notes: for z = a-j*b, y is defined as follows: 9 | % 10 | % [ sqrt(a-j*b), if b~=0 11 | % y = [ sqrt(a), if b==0 and a>=0 12 | % [ -j*sqrt(|a|), if b==0 and a<0 (i.e., the negative of what the ordinary SQRT gives) 13 | % 14 | % this definition is necessary to produce exponentially-decaying evanescent waves 15 | % (under the convention exp(j*omega*t) for harmonic time dependence) 16 | % 17 | % it is equivalent to the operation y = conj(sqrt(conj(a-j*b))), 18 | % but it fixes a bug in the ordinary SQRT in MATLAB arising whenever the real part is negative 19 | % and the imaginary part is an array with some zero elements. For example, compare the outputs: 20 | % 21 | % conj(sqrt(conj(-1 - [0; 1]*j))) = 0 + 1.0000i, sqrte(-1 - [0; 1]*j) = 0 - 1.0000i 22 | % 0.4551 - 1.0987i 0.4551 - 1.0987i 23 | % but 24 | % 25 | % conj(sqrt(conj(-1 + 0*j))) = 0 - 1.000i, sqrte(-1 + 0*j) = 0 - 1.000i 26 | 27 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 28 | 29 | function y = sqrte(z) 30 | 31 | if nargin==0, help sqrte; return; end 32 | 33 | y = sqrt(z); 34 | 35 | i = find(imag(z)==0 & real(z)<0); 36 | 37 | y(i) = -j * sqrt(abs(z(i))); 38 | 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/steer.m: -------------------------------------------------------------------------------- 1 | % steer.m - steer array towards given angle 2 | % 3 | % Usage: asteer = steer(d, a, ph0) 4 | % 5 | % d = element spacing in units of lambda 6 | % a = array weights to be steered (must be row vector) 7 | % ph0 = steering angle in degrees (broadside ph0=90) 8 | % 9 | % asteer = steered weights (row vector) 10 | % 11 | % notes: multiplies array weights by progressive phase, 12 | % asteer(n) = a(n) * exp(-j*(n-(N-1)/2)*ps0), for n = 0,1,...,N-1, 13 | % where ps0 = k*d*cos(ph0), thus, equivalent to scan(a, ps0) 14 | % 15 | % see also SCAN, ARRAY 16 | 17 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 18 | 19 | function asteer = steer(d, a, ph0) 20 | 21 | if nargin==0, help steer; return; end 22 | 23 | if ph0==90, asteer=a; return; end % avoids v5.1 evaluation of cos(pi/2)=6.123e-017 24 | 25 | ph0 = ph0 * pi / 180; 26 | 27 | ps0 = 2 * pi * d * cos(ph0); % scanning phase in psi-space 28 | 29 | asteer = scan(a, ps0); 30 | 31 | 32 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/swr.m: -------------------------------------------------------------------------------- 1 | % swr.m - standing wave ratio 2 | % 3 | % Usage: S = swr(Gamma) 4 | 5 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 6 | 7 | function S = swr(Gamma) 8 | 9 | if nargin==0, help swr; return; end 10 | 11 | if abs(Gamma)==1, 12 | S = inf; 13 | else 14 | S = (1+abs(Gamma))./(1-abs(Gamma)); 15 | end 16 | 17 | 18 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/t2pi.m: -------------------------------------------------------------------------------- 1 | % t2pi.m - T to Pi transformation 2 | % 3 | % Usage: Z123 = t2pi(Zabc) 4 | % 5 | % Zabc = impedances of T network = [Za,Zb,Zc] 6 | % Z123 = impedances of Pi network = [Z1,Z2,Z3] 7 | % 8 | % notes: Z123 and Zabc are Lx3 matrices, for transforming several cases at once 9 | % 10 | % the transformation equations are: 11 | % 12 | % Z1 = V/Za, Z2 = V/Zb, Z3 = V/Zc, where V = Za*Zb + Zb*Zc + Zc*Za 13 | % 14 | % Za = Z2*Z3/U, Zb = Z3*Z1/U, Zc = Z1*Z2/U, where U = Z1 + Z2 + Z3 15 | % 16 | % ---|----[Z2]----|--- ---[Zc]----|----[Za]--- 17 | % | | | 18 | % [Z1] [Z3] <== [Zb] 19 | % | | | 20 | % ---|------------|--- -----------|------------ 21 | % 22 | % see also pi2t for the reverse transformation 23 | 24 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 25 | 26 | function Z123 = t2pi(Zabc) 27 | 28 | if nargin==0, help t2pi; return; end 29 | 30 | Za = Zabc(:,1); Zb = Zabc(:,2); Zc = Zabc(:,3); 31 | 32 | V = Za.*Zb + Zb.*Zc + Zc.*Za; 33 | 34 | Z1 = V./Za; 35 | Z2 = V./Zb; 36 | Z3 = V./Zc; 37 | 38 | Z123 = [Z1,Z2,Z3]; 39 | 40 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/taylor1p.m: -------------------------------------------------------------------------------- 1 | % taylor1p.m - Taylor 1-parameter array design 2 | % 3 | % Usage: [a, dph] = taylor1p(d, ph0, N, R) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees (broadside ph0=90) 7 | % N = number of array elements (odd or even) 8 | % R = relative sidelobe level in dB 9 | % 10 | % a = row vector of array weights (steered towards ph0) 11 | % dph = beamwidth in degrees 12 | % 13 | % notes: essentially the Kaiser/Schafer window for spectral analysis, 14 | % 15 | % uses taylorbw to calculate Taylor's B-parameter and beamwidth Du 16 | % then, calls besseli to calculate the window's space samples 17 | % 18 | % see also gain1d, binomial, dolph, uniform, sector, taylorbw, taylornb, ville 19 | 20 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 21 | 22 | function [a, dph] = taylor1p(d, ph0, N, R) 23 | 24 | if nargin==0, help taylor1p; return; end 25 | 26 | [B,Du] = taylorbw(R); % get Taylor's B-parameter and beamwidth 27 | alpha = pi*B; 28 | 29 | r = rem(N,2); 30 | M = (N-r)/2; 31 | 32 | for m=1:M, 33 | w(m) = besseli(0, alpha*sqrt(1 - (m/M)^2)); 34 | end 35 | 36 | if r==1, % odd N=2*M+1 37 | w = [fliplr(w), besseli(0,alpha), w]; % symmetrized Kaiser window 38 | else % even N=2*M 39 | w = [fliplr(w), w]; 40 | end 41 | 42 | a = steer(d, w, ph0); % steer towards ph0 43 | 44 | a = a / norm(a); % normalize to unit norm - not really necessary 45 | 46 | dps = 2 * pi * Du / N; 47 | 48 | dph = bwidth(d, ph0, dps); % 3-dB width in phi-space 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/taylornb.m: -------------------------------------------------------------------------------- 1 | % taylornb.m - Taylor n-bar line source array design 2 | % 3 | % Usage: [a, dph] = taylornb(d, ph0, N, R, nbar) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees (broadside ph0=90) 7 | % N = number of array elements (odd or even) 8 | % R = relative sidelobe level in dB 9 | % nbar = number of near sidelobes 10 | % 11 | % a = row vector of array weights (steered towards ph0) 12 | % dph = beamwidth in degrees 13 | % 14 | % notes: calculates the Taylor n-bar distribution zeros, 15 | % maps them to the array zeros, and constructs the array 16 | % polynomial using poly2 17 | % 18 | % see also gain1d, binomial, dolph, uniform, sector, taylorbw, taylor1p, ville 19 | 20 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 21 | 22 | function [a, dph] = taylornb(d, ph0, N, R, nbar) 23 | 24 | if nargin==0, help taylornb; return; end 25 | 26 | Ra = 10^(R/20); 27 | 28 | A = 1/pi * acosh(Ra); 29 | 30 | nbarmin = 2*A^2 + 1; 31 | if nbar < nbarmin, 32 | fprintf('\ntaylornb: nbar must be at least %2.2f\n', nbarmin); 33 | a=[]; dph=[]; 34 | return; 35 | end 36 | 37 | sigma = nbar / sqrt(A^2 + (nbar-0.5)^2); 38 | 39 | u = zeros(1,N-1); 40 | 41 | n = 1:nbar-1; u(n) = sigma * sqrt(A^2 + (n-0.5).^2); u(N-n) = -u(n); 42 | n = nbar:N-nbar; u(n) = n; 43 | 44 | psi = 2*pi*u/N; 45 | 46 | z = exp(j*psi); 47 | 48 | w = real(poly2(z)); 49 | 50 | a = steer(d, w, ph0); % steer towards ph0 51 | 52 | Du = 2/pi * sqrt(acosh(Ra)^2 - acosh(Ra/sqrt(2))^2); 53 | 54 | dps = sigma * 2*pi*Du/N; 55 | 56 | dph = bwidth(d, ph0, dps); % 3-dB width in phi-space 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/traveling.m: -------------------------------------------------------------------------------- 1 | % travel.m - gain of traveling-wave antenna of length L 2 | % 3 | % Usage: [g, th, c, th0] = traveling(L, Nth); 4 | % 5 | % L is in units of lambda 6 | % th = Nth+1 equally-spaced polar angles in [0,pi], th = (0:Nth)*pi/Nth 7 | % 8 | % g(th) = c * [sin(th) * sin(pi*L*(1-cos(th))) / (1-cos(th))]^2 9 | % c normalizes g to unity maximum 10 | % 11 | % th0 = acos(1 - 0.371/L) = direction of main lobe in degrees. 12 | % 13 | % see also DIPOLE, RHOMBIC, VEE 14 | 15 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 16 | 17 | function [g, th, c, th0] = traveling(L, Nth) 18 | 19 | if nargin==0, help traveling; return; end 20 | 21 | th = (0:Nth)*pi/Nth; 22 | 23 | g = (sin(th) .* sinc(L*(1 - cos(th)))).^2; 24 | 25 | c = 1 / max(g); 26 | 27 | g = c*g; 28 | 29 | th0 = acos(1 - 0.371/L) * 180 / pi; % tilt angle in degrees 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/tsection.m: -------------------------------------------------------------------------------- 1 | % tsection.m - T-section equivalent of a length-l transmission line segment 2 | % 3 | % ----|-------------|---- ----|--Za--|--Zb--|---- 4 | % l ==> Zc 5 | % ----|-------------|---- ----|------|------|---- 6 | % 7 | % Usage: [Za,Zc] = tsection(Z0,bl) 8 | % 9 | % Z0 = line impedance 10 | % bl = phase length in radians = beta*l = 2*pi*l/lambda 11 | % 12 | % Za = series impedance (Zb=Za) 13 | % Zc = shunt impedance 14 | % 15 | % notes: Za = Zb = j*Z0*tan(bl/2), Zc = -j*Z0/sin(bl) 16 | % 17 | % for a lossy line bl can also be complex, i.e., bl-j*al 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function [Za,Zc] = tsection(Z0,bl) 22 | 23 | if nargin==0, help tsection; return; end 24 | 25 | if isreal(bl) & rem(bl/pi,2)==1 % bl = (2*n+1)*pi 26 | Za = inf; 27 | Zc = inf; 28 | elseif isreal(bl) & rem(bl/pi,2)==0 % bl = 2*n*pi 29 | Za = 0; 30 | Zc = inf; 31 | else 32 | Za = j * Z0 * tan(bl/2); 33 | Zc = -j * Z0 / sin(bl); 34 | end 35 | 36 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/twosect.m: -------------------------------------------------------------------------------- 1 | % twosect.m - two-section impedance transformer 2 | % 3 | % -----------------====L1====----L2----| 4 | % main line Z0 Z1 Z2 ZL 5 | % -----------------==========----------| 6 | % 7 | % Usage: L12 = twosect(Z0,Z1,Z2,ZL) 8 | % 9 | % Z0,Z1,Z2,ZL = line, section, and load impedances 10 | % 11 | % L12 = [ L1,L2] = 2x2 matrix, where each row is a solution 12 | % 13 | % L1,L2 are the electrical lengths of the two sections 14 | % 15 | % notes: Z0,Z1,Z2 must be real-valued, ZL can be complex-valued 16 | % 17 | % can be used for antireflection coating design: given the refractive 18 | % indices na,n1,n2,nb, compute L12 = twosect(1/na, 1/n1, 1/n2, 1/nb) 19 | % 20 | % a solution may not exist 21 | % 22 | % L12 = twosect(Z0,Z1,Z0,R), has a solution for all real loads R 23 | % in the range Z0/S^2 < R < Z0*S^2, where S = max(Z0,Z1)/min(Z0,Z1), 24 | % e.g., Z0=50, Z1=75, can match all loads in the range 22.22 < R < 112.5 25 | 26 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 27 | 28 | function L12 = twosect(Z0,Z1,Z2,ZL) 29 | 30 | if nargin==0, help twosect; return; end 31 | 32 | r1 = (Z1-Z0)/(Z1+Z0); 33 | r2 = (Z2-Z1)/(Z2+Z1); 34 | r3 = abs((ZL-Z2)/(ZL+Z2)); 35 | th3 = angle((ZL-Z2)/(ZL+Z2)); 36 | 37 | s = ((r2+r3)^2 - r1^2*(1+r2*r3)^2) / (4*r2*r3*(1-r1^2)); 38 | 39 | if (s<0)|(s>1), fprintf('\n no solution exists\n\n'); return; end 40 | 41 | de2 = th3/2 + asin(sqrt(s)) * [1;-1]; % contruct two solutions 42 | 43 | G2 = (r2 + r3*exp(j*th3-2*j*de2)) ./ (1 + r2*r3*exp(j*th3-2*j*de2)); 44 | 45 | de1 = angle(-G2/r1)/2; 46 | 47 | L1 = de1/2/pi; 48 | L2 = de2/2/pi; 49 | 50 | L12 = mod([L1,L2], 0.5); 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/uniform.m: -------------------------------------------------------------------------------- 1 | % uniform.m - uniform array weights 2 | % 3 | % Usage: [a, dph] = uniform(d, ph0, N) 4 | % 5 | % d = element spacing in units of lambda 6 | % ph0 = beam angle in degrees (broadside ph0=90) 7 | % N = number of array elements (odd) 8 | % 9 | % a = row vector of array weights (steered towards ph0) 10 | % dph = beamwidth in degrees 11 | % 12 | % note: useful mainly for calculating the beamwidth dph 13 | % 14 | % see also ARRAY, BINOMIAL, DOLPH, TAYLOR 15 | 16 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 17 | 18 | function [a, dph] = uniform(d, ph0, N) 19 | 20 | if nargin==0, help uniform; return; end 21 | 22 | a = ones(1,N); % uniform weights 23 | 24 | a = steer(d, a, ph0); % steer towards ph0 25 | 26 | dps = 0.886 * 2 * pi / N; % 3-dB width of rectangular window 27 | 28 | dph = bwidth(d, ph0, dps); % 3-dB width in angle space 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/ustep.m: -------------------------------------------------------------------------------- 1 | % ustep.m - unit-step or rising unit-step function 2 | % 3 | % Usage: y = ustep(t) (unit step) 4 | % y = ustep(t,tr) (rising unit step, with rise time tr) 5 | % 6 | % t = any vector 7 | % tr = rise time (tr=0 corresponds to a unit step) 8 | % 9 | % y = (t/tr)*[u(t)-u(t-tr)] + u(t-tr) 10 | % 11 | % 12 | % see also UPULSE 13 | 14 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 15 | 16 | function y = ustep(t,tr) 17 | 18 | if nargin==0, help ustep; return; end 19 | if nargin==1, tr=0; end 20 | 21 | y = zeros(size(t)); 22 | 23 | if tr==0, 24 | y(find(t>=0)) = 1; 25 | else 26 | y = (t/tr) .* (ustep(t) - ustep(t-tr)) + ustep(t-tr); 27 | end 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/vee.m: -------------------------------------------------------------------------------- 1 | % vee.m - gain of traveling-wave vee antenna 2 | % 3 | % Usage: [g, th, c, th0] = vee(L, alpha, Nth); 4 | % 5 | % L is in units of lambda (L=0 not allowed) 6 | % alpha = vee half-angle in degrees 7 | % 8 | % g = g(th) 9 | % th = Nth+1 equally-spaced polar angles in [0,pi] = (0:Nth)*pi/Nth 10 | % c = unity-max normalization constant 11 | % th0 = acos(1 - 0.371/L) = direction of main lobe in degrees. 12 | % 13 | % (alpha*Nth/360 must not be an integer) 14 | % 15 | % see also DIPOLE, TRAVEL, RHOMBIC 16 | 17 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 18 | 19 | function [g, th, c, th0] = vee(L, alpha, Nth) 20 | 21 | if nargin==0, help vee; return; end 22 | 23 | th = (0 : Nth) * pi / Nth; 24 | 25 | alpha = alpha * pi / 180; 26 | 27 | th1 = th - alpha; 28 | th2 = th + alpha; 29 | 30 | F1 = sin(th1) .* (1 - exp(-j*2*pi*L*(1-cos(th1)))) ./ (1 - cos(th1)); 31 | F2 = sin(th2) .* (1 - exp(-j*2*pi*L*(1-cos(th2)))) ./ (1 - cos(th2)); 32 | 33 | g = abs(F1 - F2).^2; 34 | 35 | c = 1 / max(g); 36 | 37 | g = c * g; 38 | 39 | th0 = acos(1 - 0.371/L) * 180 / pi; 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/vprop.m: -------------------------------------------------------------------------------- 1 | % vprop.m - voltage and current propagation 2 | % 3 | % --------|-------------|---------- 4 | % generator V1,I1 l V2,I2 load 5 | % --------|-------------|---------- 6 | % 7 | % Usage: [V1,I1] = vprop(V2,I2,Z0,bl) 8 | % 9 | % V2,I2 = voltage and current at point z2 10 | % Z0 = line impedance 11 | % bl = phase length in radians = beta*l = 2*pi*l/lambda 12 | % 13 | % V1,I1 = voltage and current at point z1 14 | % 15 | % notes: for a lossy line bl can also be complex, i.e., bl-j*al 16 | 17 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 18 | 19 | function [V1,I1] = vprop(V2,I2,Z0,bl) 20 | 21 | if nargin==0, help vprop; return; end 22 | 23 | VI = [cos(bl), j*Z0*sin(bl); j*sin(bl)/Z0, cos(bl)] * [V2; I2]; 24 | 25 | V1 = VI(1); 26 | I1 = VI(2); 27 | 28 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/wavenum.m: -------------------------------------------------------------------------------- 1 | % wavenum.m - calculate wavenumber and characteristic impedance 2 | % 3 | % Usage:k [kc, etac] = wavenum(er, mr, sigma, f) 4 | % 5 | % er,mr = relative epsilon and mu 6 | % sigma = conductivity in S/m 7 | % f = frequency in Hz 8 | % 9 | % kc = wavenumber 10 | % etac = characteristic impedance 11 | % 12 | % kc = w * sqrt(mu*ep) * (1 - j*sigma/w*ep)^(1/2) = beta - j* alpha 13 | % etac = sqrt(mu/ep) * (1 - j*sigma/w*ep)^(-1/2) 14 | 15 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 16 | 17 | function [kc, etac] = wavenum(er, mr, sigma, f) 18 | 19 | if nargin==0, help wavenum; return; end 20 | 21 | ep0 = 8.854E-12; 22 | mu0 = 4*pi*1E-7; 23 | 24 | ep = er * ep0; 25 | mu = mr * mu0; 26 | 27 | w = 2*pi*f; 28 | tand = sigma/(w*ep); 29 | 30 | kc = w * sqrt(mu*ep) * (1 - j*tand)^(1/2); 31 | etac = sqrt(mu/ep) * (1 - j*tand)^(-1/2); 32 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/woodward.m: -------------------------------------------------------------------------------- 1 | % woodward.m - Woodward-Lawson-Butler beams 2 | % 3 | % Usage: a = woodward(A, alt) 4 | % 5 | % A = N-dimensional row vector of beam amplitudes 6 | % alt = 0,1 for standard or alternative half-integer DFT frequencies 7 | % 8 | % a = N-dimensional row vector of array weights 9 | % 10 | % notes: essentially, a = IDFT(A,N), 11 | % 12 | % can be considered a special case of MULTIBEAM with uniform window 13 | % and N beams at steering angles phk = acos(k/d*N), 14 | % so that psk = 2*pi*d*cos(phk) = 2*pi*k/N = DFT frequencies, 15 | % 16 | % the k-th Butler beam can be turned on by choosing A(i) = delta(i-k), 17 | % 18 | % for frequency-sampling design, a(n) must be windowed by a window w(n). 19 | 20 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 21 | 22 | function a = woodward(A, alt) 23 | 24 | if nargin==0, help woodward; return; end 25 | 26 | N = length(A); 27 | 28 | k = (0:N-1) - alt*(N-1)/2; % DFT index 29 | 30 | psi = 2*pi*k/N; % DFT frequencies in psi-space 31 | 32 | n = (0:N-1) - (N-1)/2; % array index (half-integer for even N) 33 | 34 | a = A * exp(-j*psi'*n); % a(n) = \sum_k A(k) e^{-j\psi_k*n} 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/z2g.m: -------------------------------------------------------------------------------- 1 | % z2g.m - impedance to reflection coefficient transformation 2 | % 3 | % Usage: Gamma = z2g(Z,Z0) 4 | % Gamma = z2g(Z) (equivalent to Z0=1, i.e., normalized impedances) 5 | % 6 | % Z = vector of impedances 7 | % Z0 = line impedance 8 | % 9 | % Gamma = vector of reflection coefficients 10 | 11 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 12 | 13 | function Gamma = z2g(Z,Z0) 14 | 15 | if nargin==0, help z2g; return; end 16 | if nargin==1, Z0=1; end 17 | 18 | Gamma = ones(size(Z)); % Gamma=1 when Z=Inf 19 | 20 | i = find(Z ~= Inf); % Gamma for Z not equal to Inf 21 | Gamma(i) = (Z(i)-Z0)./(Z(i)+Z0); 22 | 23 | 24 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/toolBox/zprop.m: -------------------------------------------------------------------------------- 1 | % zprop.m - wave impedance propagation 2 | % 3 | % --------|-------------|---------- 4 | % generator Z1 l Z2 load 5 | % --------|-------------|---------- 6 | % 7 | % Usage: Z1 = zprop(Z2,Z0,bl) 8 | % 9 | % Z2 = wave impedance at point z2 10 | % Z0 = line impedance 11 | % bl = phase length in radians = beta*l = 2*pi*l/lambda 12 | % 13 | % Z1 = wave impedance at point z1 14 | % 15 | % notes: for a lossy line bl can also be complex, i.e., bl-j*al 16 | % 17 | % if Z2=inf, it returns Z1=-j*Z0*cot(bl) 18 | 19 | % Sophocles J. Orfanidis - 1999-2008 - www.ece.rutgers.edu/~orfanidi/ewa 20 | 21 | function Z1 = zprop(Z2,Z0,bl) 22 | 23 | if nargin==0, help zprop; return; end 24 | 25 | if Z2==inf, 26 | Z1 = -j*Z0*cot(bl); 27 | else 28 | Z1 = Z0 * (Z2 + j*Z0*tan(bl))/(Z0 + j*Z2*tan(bl)); 29 | end 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 41 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 42 | 43 | end 44 | 45 | R = abs(r).^2; 46 | T = abs(t).^2; 47 | -------------------------------------------------------------------------------- /BraggGratingSolvers/Bragg Grating Transfer Matrix Solver/transferMatrix2.m: -------------------------------------------------------------------------------- 1 | function [R,T] = transferMatrix(lambdaNot, lambdaMin, lambdaMax, n, L) 2 | 3 | 4 | lambdas = linspace(lambdaMin, lambdaMax, 501); 5 | n = [1 2.32 1.38 2.32 1.38 2.32 1.52]; 6 | L = [.1078 .1812 .1078 .1812 .1078].*500e-9; 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambdas),1); 12 | t = zeros(length(lambdas),1); 13 | 14 | 15 | for w = 1:length(lambdas); 16 | 17 | lambda = lambdas(w); 18 | ko = 2*pi*n(1)/lambda; 19 | kf = 2*pi*n(end)/lambda; 20 | M = eye(2,2); 21 | 22 | for s = 1:cellNum; 23 | 24 | kl = 2*pi*n(s+1)*L(s)/lambda; 25 | k = kl/(L(s)); 26 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 27 | M = Mi*M; 28 | 29 | end 30 | 31 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 32 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 33 | 34 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 35 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 36 | 37 | end 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | 42 | plot( lambdas*1e9, R, lambdas*1e9, T, lambdas*1e9) 43 | 44 | 45 | -------------------------------------------------------------------------------- /Coupled1D-SchodingerNewtonMaxwell/gramSchmidt.m: -------------------------------------------------------------------------------- 1 | function [ Q ] = gramSchmidt(UT ) 2 | %GRAMSCHMIDT Computes orthonormal columns according to the Gram-Schmidt 3 | %orthonormalization procedure. 4 | 5 | sU = size(UT); 6 | Q = zeros(sU); 7 | for k = 1:sU(2) 8 | v = UT(:,k); 9 | for n = 1:k-1; 10 | R = Q(:,n)'*UT(:,k); 11 | v = v - R*Q(:,n); 12 | end 13 | 14 | Q(:,k) = v/norm(v); 15 | 16 | end 17 | 18 | end 19 | 20 | -------------------------------------------------------------------------------- /Coupled1D-SchodingerNewtonMaxwell/nlsSimple.m: -------------------------------------------------------------------------------- 1 | function [ dUT ] = nlsSimple( t, UT, k, Vx, c1, c2) %#ok 2 | % Solves the NLS using a pseudospectral fft method 3 | % input requires variables and parameters 4 | % ( t, UT, k, Vx, fftCoul, c1, c2, c3) 5 | % i.e. time dependent schrodinger equation with linear potential and 6 | % nonlinear square term... 7 | %-------------------------------------------------------------------------% 8 | % % 9 | % dPsi_i d^2Psi_i % 10 | % ------ = c1*-------- + c2*V(x)*Psi_i + c3*F(rho(x,t)) % 11 | % dt dx^2 % 12 | % % 13 | %- - - - - - - - - - - - - - - - - - - - - - - - -% 14 | % where rho(x) = sum |Psi_i(x)|^2 % 15 | % % 16 | % F(rho) = Int [ rho(x)*u(x-x') ] dx' % 17 | % i.e. F is the convolution of rho(x) and u(x) % 18 | % % 19 | %-------------------------------------------------------------------------% 20 | 21 | pkg = size(UT); 22 | rho = zeros(pkg(1),1); 23 | dUT = zeros(pkg); 24 | for s = 1:pkg(2) 25 | rho = rho + (abs(UT(:,s)).^2); 26 | end 27 | 28 | for s = 1:pkg(2) 29 | uxx = (ifft( (k*1i).^2 .* fft(UT(:,s)) ) ); 30 | dUT(:,s) = c1.*uxx + ( c2*Vx ).*UT(:,s); 31 | end 32 | 33 | end 34 | 35 | -------------------------------------------------------------------------------- /Coupled1D-SchodingerNewtonMaxwell/splineDerivative.m: -------------------------------------------------------------------------------- 1 | function [ d ] = splineDerivative( x, y ) 2 | %SPLINEDERIVATIVE Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | 6 | h = x(2:end) - x(1:end-1) ; 7 | N = length(h)+1; 8 | del = ( y(2:end) - y(1:end-1) )./ (h); 9 | 10 | for k = 1:length(del) 11 | if isnan(del(k)) == 1 12 | del(k) = 0; 13 | end 14 | end 15 | e1 = [h(2:end); h(end) + h(end-1)]; 16 | e2 = [h(2); 2*(h(1:end-1) + h(2:end)); h(end-1)]; 17 | e3 = [h(2) + h(1); h(1:end-1)]; 18 | 19 | r = [((h(1)+2*e3(1))*h(2)*del(1)+ h(1)^2*del(2))/e3(1) ; ... 20 | 3*(h(2:N-1).*del(1:N-2)+ h(1:N-2).*del(2:N-1)) ; ... 21 | (h(N-1)^2*del(N-2)+(2*e1(N-1)+h(N-1))*h(N-2)*del(N-1))/e1(N-1) ]; 22 | 23 | d = tridisolve(e1,e2,e3,r); 24 | end 25 | 26 | -------------------------------------------------------------------------------- /Coupled1D-SchodingerNewtonMaxwell/tridisolve.m: -------------------------------------------------------------------------------- 1 | function x = tridisolve(a,b,c,d) 2 | % TRIDISOLVE Solve tridiagonal system of equations. 3 | % x = TRIDISOLVE(a,b,c,d) solves the system of linear equations 4 | % b(1)*x(1) + c(1)*x(2) = d(1), 5 | % a(j-1)*x(j-1) + b(j)*x(j) + c(j)*x(j+1) = d(j), j = 2:n-1, 6 | % a(n-1)*x(n-1) + b(n)*x(n) = d(n). 7 | % 8 | % The algorithm does not use pivoting, so the results might 9 | % be inaccurate if abs(b) is much smaller than abs(a)+abs(c). 10 | % More robust, but slower, alternatives with pivoting are: 11 | % x = T\d where T = diag(a,-1) + diag(b,0) + diag(c,1) 12 | % x = S\d where S = spdiags([[a; 0] b [0; c]],[-1 0 1],n,n) 13 | 14 | x = d; 15 | n = length(x); 16 | 17 | for j = 1:n-1 18 | mu = a(j)/b(j); 19 | b(j+1) = b(j+1) - mu*c(j); 20 | x(j+1) = x(j+1) - mu*x(j); 21 | end 22 | 23 | x(n) = x(n)/b(n); 24 | for j = n-1:-1:1 25 | x(j) = (x(j)-c(j)*x(j+1))/b(j); 26 | end 27 | -------------------------------------------------------------------------------- /CppVersions/2012-07-02-2D_AXISYMMETRIC_FDTD/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : 2D_AXISYMMETRIC_FDTD Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this 2D_AXISYMMETRIC_FDTD application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your 2D_AXISYMMETRIC_FDTD application. 9 | 10 | 11 | 2D_AXISYMMETRIC_FDTD.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | 2D_AXISYMMETRIC_FDTD.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | 2D_AXISYMMETRIC_FDTD.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named 2D_AXISYMMETRIC_FDTD.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /CppVersions/2013-03-05-3D_FDTD/destructor.cpp: -------------------------------------------------------------------------------- 1 | #include "3D_FDTD.h" 2 | -------------------------------------------------------------------------------- /CppVersions/2013-03-05-3D_FDTD/model.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_H 2 | #define MODEL_H 3 | #include "3D_FDTD.h" 4 | 5 | // Generates domain 6 | class Domain 7 | { 8 | 9 | public: 10 | int xGrid, yGrid, zGrid; 11 | 12 | double xLength, yLength, zLength; 13 | 14 | double dx, dy, dz; 15 | 16 | int tSteps; 17 | 18 | double dt, maxTime, courant; 19 | 20 | Domain(); // Standard Constructor 21 | 22 | }; 23 | 24 | // Generates Efields 25 | class Efield 26 | { 27 | 28 | public: 29 | int xGrid, yGrid, zGrid; 30 | double dt; 31 | double *** field; 32 | double *** sigma; 33 | double *** eps; 34 | double *** c1; 35 | double *** c2; 36 | 37 | Efield(int xIn, int yIn, int zIn, double dtIn); // Standard Constructor 38 | }; 39 | 40 | // Generates Hfields 41 | class Hfield 42 | { 43 | 44 | public: 45 | int xGrid, yGrid, zGrid; 46 | double dt; 47 | double *** field; 48 | double *** sigma; 49 | double *** mu; 50 | double *** d1; 51 | double *** d2; 52 | 53 | Hfield(int xIn, int yIn, int zIn, double dtIn); // Standard Constructor 54 | 55 | }; 56 | 57 | // Generates source conditions 58 | class Source 59 | { 60 | 61 | public: 62 | int xPos, yPos, zPos; 63 | string sourceType; 64 | double freq; 65 | double amplitude; 66 | double width; 67 | double waist; 68 | double fLength; 69 | double zo; 70 | double vortexN; 71 | 72 | Source(); 73 | void gaussian( Domain dom, Efield Ex, Efield Ey, Efield Ez, int r ); 74 | void gaussBeam( Domain dom, Efield Ex, Efield Ey, Efield Ez, int r ); 75 | void vortex( Domain dom, Efield Ex, Efield Ey, Efield Ez, int r ); 76 | }; 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /CppVersions/2013-03-05-3D_FDTD/settings.txt: -------------------------------------------------------------------------------- 1 | # Settings for 1D FDTD simulation. 2 | 3 | [Domain] 4 | xGrid = 100 5 | yGrid = 100 6 | zGrid = 400 7 | 8 | xLength = 2e-6 9 | yLength = 2e-6 10 | zLength = 4e-6 11 | 12 | maxTime = 6e-15 13 | courant = .5 14 | 15 | [Output] 16 | fileName = TRIPLEdata.bin 17 | frames = 500 18 | outputParameters = 10 19 | # Video? Write "1" = yes or "0" = no: 20 | video = 1 21 | 22 | 23 | [SourceCondition] 24 | # options: modulatedGauss, sech, CW, gauss, vortex, gaussBeam 25 | pulse = gaussBeam 26 | frequency = 1000e12 27 | amplitude = 1 28 | width = 2e-15 29 | waist = .1e-6 30 | fLength = 1.5e-6 31 | zo = -2e-6 32 | vortexN = 2 33 | 34 | xPosition = 50 35 | yPosition = 50 36 | zPosition = 10 -------------------------------------------------------------------------------- /CppVersions/2013-03-05-3D_FDTD/utilityFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "3D_FDTD.h" 2 | 3 | void writeData( Efield aEfield, string name ) 4 | { 5 | ofstream data(name, ios::out | ios::binary); // Open file to store data 6 | 7 | double x = aEfield.xGrid; 8 | double y = aEfield.yGrid; 9 | double z = aEfield.zGrid; 10 | 11 | data.write((char *) &x, sizeof x); 12 | data.write((char *) &y, sizeof y); 13 | data.write((char *) &z, sizeof z); 14 | 15 | for (int i = 0; i < aEfield.xGrid; i++) 16 | { 17 | for (int j = 0; j < aEfield.yGrid; j++) 18 | { 19 | for (int k = 0; k < aEfield.zGrid; k++) 20 | { 21 | data.write((char *) &aEfield.field[i][j][k], sizeof aEfield.field[i][j][k]); 22 | } 23 | } 24 | } 25 | 26 | data.close(); 27 | } -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/PSI.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/PSI.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/RN.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/domain.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/domain.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/ground: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/ground -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/groundVideo.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/groundVideo.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/ionVid.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/ionVid.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/modelDestructor.cpp: -------------------------------------------------------------------------------- 1 | #include "1D_TRIPLE.h" 2 | 3 | -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/new.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/new.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/newIon.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/newIon.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/psiVid.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/psiVid.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/rho.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/rho.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/rhoVid.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/rhoVid.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/temp.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/temp.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/temp2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/temp2.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/video.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/video.bin -------------------------------------------------------------------------------- /CppVersions/2013-05-15-SchrodingerNewtonMaxwell/videoIon.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/CppVersions/2013-05-15-SchrodingerNewtonMaxwell/videoIon.bin -------------------------------------------------------------------------------- /CppVersions/2013-06-13-SchrodingerNewtonMaxwell-RK4Update/3D Data Conv/SN_1D_IMP.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | fclose('all'); 4 | 5 | %% IMPORT DATA 6 | folder = 'C:\Users\Inchoate\Documents\Visual Studio 2012\Projects\SNM update 5-15 - Copy\SNM\'; 7 | % folder = 'C:\Users\Brian\Documents\Visual Studio 2012\Projects\SNMdata\24elc24IonwInputfield\Run 3\SNM\'; 8 | % folder = 'C:\Users\Brian\Documents\Visual Studio 2012\Projects\batchRun\batchFiles\batch_0\dataSet_4\'; 9 | 10 | data = fopen( strcat(folder, '1Ddata.bin' ) ); 11 | vidData = fopen( strcat(folder, '1Dvid.bin' ) ); 12 | 13 | data = fread(data, 'double'); 14 | vidData = fread(vidData, 'double'); 15 | 16 | N = data(1); 17 | L = data(2); 18 | dx = data(3); 19 | x = 0:dx:L; 20 | 21 | 22 | data = data(4:end); 23 | U = data(1:N); 24 | dU = data(N+1:end); 25 | 26 | plot( x, U, x, dU) 27 | 28 | 29 | frames = 200000; 30 | figure; 31 | for k = 0:1:frames; 32 | 33 | rho = vidData(k*N+1: (k+1)*(N)); 34 | 35 | plot(x,rho); 36 | axis ([x(1), x(end), -1,1]) 37 | text(0,0,num2str(k)); 38 | getframe; 39 | 40 | 41 | end 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CppVersions/2013-06-13-SchrodingerNewtonMaxwell-RK4Update/SN_3D.cpp: -------------------------------------------------------------------------------- 1 | #include "SN_3D.h" 2 | 3 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MAIN FUNCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// 4 | int main () { 5 | 6 | 7 | CX dt; 8 | 9 | Domain dom ; 10 | Manager boss(dom); 11 | boss.startTime(); 12 | Derivative D2( 2.0, 2.0, dom.boundary, dom.Nx, dom.Ny, dom.Nz, dom.Lx, dom.Ly, dom.Lz); 13 | Schrodinger elc(dom); 14 | 15 | boss.initalData(dom, elc, D2); 16 | boss.midTime(); 17 | 18 | 19 | // Imaginary time 20 | dt = CX( 0.0, - dom.dt_im); 21 | cout << dt << endl; 22 | RK4 ( elc, dom, D2, boss, dt); 23 | 24 | 25 | // Real time 26 | dt = CX(dom.dt_re, 0.0); 27 | cout << dt << endl; 28 | RK4 ( elc, dom, D2, boss, dt); 29 | 30 | boss.endTime(); 31 | 32 | 33 | return(0); 34 | 35 | }//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END MAIN FUNCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%// 36 | 37 | 38 | -------------------------------------------------------------------------------- /CppVersions/2013-06-13-SchrodingerNewtonMaxwell-RK4Update/classDef.h: -------------------------------------------------------------------------------- 1 | // finiteDifference.h 2 | #include "SN_3D.h" 3 | 4 | #ifndef CLASS_H 5 | #define CLASS_H 6 | 7 | class Domain{ 8 | 9 | public: 10 | 11 | int Nx, Ny, Nz, N3; 12 | double dx, dy, dz; 13 | double Lx, Ly, Lz; 14 | 15 | int Nt_im, Nt_re; 16 | double dt_im, tf_im; 17 | double dt_re, tf_re; 18 | 19 | string boundary; 20 | 21 | // Initializer, generates sparse derivative matrix [vector] 22 | Domain(); 23 | 24 | }; 25 | 26 | class Schrodinger{ 27 | 28 | public: 29 | CX* U; 30 | CX c1, c2, c3; 31 | double alpha, beta; 32 | double *Vext, *rho; 33 | double dx, dy, dz; 34 | double xo, yo, zo; 35 | double Lx, Ly, Lz; 36 | int Nx, Ny, Nz, N3; 37 | 38 | 39 | Schrodinger::Schrodinger(Domain dom); 40 | void Schrodinger::density(); 41 | }; 42 | 43 | 44 | class Manager{ 45 | 46 | public: 47 | string videoBin; 48 | int frames, Nt_re, Nt_im, N3; 49 | double elapTime; 50 | clock_t beginT, endT; 51 | 52 | Manager(Domain dom); 53 | void Manager::vidWrite( int r, double* rho, CX* U, CX dt ); 54 | void Manager::initalData( Domain dom, Schrodinger elc, Derivative D2 ); 55 | void Manager::startTime(); 56 | void Manager::midTime(); 57 | void Manager::endTime(); 58 | 59 | }; 60 | 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /CppVersions/2013-06-13-SchrodingerNewtonMaxwell-RK4Update/modelDestructor.cpp: -------------------------------------------------------------------------------- 1 | #include "1D_TRIPLE.h" 2 | 3 | -------------------------------------------------------------------------------- /CppVersions/2013-06-13-SchrodingerNewtonMaxwell-RK4Update/settings.txt: -------------------------------------------------------------------------------- 1 | # Settings for 3D TDDFT Theory 2 | 3 | [Domain] 4 | tf_im = 30 5 | Nt_im = 800 6 | 7 | tf_re = 30 8 | Nt_re = 800 9 | 10 | Lx = 12.4407 11 | Ly = 12.4407 12 | Lz = 12.4407 13 | Nx = 30 14 | Ny = 30 15 | Nz = 30 16 | 17 | boundary = zero 18 | 19 | 20 | [Equations] 21 | alpha = 1e-2 22 | beta = 1 23 | 24 | [Other] 25 | frames = 200 -------------------------------------------------------------------------------- /NonlinearSchrodingerSolver1DFD/convolutionTest.m: -------------------------------------------------------------------------------- 1 | close all 2 | 3 | n = 1000; 4 | xMin = -2*pi; % x domain min 5 | xMax = 2*pi; % x domain max 6 | xDom = linspace(xMin,xMax,n); 7 | dx = xDom(2)-xDom(1); 8 | 9 | sigma = 1; 10 | y = (1/(sigma*sqrt(2*pi)))*exp(-.5*(xDom/sigma).^2); 11 | 12 | sigma = .01; 13 | 14 | y2 = .0125*(1/(sigma*sqrt(2*pi)))*exp(-.5*(xDom/sigma).^2); 15 | 16 | 17 | y3 = conv(y,y2, 'same'); 18 | y4 = fftshift( ifft(fft(y).*fft(y2)) ); 19 | 20 | plot(xDom,y, xDom, y2, xDom, y3, xDom, y4) 21 | -------------------------------------------------------------------------------- /NonlinearSchrodingerSolver1DFD/nls.m: -------------------------------------------------------------------------------- 1 | function [ dPsi ] = nls( t, Psi, k, Vx, c1, c2, c3) %#ok 2 | % Solves the NLS using a pseudospectral fft method 3 | % input requires parameters (k, Vx, c1, c2, c3) 4 | % i.e. time dependent schrodinger equation with linear potential and 5 | % nonlinear square term... 6 | % 7 | % dPsi d^2Psi 8 | % ---- = c1*------ + c2*V(x) + c3*|Psi|^2*Psi 9 | % dt dx^2 10 | % 11 | uxx = (ifft( (k*1i).^2 .* fft(Psi) ) ); 12 | uNL = abs(Psi).^2.*Psi; 13 | dPsi = c1.*uxx + c2*Vx.*Psi + c3*uNL; 14 | 15 | end 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComputationalElectromagnetics 2 | 3 | 1. 1D FDTD examples illustrate alterations to the frequency spectrum of a ultrashort laser pulse when encountering homogeneous and inhomogeneous media described using two-level atom models. 4 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData2.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/newData3.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/FDTD Tester/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/TROptim.m: -------------------------------------------------------------------------------- 1 | function [TInv RrevInv] = TROptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | Lrev = L(end:-1:1); 10 | nrev = n(end:-1:1); 11 | [Rrev, rrev, Trev, trev] = transferMatrixOne(lambda, nrev, Lrev, sigma); 12 | 13 | %% 14 | TInv = 1/(T*100); 15 | RrevInv = 1/(Rrev*100); 16 | 17 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/TROptimSum.m: -------------------------------------------------------------------------------- 1 | function [sums] = TROptimSum(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | Lrev = L(end:-1:1); 10 | nrev = n(end:-1:1); 11 | [Rrev, rrev, Trev, trev] = transferMatrixOne(lambda, nrev, Lrev, sigma); 12 | 13 | %% 14 | TInv = 1/(T*100); 15 | RrevInv = 1/(Rrev*100); 16 | sums = 1/((T*3.4+Rrev)*100); 17 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/gainFun.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, T, tauPicoR, tauPicoT, phaseR, phaseT] = gainFun(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = lambdas(end)-lambdas(end-1); 12 | phi = phase(r); 13 | phaseR = phi; 14 | phiDot = gradient(phi,lambdaStep); 15 | 16 | for k = 3:lambdaSteps-20; 17 | 18 | meanPhase = abs(mean(phiDot(1:k+10))); 19 | 20 | if abs(phiDot(k)) > 5*meanPhase 21 | phiDot(k) = (phiDot(k+2) + phiDot(k-2))/2; 22 | end 23 | 24 | 25 | end 26 | lambdaStep = lambdas(end)-lambdas(end-1); 27 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 28 | PHIdot = ppval(lambdas, ppPHIdot); 29 | phiDot = PHIdot; 30 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 31 | tauPicoR = tau.*10e12; 32 | 33 | %% Calculations of group delay for solution with no gain 34 | lambdaStep2 = lambdas(end)-lambdas(end-1); 35 | phi2 = phase(t); 36 | phaseT = phi2; 37 | 38 | phiDot2 = gradient(phi2,lambdaStep2); 39 | for k = 3:lambdaSteps-20; 40 | 41 | meanPhase = abs(mean(phiDot2(1:k+10))); 42 | 43 | if abs(phiDot2(k)) > 5*meanPhase 44 | phiDot2(k) = (phiDot2(k+2) + phiDot2(k-2))/2; 45 | end 46 | 47 | 48 | end 49 | lambdaStep2 = lambdas(end)-lambdas(end-1); 50 | ppPHIdot2 = pchip(lambdas(1:2:end), phiDot2(1:2:end)); 51 | PHIdot2 = ppval(lambdas, ppPHIdot2); 52 | phiDot2 = PHIdot2; 53 | tau2 = -lambdas.^2./(2.*pi.*cNot).*phiDot2; 54 | tauPicoT = tau2.*10e12; 55 | 56 | 57 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/gainOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (R).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/gainOptimSum.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptimSum(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (R+T).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/matlab.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/matlab.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/storage.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/storage.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/transOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = TROptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (T).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain Sections/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/gainFun.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, T, tauPicoR, tauPicoT, phaseR, phaseT] = gainFun(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = lambdas(end)-lambdas(end-1); 12 | phi = phase(r); 13 | phaseR = phi; 14 | phiDot = gradient(phi,lambdaStep); 15 | 16 | for k = 3:lambdaSteps-20; 17 | 18 | meanPhase = abs(mean(phiDot(1:k+10))); 19 | 20 | if abs(phiDot(k)) > 5*meanPhase 21 | phiDot(k) = (phiDot(k+2) + phiDot(k-2))/2; 22 | end 23 | 24 | 25 | end 26 | lambdaStep = lambdas(end)-lambdas(end-1); 27 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 28 | PHIdot = ppval(lambdas, ppPHIdot); 29 | phiDot = PHIdot; 30 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 31 | tauPicoR = tau.*10e12; 32 | 33 | %% Calculations of group delay for solution with no gain 34 | lambdaStep2 = lambdas(end)-lambdas(end-1); 35 | phi2 = phase(t); 36 | phaseT = phi2; 37 | 38 | phiDot2 = gradient(phi2,lambdaStep2); 39 | for k = 3:lambdaSteps-20; 40 | 41 | meanPhase = abs(mean(phiDot2(1:k+10))); 42 | 43 | if abs(phiDot2(k)) > 5*meanPhase 44 | phiDot2(k) = (phiDot2(k+2) + phiDot2(k-2))/2; 45 | end 46 | 47 | 48 | end 49 | lambdaStep2 = lambdas(end)-lambdas(end-1); 50 | ppPHIdot2 = pchip(lambdas(1:2:end), phiDot2(1:2:end)); 51 | PHIdot2 = ppval(lambdas, ppPHIdot2); 52 | phiDot2 = PHIdot2; 53 | tau2 = -lambdas.^2./(2.*pi.*cNot).*phiDot2; 54 | tauPicoT = tau2.*10e12; 55 | 56 | 57 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/gainOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (R).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/phaseOptim.m: -------------------------------------------------------------------------------- 1 | function [gainSumInv] = phaseOptim(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = (lambdas(end)-lambdas(end-1))*1e9; 12 | gainSumInv = length(lambdas)/(sum(R)*100); 13 | 14 | 15 | 16 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/phaseOptimizerMfile.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/phaseOptimizerMfile.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/storage.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/storage.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain in an interval/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/gainFun.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, T, tauPicoR, tauPicoT, phaseR, phaseT] = gainFun(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = lambdas(end)-lambdas(end-1); 12 | phi = phase(r); 13 | phaseR = phi; 14 | phiDot = gradient(phi,lambdaStep); 15 | 16 | for k = 3:lambdaSteps-20; 17 | 18 | meanPhase = abs(mean(phiDot(1:k+10))); 19 | 20 | if abs(phiDot(k)) > 5*meanPhase 21 | phiDot(k) = (phiDot(k+2) + phiDot(k-2))/2; 22 | end 23 | 24 | 25 | end 26 | lambdaStep = lambdas(end)-lambdas(end-1); 27 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 28 | PHIdot = ppval(lambdas, ppPHIdot); 29 | phiDot = PHIdot; 30 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 31 | tauPicoR = tau.*10e12; 32 | 33 | %% Calculations of group delay for solution with no gain 34 | lambdaStep2 = lambdas(end)-lambdas(end-1); 35 | phi2 = phase(t); 36 | phaseT = phi2; 37 | 38 | phiDot2 = gradient(phi2,lambdaStep2); 39 | for k = 3:lambdaSteps-20; 40 | 41 | meanPhase = abs(mean(phiDot2(1:k+10))); 42 | 43 | if abs(phiDot2(k)) > 5*meanPhase 44 | phiDot2(k) = (phiDot2(k+2) + phiDot2(k-2))/2; 45 | end 46 | 47 | 48 | end 49 | lambdaStep2 = lambdas(end)-lambdas(end-1); 50 | ppPHIdot2 = pchip(lambdas(1:2:end), phiDot2(1:2:end)); 51 | PHIdot2 = ppval(lambdas, ppPHIdot2); 52 | phiDot2 = PHIdot2; 53 | tau2 = -lambdas.^2./(2.*pi.*cNot).*phiDot2; 54 | tauPicoT = tau2.*10e12; 55 | 56 | 57 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/gainOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptim(lambda, n, L, sigma, scale) 2 | 3 | L = L/scale; 4 | 5 | %Constants 6 | cNot = 2.99792458e8; % Speed of light 7 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 8 | 9 | % solution with gain 10 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 11 | 12 | %% 13 | gain = (R).*100; 14 | gainInv = -gain; 15 | 16 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/gainOptimL.m: -------------------------------------------------------------------------------- 1 | function [negGain] = gainOptimL(lambda, n, x, lWell, numWell, sigma, scaleFactor) 2 | global storage 3 | global storageInit 4 | global pop 5 | 6 | % Grating in active region 7 | 8 | lH = x(2)/scaleFactor; % Widths of surrounding cladding (High refractive index) 9 | lL = x(1)/scaleFactor; % Widths of surrounding cladding (Low refractive index) 10 | LActive = repmat([ lH , lWell, lL], 1, numWell); 11 | L = LActive; 12 | 13 | %Constants 14 | cNot = 2.99792458e8; % Speed of light 15 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 16 | 17 | % solution with gain 18 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 19 | 20 | %% 21 | gain = (R).*100; 22 | negGain= -gain; 23 | 24 | if length(storageInit) < pop; 25 | storageInit = [x(1)/scaleFactor, x(2)/scaleFactor; storageInit]; 26 | else 27 | storage = [x(1)/scaleFactor, x(2)/scaleFactor; storage]; 28 | end 29 | 30 | % 31 | % storage 32 | % storageInit 33 | 34 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/matlab.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/matlab.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData2.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData3.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newData3.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newStorage.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/newStorage.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/weekendRun.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Gain/weekendRun.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/gainFun.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, T, tauPicoR, tauPicoT, phaseR, phaseT] = gainFun(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = lambdas(end)-lambdas(end-1); 12 | phi = phase(r); 13 | phaseR = phi; 14 | phiDot = gradient(phi,lambdaStep); 15 | 16 | for k = 3:lambdaSteps-20; 17 | 18 | meanPhase = abs(mean(phiDot(1:k+10))); 19 | 20 | if abs(phiDot(k)) > 5*meanPhase 21 | phiDot(k) = (phiDot(k+2) + phiDot(k-2))/2; 22 | end 23 | 24 | 25 | end 26 | lambdaStep = lambdas(end)-lambdas(end-1); 27 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 28 | PHIdot = ppval(lambdas, ppPHIdot); 29 | phiDot = PHIdot; 30 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 31 | tauPicoR = tau.*10e12; 32 | 33 | %% Calculations of group delay for solution with no gain 34 | lambdaStep2 = lambdas(end)-lambdas(end-1); 35 | phi2 = phase(t); 36 | phaseT = phi2; 37 | 38 | phiDot2 = gradient(phi2,lambdaStep2); 39 | for k = 3:lambdaSteps-20; 40 | 41 | meanPhase = abs(mean(phiDot2(1:k+10))); 42 | 43 | if abs(phiDot2(k)) > 5*meanPhase 44 | phiDot2(k) = (phiDot2(k+2) + phiDot2(k-2))/2; 45 | end 46 | 47 | 48 | end 49 | lambdaStep2 = lambdas(end)-lambdas(end-1); 50 | ppPHIdot2 = pchip(lambdas(1:2:end), phiDot2(1:2:end)); 51 | PHIdot2 = ppval(lambdas, ppPHIdot2); 52 | phiDot2 = PHIdot2; 53 | tau2 = -lambdas.^2./(2.*pi.*cNot).*phiDot2; 54 | tauPicoT = tau2.*10e12; 55 | 56 | 57 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/gainOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (R).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/phaseOptim.m: -------------------------------------------------------------------------------- 1 | function [gainSumInv] = phaseOptim(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | phi = phase(r); 12 | phaseR = phi; 13 | lambdaStep = lambdas(end)-lambdas(end-1); 14 | phiDot = gradient(phi,lambdaStep); 15 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 16 | PHIdot = ppval(lambdas, ppPHIdot); 17 | phiDot = PHIdot; 18 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 19 | tauPicoR = tau.*10e12; 20 | lambdaStep = (lambdas(end)-lambdas(end-1))*1e9; 21 | gainSumInv = length(lambdas)/(abs(sum(tauPicoR))); 22 | 23 | 24 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/phaseOptimizerMfile.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/phaseOptimizerMfile.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/storage.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/storage.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize Group Delay/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/[a b] = gainFunNew(L).mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/[a b] = gainFunNew(L).mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/gainFun.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, T, tauPicoR, tauPicoT, phaseR, phaseT] = gainFun(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = lambdas(end)-lambdas(end-1); 12 | phi = phase(r); 13 | phaseR = phi; 14 | phiDot = gradient(phi,lambdaStep); 15 | 16 | for k = 3:lambdaSteps-20; 17 | 18 | meanPhase = abs(mean(phiDot(1:k+10))); 19 | 20 | if abs(phiDot(k)) > 5*meanPhase 21 | phiDot(k) = (phiDot(k+2) + phiDot(k-2))/2; 22 | end 23 | 24 | 25 | end 26 | lambdaStep = lambdas(end)-lambdas(end-1); 27 | ppPHIdot = pchip(lambdas(1:2:end), phiDot(1:2:end)); 28 | PHIdot = ppval(lambdas, ppPHIdot); 29 | phiDot = PHIdot; 30 | tau = -lambdas.^2./(2.*pi.*cNot).*phiDot; 31 | tauPicoR = tau.*10e12; 32 | 33 | %% Calculations of group delay for solution with no gain 34 | lambdaStep2 = lambdas(end)-lambdas(end-1); 35 | phi2 = phase(t); 36 | phaseT = phi2; 37 | 38 | phiDot2 = gradient(phi2,lambdaStep2); 39 | for k = 3:lambdaSteps-20; 40 | 41 | meanPhase = abs(mean(phiDot2(1:k+10))); 42 | 43 | if abs(phiDot2(k)) > 5*meanPhase 44 | phiDot2(k) = (phiDot2(k+2) + phiDot2(k-2))/2; 45 | end 46 | 47 | 48 | end 49 | lambdaStep2 = lambdas(end)-lambdas(end-1); 50 | ppPHIdot2 = pchip(lambdas(1:2:end), phiDot2(1:2:end)); 51 | PHIdot2 = ppval(lambdas, ppPHIdot2); 52 | phiDot2 = PHIdot2; 53 | tau2 = -lambdas.^2./(2.*pi.*cNot).*phiDot2; 54 | tauPicoT = tau2.*10e12; 55 | 56 | 57 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/gainOptim.m: -------------------------------------------------------------------------------- 1 | function [gainInv] = gainOptim(lambda, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma); 9 | 10 | %% 11 | gain = (R).*100; 12 | gainInv = 1/gain; 13 | 14 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/optJun11.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/optJun11.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/phaseOptim.m: -------------------------------------------------------------------------------- 1 | function [gainSumInv, phaseCurveNorm] = phaseOptim(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = (lambdas(end)-lambdas(end-1))*1e9; 12 | phi = phase(r); 13 | phaseR = phi; 14 | phaseCurve = (phi(3:end) - 2.*phi(2:end-1) + phi(1:end-2))./(lambdaStep).^2; 15 | phaseCurveNorm = norm(phaseCurve,2); 16 | 17 | gainSumInv = length(lambdas)/sum(R*100); 18 | 19 | 20 | 21 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/phaseOptimOne.m: -------------------------------------------------------------------------------- 1 | function [compilation] = phaseOptimOne(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma, tolerance) 2 | 3 | %Constants 4 | cNot = 2.99792458e8; % Speed of light 5 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 6 | 7 | % solution with gain 8 | [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma); 9 | 10 | %% Calculations of group delay 11 | lambdaStep = (lambdas(end)-lambdas(end-1))*1e9; 12 | phi = phase(r); 13 | phaseR = phi; 14 | phaseCurve = (phi(3:end) - 2.*phi(2:end-1) + phi(1:end-2))./(lambdaStep).^2; 15 | phaseCurveNorm = norm(phaseCurve,2); 16 | gainSumInv = length(lambdas)/sum(R*100); 17 | 18 | compilation = gainSumInv + phaseCurveNorm*tolerance; 19 | compilation = phaseCurveNorm; 20 | 21 | end -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/s.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/s.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/storage.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/storage.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/storage2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/storage2.mat -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/2nd Transfer Matrix Optimizer/Optimize phase and gain/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/Transfer Matrix Gain Optimizer/consFun.m: -------------------------------------------------------------------------------- 1 | function [ cons, consEq ] = consFun( x, grateSize ) 2 | %CONSFUN Summary of this function goes here 3 | % Detailed explanation goes here 4 | 5 | cons = (sum(x) - grateSize).*1e7; 6 | consEq = []; 7 | 8 | end 9 | 10 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/Transfer Matrix Gain Optimizer/perturbations.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/briandaniel/ComputationalElectromagnetics/dc7a539a8c81a116919bc841c00a30d78a34774d/VECSEL-GA-Optimizer/Transfer Matrix Gain Optimizer/perturbations.fig -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/Transfer Matrix Gain Optimizer/transferMatrix.m: -------------------------------------------------------------------------------- 1 | function [lambdas, R, r, T, t] = transferMatrix(lambdaMin, lambdaMax, lambdaSteps, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | lambdas = linspace(lambdaMin, lambdaMax, lambdaSteps); 8 | grateLength = sum(L); 9 | cellNum = length(L); 10 | 11 | Mi = zeros(2,2); 12 | r = zeros(length(lambdas),1); 13 | t = zeros(length(lambdas),1); 14 | 15 | eps = n.^2; 16 | 17 | 18 | for w = 1:length(lambdas); 19 | 20 | lambda = lambdas(w); 21 | ko = 2*pi*n(1)/lambda; 22 | kf = 2*pi*n(end)/lambda; 23 | M = eye(2,2); 24 | freq = cNot/lambda; 25 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 26 | nW = sqrt(eps); 27 | 28 | for s = 1:cellNum; 29 | 30 | kl = 2*pi*nW(s+1)*L(s)/lambda; 31 | k = kl/(L(s)); 32 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 33 | M = Mi*M; 34 | 35 | end 36 | 37 | r(w) = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 38 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 39 | 40 | 41 | t(w) = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 42 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 43 | 44 | end 45 | 46 | R = abs(r).^2; 47 | T = abs(t).^2; 48 | -------------------------------------------------------------------------------- /VECSEL-GA-Optimizer/Transfer Matrix Gain Optimizer/transferMatrixOne.m: -------------------------------------------------------------------------------- 1 | function [R, r, T, t] = transferMatrixOne(lambda, n, L, sigma) 2 | %Constants 3 | cNot = 2.99792458e8; % Speed of light 4 | epsNot = 8.854187817620e-12; % Permittivity of Free Space 5 | 6 | %Initilization 7 | grateLength = sum(L); 8 | cellNum = length(L); 9 | 10 | Mi = zeros(2,2); 11 | r = zeros(length(lambda),1); 12 | t = zeros(length(lambda),1); 13 | 14 | eps = n.^2; 15 | 16 | ko = 2*pi*n(1)/lambda; 17 | kf = 2*pi*n(end)/lambda; 18 | M = eye(2,2); 19 | freq = cNot/lambda; 20 | eps = n.^2 + i.*sigma./(freq.*2*pi*epsNot); 21 | nW = sqrt(eps); 22 | 23 | for s = 1:cellNum; 24 | 25 | kl = 2*pi*nW(s+1)*L(s)/lambda; 26 | k = kl/(L(s)); 27 | Mi = [cos(kl), 1/k*sin(kl); -k*sin(kl), cos(kl)]; 28 | M = Mi*M; 29 | 30 | end 31 | 32 | r = ((M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)-kf*M(1,1)))... 33 | /((-M(2,1)+ko*kf*M(1,2))+1i*(ko*M(2,2)+kf*M(1,1))); 34 | 35 | 36 | t = 2*1i*ko*exp(-1i*kf*grateLength)*(M(1,1)*M(2,2)-M(1,2)*M(2,1))... 37 | /(-M(2,1)+ko*kf*M(1,2)+1i*(kf*M(1,1)+ko*M(2,2))); 38 | 39 | R = abs(r).^2; 40 | T = abs(t).^2; 41 | --------------------------------------------------------------------------------