├── Results.PNG ├── README.md ├── LICENSE ├── TE_solve_f.m ├── TM_solve_f.m ├── TM_solve_f2.m └── WaveGuide1D_Main.m /Results.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentNevou/Light_WaveGuide1D/HEAD/Results.PNG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WaveGuide1D 2 | Compute effective mode in a 1D wave guide; 3 | Solve the Helmholtz-Maxwell equation in a 1D waveguide 4 | 5 | => If you like it, don't forget the star! 6 | 7 | ![image](https://user-images.githubusercontent.com/35040499/113291779-cc772280-92f3-11eb-9372-c359e1120265.png) 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 LaurentNevou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TE_solve_f.m: -------------------------------------------------------------------------------- 1 | function[Ex,neff,alpha]=TE_solve_f(y,eps,lambda,nmodes,neff_min,neff_max) 2 | 3 | k0 = 2*pi/lambda; 4 | dy=y(2)-y(1); 5 | 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 7 | %%%%%%%%%%%%%%%%%%%%%%%%%% Building of the operators %%%%%%%%%%%%%%%%%%%%%%%%%%% 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | tic 10 | AA=ones(1,length(y)); 11 | BB=ones(1,length(y)-1); 12 | 13 | DY2=(-2)*diag(AA) + diag(BB,1) + diag(BB,-1); 14 | 15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | %%%%%%%%%%%%%%%%%%%% Building and solving of the Hamiltonien %%%%%%%%%%%%%%%%%%% 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | H = DY2/dy^2 + diag(eps) * k0^2; 20 | 21 | %H=sparse(H); 22 | %[Ex,Beta] = eigs(H,nmodes,'LR'); 23 | [Ex,Beta] = eig(H); 24 | 25 | neff=sqrt(diag(Beta))/k0; 26 | 27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 28 | %%%%%%%%%%%%%%%%%%% Filtering and reshaping the Wavefunction %%%%%%%%%%%%%%%%%%% 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | 31 | idx1=real(neff)>neff_min; 32 | idx2=real(neff)1 50 | if neff(2)>neff(1) 51 | Ex=Ex(:,end:-1:1); 52 | neff=neff(end:-1:1); 53 | end 54 | end 55 | 56 | end 57 | 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 61 | -------------------------------------------------------------------------------- /TM_solve_f.m: -------------------------------------------------------------------------------- 1 | function[Ey,neff,alpha]=TM_solve_f(y,eps,lambda,nmodes,neff_min,neff_max) 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | 7 | c = 2.99792458e8; %% m/s 8 | eps0 = 8.85418782e-12; %% F/m 9 | mu0 = 4*pi*1e-7; %% H/m 10 | 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | 13 | k0 = 2*pi/lambda; 14 | w = c*k0; 15 | %eps(1) = eps(end) = 1; 16 | dy=y(2)-y(1); 17 | 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | %%%%%%%%%%%%%%%%%%%%%%%%% Building of the operators %%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 21 | 22 | AA=ones(1,length(y)); 23 | BB=ones(1,length(y)-1); 24 | 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% First derivative %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | 27 | DY1 = (-0.5)*diag(BB,-1) + (0.5)*diag(BB,1); %symetric derivative 28 | 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Second derivative %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | 31 | DY2 = (-2)*diag(AA) + (1)*diag(BB,1) + (1)*diag(BB,-1); 32 | 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | %%%%%%%%%%%%%%%%%%%% Building and solving of the Hamiltonien %%%%%%%%%%%%%%%%%%% 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | 37 | H0 = DY2/dy^2 + diag(eps(:)) * k0^2; 38 | 39 | % Those 2 writtings give the same result!!! 40 | H = H0 + diag(eps) * diag( DY1*(1./(eps(:))) ) * DY1 /dy^2 ; 41 | %H = H0 - diag(1./eps) * diag( DY1*eps(:) ) * DY1 /dy^2 ; 42 | 43 | % Like in 2D, it gives different results with the folowing writting 44 | %H = H0 - diag( DY1*log(eps(:)) ) * DY1 /dy^2 ; 45 | 46 | 47 | %H=sparse(H); 48 | %[Hx,Beta] = eigs(H,nmodes,'LR'); 49 | [Hx,Beta] = eig(H); 50 | Beta = diag(Beta); 51 | 52 | neff=sqrt(Beta)/k0; 53 | 54 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 55 | %%%%%%%%%%%%%%%%%%% Filtering and reshaping the Wavefunction %%%%%%%%%%%%%%%%%%% 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 57 | 58 | idx1=real(neff)>neff_min; 59 | idx2=real(neff)1 80 | if neff(2)>neff(1) 81 | Ey=Ey(:,end:-1:1); 82 | neff=neff(end:-1:1); 83 | end 84 | end 85 | 86 | end 87 | 88 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 92 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 94 | -------------------------------------------------------------------------------- /TM_solve_f2.m: -------------------------------------------------------------------------------- 1 | function[Ey,neff,alpha]=TM_solve_f2(y,eps,lambda,nmodes,neff_min,neff_max) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | % One problem here is the operator (d/z)*(1/eps(z))*(d/z) inside the Wave equation 6 | % Without any modification, the results are not accurate and show discontinuity 7 | % at the material interface due to the difference of epsilon 8 | % One very nice approach is to use the mid-point mass: 9 | 10 | % Paul Harrisson 11 | % Quantum Wells, Wires and Dots. 12 | % 4th edition (2016), 13 | % chap 3 : "Numerical Solutions" 14 | % 3.13: "Extention to variable effective mass" 15 | % page 102 16 | 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 20 | 21 | c = 2.99792458e8; %% m/s 22 | eps0 = 8.85418782e-12; %% F/m 23 | mu0 = 4*pi*1e-7; %% H/m 24 | 25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 26 | 27 | k0 = 2*pi/lambda; 28 | w = c*k0; 29 | %eps(1) = eps(end) = 1; 30 | dy=y(2)-y(1); 31 | Ny=length(y); 32 | 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 34 | %%%%%%%%%%%%%%%%%%%%%%%%%% Building of the operators %%%%%%%%%%%%%%%%%%%%%%%%%%% 35 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 | 37 | epsp = [ (eps(1:end-1) + eps(2:end)) / 2 eps(end) ]; 38 | epsm = [ eps(1) (eps(1:end-1) + eps(2:end)) / 2 ]; 39 | 40 | b = (1./epsp + 1./epsm) .* ones(1,Ny) ; 41 | a = 1./epsm(2:end) .* ones(1,Ny-1) ; 42 | c = 1./epsm(2:end) .* ones(1,Ny-1) ; 43 | 44 | DY2 = (-1)*diag(b) + (1)*diag(a,-1) + (1)*diag(c,+1) ; 45 | 46 | DY2 = DY2 / dy^2; 47 | 48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 49 | %%%%%%%%%%%%%%%%%%%%%%%% Building of the Hamiltonien %%%%%%%%%%%%%%%%%%%%%%%%%%% 50 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 51 | % If the equation is correct (which I am not sure), 52 | % the solver is for sure vey well accurate 53 | 54 | H = diag(eps(:)) * DY2 + diag(eps(:)) * k0^2; 55 | 56 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 57 | %%%%%%%%%%%%%%%%%%%% Building and solving of the Hamiltonien %%%%%%%%%%%%%%%%%%% 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 59 | 60 | %H=sparse(H); 61 | %[Hx,Beta] = eigs(H,nmodes,'LR'); 62 | [Hx,Beta] = eig(H); 63 | Beta = diag(Beta); 64 | 65 | neff=sqrt(Beta)/k0; 66 | 67 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 68 | %%%%%%%%%%%%%%%%%%% Filtering and reshaping the Wavefunction %%%%%%%%%%%%%%%%%%% 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 70 | 71 | idx1=real(neff)>neff_min; 72 | idx2=real(neff)1 93 | if neff(2)>neff(1) 94 | Ey=Ey(:,end:-1:1); 95 | neff=neff(end:-1:1); 96 | end 97 | end 98 | 99 | end 100 | 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 103 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 105 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 106 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 107 | -------------------------------------------------------------------------------- /WaveGuide1D_Main.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | %%%%%%%%%%%%%%%%%%%%%% last update 15July2019, lne %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | clear all 6 | close all 7 | clc 8 | 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 10 | %%%%%%%%%%%%%%%%%%%%%%%%% Solving Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | 13 | dy=1e-8; %% resolution in y 14 | lambda=2e-6; %% Wavelength (meter) 15 | 16 | neff_min=2; %% filter the solutions where the effective index is superior than 17 | neff_max=4; %% filter the solutions where the effective index is inferior than 18 | nmodes=2; %% number of solutions asked (not activated) 19 | ScF=0.5; 20 | 21 | TE=1; %% activate the calcul for the TE mode 22 | TM=1; %% activate the calcul for the TM mode 23 | 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 25 | 26 | print_neff=1; 27 | print_losses=0; 28 | 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 30 | %%%%%%%%%%%%%%%%%%%%%%% Optical index definition %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32 | 33 | % real index / imag index / thickness um / doping cm-3 / eff mass / Drude time ps 34 | 35 | M=[ 36 | 37 | 2 0 1 0 0.067 0.1 38 | 3 0 0.7 0 0.067 0.1 39 | 2 0 1 0 0.067 0.1 40 | 41 | ]; 42 | 43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 44 | %%%%%%%%%%%%% Computation of the imaginary part from the doping %%%%%%%%%%%%%%%% 45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 46 | 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 48 | c = 2.99792458E8; %% speed of light (m/s) 49 | e = 1.602176487E-19; %% electron charge (C) 50 | eps0 = 8.854187817620E-12; %% vaccum dielectric constant (F/m) 51 | mu0 = 1/(eps0*c^2); %% vaccum permeabiliy 52 | me = 9.10938188E-31; %% electron mass (kg) 53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 54 | 55 | w=2*pi*c/lambda; 56 | M(:,4)=M(:,4)*1E6; %% conversion of the doping from cm-3 to m-3 57 | M(:,5)=M(:,5)*me; 58 | M(:,6)=M(:,6)*1E-12; %% conversion of tau from ps to second 59 | 60 | for i=1:length(M(:,1)) 61 | 62 | Plasma_2=M(i,4)*e^2 / ( eps0 * M(i,5) ); %%% Plasma frequency 63 | Ki= - Plasma_2/(w^2+ 1i*w/M(i,6)); %%% suceptibility 64 | 65 | if isnan(Ki)==1 66 | Ki=0; 67 | end 68 | 69 | epst(i)=M(i,1)^2 + Ki ; 70 | 71 | nn=real( sqrt(epst(i)) ); 72 | kk=imag( sqrt(epst(i)) ); 73 | 74 | M(i,1)=nn; 75 | if kk~=0 76 | M(i,2)=kk; 77 | end 78 | 79 | end 80 | 81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 82 | %%%%%%%%%%%%%%%%%%%%%%%%%% Discretisation of Epsilon %%%%%%%%%%%%%%%%%%%%%%%%%%% 83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 84 | 85 | yt=M(:,3)*1E-6; % conversion of the length from um to meter 86 | 87 | y=[];eps=[]; 88 | y(1)=0;eps(1)=epst(1); 89 | 90 | for i=1:length(yt) 91 | t=yt(i); 92 | yv= (y(end)+dy): dy : (y(end)+dy)+t; 93 | y=[y yv]; 94 | epsv=ones(size(yv))*epst(i); 95 | eps=[eps epsv]; 96 | end 97 | 98 | n=sqrt(eps); 99 | 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 102 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 103 | 104 | if TE==1 105 | [Ex,neffTE,alphaTE]=TE_solve_f(y,eps,lambda,nmodes,neff_min,neff_max); 106 | n1=length(neffTE); 107 | 108 | if print_neff==1; 109 | neffTE 110 | end 111 | if print_losses==1 112 | alphaTE=alphaTE*0.01 %% losses conversion from [m-1] to [cm-1] 113 | end 114 | 115 | for i=1:n1 116 | Ex(:,i)=abs(Ex(:,i)).^2/max(abs(Ex(:,i)).^2)*ScF + real(neffTE(i)); % normalisation for the plotting 117 | end 118 | end 119 | 120 | if TM==1 121 | %[Ey,neffTM,alphaTM]=TM_solve_f(y,eps,lambda,nmodes,neff_min,neff_max); 122 | % => solves the correct equation but is numerically unstable when diff(eps) is high 123 | [Ey,neffTM,alphaTM]=TM_solve_f2(y,eps,lambda,nmodes,neff_min,neff_max); 124 | % => solves a slightly different equation (I am not sure how correct it is...) but very stable numerically 125 | n2=length(neffTM); 126 | 127 | if print_neff==1; 128 | neffTM 129 | end 130 | if print_losses==1 131 | alphaTM=alphaTM*0.01 %% losses conversion from [m-1] to [cm-1] 132 | end 133 | 134 | for i=1:n2 135 | Ey(:,i)=abs(Ey(:,i)).^2/max(abs(Ey(:,i)).^2)*ScF + real(neffTM(i)); % normalisation for the plotting 136 | end 137 | end 138 | 139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 143 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 144 | 145 | X0fig=50; Y0fig=10; 146 | Wfig=1200;Hfig=800; 147 | 148 | figure('Name','Electrical Field','position',[X0fig Y0fig Wfig Hfig]) 149 | 150 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 152 | 153 | subplot(111,'fontsize',20) 154 | hold on;grid on; 155 | 156 | %plot(y*1e6,abs(n),'b-','linewidth',2) % plot the refractive index 157 | plot(y*1e6,real(n),'b-','linewidth',2) 158 | 159 | s{1}='\fontsize{20}\color{blue}Optical index'; 160 | 161 | if TE==1 162 | for i=1:n1 163 | plot(y*1e6,Ex(:,i),'g','linewidth',2) % plot Ex for TE-modes 164 | end 165 | s{length(s)+1}='\fontsize{20}\color{green}TE-modes: Ex(y)'; 166 | end 167 | 168 | if TM==1 169 | for i=1:n2 170 | plot(y*1e6,Ey(:,i),'r-','linewidth',2) % plot Ey for TM-modes 171 | end 172 | s{length(s)+1}='\fontsize{20}\color{red}TM-modes: Ey(y)'; 173 | end 174 | 175 | 176 | 177 | 178 | xlabel('y (um)'); 179 | ylabel('effective index'); 180 | title(strcat('\lambda=',num2str(lambda*1e6,'%.3f'),'um; dy=',num2str(dy*1e9),'nm')) 181 | 182 | xscale=get(gca,'xlim'); 183 | yscale=get(gca,'ylim'); 184 | 185 | x0=0.8*xscale(end); 186 | y0=0.9*(yscale(end) - yscale(1)) + yscale(1); 187 | 188 | text(x0,y0,s) 189 | 190 | if TE==1 191 | sTE{1}='\fontsize{15}neff-TE'; 192 | sTE{2}='-----------'; 193 | for i=1:length(neffTE) 194 | sTE{i+2}=strcat(num2str(neffTE(i))); 195 | end 196 | y0=0.7*(yscale(end) - yscale(1)) + yscale(1); 197 | text(x0,y0,sTE) 198 | end 199 | 200 | if TM==1 201 | sTM{1}='\fontsize{15}neff-TM'; 202 | sTM{2}='-----------'; 203 | for i=1:length(neffTM) 204 | sTM{i+2}=strcat(num2str(neffTM(i))); 205 | end 206 | y0=0.7*(yscale(end) - yscale(1)) + yscale(1); 207 | text(x0*1.1,y0,sTM) 208 | end 209 | 210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 211 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 212 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 213 | --------------------------------------------------------------------------------