%Rafal Piersiak%
%12/3/1013%
%ESE 525%
%Generation of Bandgap and Cutoff Wavelength for HgCdTe infrared detector%
%Code creates two contour maps of Bandgap (eV) and Cutoff Wavelength (um)%
%vs. X (Normalized concentration of Cd compared to Hg+Cd)%\
%vs. temperature in Kelvin%

%HgCdTe Composition%
%Hg(x-1)*Cd(x)Te%
%x ranges from 0 to 1, represents percent)

clear all %clears workspace
clc %clears command window

k = 1.3806488E-23;      %(J*K^-1) Boltzsmann Constant
tt = 300;               %(Kelvin) is given
q = 1.602176565E-19;    %(C) electron charge

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Band Gap Plot%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XMin = 0.10;            %10%
XMax = 0.50;            %50%
XSteps = 1001;          %1001 steps
x = linspace(XMin,XMax,XSteps); %create linear array of widths between XMin and XMax

TMin = 0;               %0 Kelvin
TMax = 300;             %300 Kelvin
TSteps = 1001;          %1001 steps
t = linspace(TMin,TMax,TSteps); %create linear array of widths between TMin and TMax

[X,T] = meshgrid(x,t);          %mesh x and t values to make 3-D plot

Eg = -0.302 + 1.93.*X +(5.35*10^-4).*T.*(1-2.*X) - 0.31.*X.^2 + 0.832.*X.^3;    %calculate bandgap energy (eV)

figure(1)                               %figure 1
surf(X,T,Eg);                           %plot results as 3-D plot
colormap(jet);                          %set plot color scheme
shading interp;                         %interpolate the 3D graph colors
colorbar('location','eastoutside');     %set colorbar to the east, outside
title('Bandgap Voltage (eV) vs Temperature vs Percent of Cd');  %title
xlabel('Percent of Cd');                %x-axis label
ylabel('Temperature (K)');              %y-axix label
zlabel('Bandgap Voltage (eV)');         %z-axix label
view(0,90);                             %flatten z-axis; creates contour


%%%%%%%%%%%%%%%%%%%%%%%%%Cutoff Wavelength Plot%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XMin = 0.20;            %20%
XMax = 0.70;            %70%
XSteps = 1001;          %1001 steps
x = linspace(XMin,XMax,XSteps); %create linear array of widths between XMin and XMax

[X,T] = meshgrid(x,t);          %mesh x and t values to make 3-D plot

Lc = -0.244 + 1.556.*X +(4.31*10^-4).*T.*(1-2.*X) - 0.65.*X.^2 + 0.671.*X.^3;   %calculate cutoff wavelength (um)
Lc = 1./Lc;                                                                     %take inverse of Lc to get final wavelength.

figure(2)                               %figure 2
surf(X,T,Lc);                           %plot results as 3-D plot
cmap([1 0 0],500,20,10);                %set color, number of discrete colors, cut out x% darkest, cut out x% lightest
colormap(flipud(colormap));             %flip color map
shading interp;                         %interpolate the 3D graph colors
colorbar('location','eastoutside');     %set colorbar to the east, outside
title('Cuttoff Wavelength (\mum) vs Temperature vs Percent of Cd');  %title
xlabel('Percent of Cd');                %x-axis label
ylabel('Temperature (K)');              %y-axix label
zlabel('Cutoff Wavelength (\lambda)');  %z-axix label
view(0,90);                             %flatten z-axis; creates contour


%%%%%%%%%%%%%%%%%%%%%%%%%Intrinsic Carrier Plot%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XMin = 0.20;            %20%
XMax = 0.50;            %50%
XSteps = 1001;          %1001 steps
X = linspace(XMin,XMax,XSteps); %create linear array of widths between XMin and XMax

Kb = 8.6173324*10^-5;               %eV*K^-1
Tc = [77, 100, 150, 200, 250, 300]; %set 6 temperatures in Kelvin

figure(4)                           %figure 4

