% Experiment of Finding Beta
% This prog is based on CEs given in (3.17) and (3.22) of lecture notes, entitled
% "ECE 635_Notes on Fibre Propagation_Jan_2013_HTE" available on
% ece635.cankaya.edu.tr course webpage
close all;clear;clc;clf reset
unset = 0.1:0.1:10;wnset = 0.1:0.1:10;
%wnset = sqrt(V^2 - unset.^2);
n1 = 1.50;n2 = 1.468;v = 4;%n1 = 1.47028; n2 = 1.45709;
lamda = 1.55e-6;k1 = 2*pi*n1/lamda;k2 = 2*pi*n2/lamda;k = 2*pi / lamda;
[un,wn]=meshgrid(unset,wnset);
vstr = [' , \itv \rm\bf= ' num2str(v)];vstrTETM = [' , \itv \rm\bf= ' num2str(0)];
% Case of HE and EH Modes
% CE_HEEH_322 = (besselj(v+1,un)./(un.*besselj(v,un))   +    besselk(v+1,wn)./(wn.*besselk(v,wn))).* ....
%      (n1^2*besselj(v-1,un)./(un.*besselj(v,un)) - n2^2*besselk(v-1,wn)./(wn.*besselk(v,wn)))+ .... 
%           (besselj(v-1,un)./(un.*besselj(v,un))   -    besselk(v-1,wn)./(wn.*besselk(v,wn))).* ....
%      (n1^2*besselj(v+1,un)./(un.*besselj(v,un)) + n2^2*besselk(v+1,wn)./(wn.*besselk(v,wn))); 
CE_HEEH_322 = (besselj(v+1,un)./un   +    besselj(v,un).*besselk(v+1,wn)./(wn.*besselk(v,wn))).* ....
     (n1^2*besselj(v-1,un)./un - n2^2*besselj(v,un).*besselk(v-1,wn)./(wn.*besselk(v,wn)))+ .... 
          (besselj(v-1,un)./un   -    besselj(v,un).*besselk(v-1,wn)./(wn.*besselk(v,wn))).* ....
     (n1^2*besselj(v+1,un)./un + n2^2*besselj(v,un).*besselk(v+1,wn)./(wn.*besselk(v,wn)));  
% Case of TE Modes
% CE_TE_317 = besselj(1,un)./(un.*besselj(0,un)) + besselk(1,wn)./(wn.*besselk(0,wn));% Actual equation, singular
CE_TE_320 = besselj(1,un)./un      + besselj(0,un).*besselk(1,wn)./(wn.*besselk(0,wn));
% Case of TM Modes
% First two are actual equations, but they create singularities 
% CE_TM_317 = (2*pi*n1/lamda)^2*besselj(1,un)./(un*besselj(0,un)) + (2*pi*n2/lamda)^2*besselk(1,wn)./(wn*besselk(0,wn)); 
% CE_TM_317 = n1^2*besselj(1,un)./(un.*besselj(0,un)) + n2^2*besselk(1,wn)./(wn.*besselk(0,wn));  
CE_TM_320 = n1^2*besselj(1,un)./un + n2^2*besselj(0,un).*besselk(1,wn)./(wn.*besselk(0,wn)); 
%CE = CE_HEEH_322;CE = CE_TE_320;CE = CE_TM_320;
%CE = CE / max(max(abs(CE)));
figure(1)
set(gcf,'Renderer','Zbuffer');set(gcf,'Color',[1 1 1]);
meshc(un,wn,CE_TM_320);set(gca,'FontSize',16);colormap colorcube;%view([-21.5 60.0])
title('3D Plot of Characteristic Equation (CE) for TM_0_m modes','FontSize',14,'FontWeight','bold');
xlabel('\itu_n','FontSize',14,'FontWeight','bold');
ylabel('\itw_n','FontSize',14,'FontWeight','bold');
figure(2)
[C,h] = contour(un,wn,CE_TM_320,'--k');axis square;grid on
set(h,'LineWidth',2);H = clabel(C,h,[0]);set(H,'FontSize',10,'LineWidth',2);
set(gca,'FontSize',13);set(gcf,'Color',[1 1 1]);hold on
V2 = un.^2 + wn.^2;V = sqrt(V2);[C,h] = contour(un,wn,V,'-k');set(h,'LineWidth',2);
H = clabel(C,h);set(H,'FontSize',12,'LineWidth',3);set(H,'LineWidth',2,'BackgroundColor','white','Edgecolor',[.1 .8 .1]);
legtitle = ['Contour plot of TM_0_m modes and different \itV \rm\bfcircles' vstrTETM];
title(legtitle,'FontSize',16,'FontWeight','bold');
xlabel('\itu_n','FontSize',14,'FontWeight','bold');
ylabel('\itw_n','FontSize',14,'FontWeight','bold');

figure(3)
[C,h] = contour(un,wn,CE_TE_320,'--k');axis square;grid on
set(h,'LineWidth',2);H = clabel(C,h,[0]);set(H,'FontSize',10,'LineWidth',2);
set(gca,'FontSize',13);set(gcf,'Color',[1 1 1]);hold on
V2 = un.^2 + wn.^2;V = sqrt(V2);[C,h] = contour(un,wn,V,'-k');set(h,'LineWidth',2);
H = clabel(C,h);set(H,'FontSize',12,'LineWidth',3);set(H,'LineWidth',2,'BackgroundColor','white','Edgecolor',[.1 .8 .1]);
legtitle = ['Contour plot of TE_0_m modes and different \itV \rm\bfcircles' vstrTETM];
title(legtitle,'FontSize',16,'FontWeight','bold');
xlabel('\itu_n','FontSize',14,'FontWeight','bold');
ylabel('\itw_n','FontSize',14,'FontWeight','bold');

figure(4)
[C,h] = contour(un,wn,CE_HEEH_322,'--k');axis square;grid on
set(h,'LineWidth',2);H = clabel(C,h,[0]);set(H,'FontSize',10,'LineWidth',2);
set(gca,'FontSize',13);set(gcf,'Color',[1 1 1]);hold on
V2 = un.^2 + wn.^2;V = sqrt(V2);[C,h] = contour(un,wn,V,'-k');set(h,'LineWidth',2);
H = clabel(C,h);set(H,'FontSize',12,'LineWidth',3);set(H,'LineWidth',2,'BackgroundColor','white','Edgecolor',[.1 .8 .1]);
legtitle = ['Contour plot of HE and EH modes and different \itV \rm\bfcircles' vstr];
title(legtitle,'FontSize',16,'FontWeight','bold');
xlabel('\itu_n','FontSize',14,'FontWeight','bold');
ylabel('\itw_n','FontSize',14,'FontWeight','bold')