for i=1:6                           %plot carrier concentrations for all 6 temperatures

    T = Tc(i);                      %save ith temperature in T
    Eg = -0.302 + 1.93.*X +(5.35*10^-4)*T*(1-2.*X) - 0.31.*X.^2 + 0.832.*X.^3;  %calculate Eg for that temp
    Niplot = (5.585-3.82.*X+(1.7531^-3)*T-1.36411^-3*T.*X)*10^14.*Eg.^0.75*T^1.5.*exp((-Eg./(2*Kb*T))); %calculate Ni for that temp

    semilogy(X,Niplot,'LineWidth', 2);       %plot results
    hold all;                                %hold plot while plotting next plot
end

title('Intrinsic Carrier Concentration vs Percent of Cd at Several K'); %title
xlabel('Percent of Cd');                %x-axis label
ylabel('N_i');                          %y-axix label
[maxNi, index] = max(Niplot);           %find find max of Niplot
axis([XMin, XMax, 10^10 maxNi])         %set x, y, axis limits

text('Position',[0.24 2*10^10],'String',strcat(num2str(Tc(1)),'K'));    %print temperature on plot
text('Position',[0.31 2*10^10],'String',strcat(num2str(Tc(2)),'K'));    %print temperature on plot
text('Position',[0.39 2*10^10],'String',strcat(num2str(Tc(3)),'K'));    %print temperature on plot
text('Position',[0.45 7*10^10],'String',strcat(num2str(Tc(4)),'K'));    %print temperature on plot
text('Position',[0.45 3*10^12],'String',strcat(num2str(Tc(5)),'K'));    %print temperature on plot
text('Position',[0.45 5*10^13],'String',strcat(num2str(Tc(6)),'K'));    %print temperature on plot


%{
figure(3)                               %figure 2
surf(X,T,Ni);                           %plot results as 3-D plot
colormap(jet);                          %color map
shading interp;                         %interpolate the 3D graph colors
colorbar('location','eastoutside');     %set colorbar to the east, outside
title('Cuttoff Wavelength (\mum) vs Temperature vs Percent of Cd');  %title
xlabel('Percent of Cd');                %x-axis label
ylabel('Temperature (K)');              %y-axix label
zlabel('Cutoff Wavelength (\lambda)');  %z-axix label
view(0,90);                             %flatten z-axis; creates contour
%}


%{
XMin = 0.20;                   %100nm
XMax = 0.55;                   %1mm
XSteps = 1001;                  %1000 widths
x = linspace(XMin,XMax,XSteps); %create linear array of widths between WMin and WMax

[X,T] = meshgrid(x,t);

Eg = -0.302 + 1.93.*X +(5.35*10^-4).*T.*(1-2.*X) - 0.31.*X.^2 + 0.832.*X.^3;

EgSQ = real(sqrt(Eg));
Auger1 = (2.12*10^-14.*EgSQ.*exp((q.*Eg)./(k*tt)))/(0.221^2*(k*tt/q)^1.5);

figure(3)                               %figure 1
surf(X,T,Auger1);                 %plot results with mesh grid lines
%cmap([1 0 0],500,20,10);        %set color, number of discrete colors, cut of x% darkest, cut of x% lightest
colormap(jet);
colormap(flipud(colormap));     %flip color map
shading interp;                         %interpolate the 3D graph colors
colorbar('location','eastoutside');     %set colorbar to the east, outside
title('Cuttoff Wavelength vs Temperature vs Percent Cd');  %title
xlabel('Percent of Cd');             %x-axis label
ylabel('Temperature (K)');                   %y-axix label
zlabel('Cutoff Wavelength (\lambda)');              %z-axix label
view(0,90);%set rotation and elevation of plot view


Mh = 0.443;
T = 78;
Ni = ((Mh*k*T)/pi)^(3/2)*(1/(2^0.5))*exp(-E-ni);
%}
Warning: Integer operands are required for colon operator when used as index