How to do optimization coding for minimize peak width ?
显示 更早的评论
i need a optimization code for minimize the "peak_width" (width at half maximum) by the optimized "del" (thickness variation parameter) that varying between -1 and 1 at specific frequency and i need unit transmission(maximum transmission) also (red solid line)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is a program for 1-D Photonic crystal
% For Photonic band structure calculation and Transmission Spectrum
% This program uses Transfer Matrix Method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define material properties and simulation parameters
P = 0; %%% Hydrostatic pressure in MPa
n0 = 1; % Refractive index of air
ns = 1.46; % Refractive index of subtrate
n01 = 1.578; % Refractive index of PS
n02 = 1.484; % Refractive index of PMMA
% Calculate Epsilon for n01, n02
e01 = n01^2;
e02 = n02^2;
% Constants
p11_1 = 0.32;
p12_1 = 0.31;
p11_2 = 0.3;
p12_2 = 0.297;
v1 = 0.35;
E1 = 3.3e3; % Convert to scientific notation (3.3 x 10^3)
v2 = 0.37;
E2 = 3.0303e3; % Convert to scientific notation (3.0303 x 10^3)
% Formula for calculating nA
e1 = e01 - ((e01^2)/2) * (((p11_1/E1) * (v1+1) * P) + ((p12_1/E1) * (3*v1+1) * P));
nA = sqrt(e1);
% Formula for calculating nA
e2 = e02 - ((e02^2)/2) * (((p11_2/E2) * (v2+1) * P) + ((p12_2/E2) * (3*v2+1) * P));
nB = sqrt(e2);
del=0.131; %%% Thickness variation parameter
% Initialization of parameters
dair=1200e-9; % Thickness of air in meters
dA=780e-9; % Thickness of First Layer in meters
dB=830e-9; % Thickness of Second Layer in meters
ddA=(1+del)*dA; % Thickness of First Layer with thickness variation in meters
ddB=(1+del)*dB; % Thickness of Second Layer with thickness variation in meters
c=3e8; % Velocity of Light (m/s)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Frequency Range
% f=linspace(58,67,16001); % Frequncy in THz
f=58:0.001:67; % Frequncy in THz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for loop=1:length(f)
%%% angular frequency
w=2*pi*f*1e12;
a=dA+dB; %%% Lattice Constant
DA=((w(loop))/c)*dA*nA; %%% wave number of first layer
DB=((w(loop))/c)*dB*nB; %%% wave number of second layer
Da=((w(loop))/c)*(dA*0.5)*nA; %%% wave number of first half layer
Db=((w(loop))/c)*(dB*0.5)*nB; %%% wave number of second half layer
DDA=((w(loop))/c)*ddA*nA; %%% wave number of first layer with thickness variation
DDB=((w(loop))/c)*ddB*nB; %%% wave number of second layer with thickness variation
DDa=((w(loop))/c)*(ddA*0.5)*nA; %%% wave number of first half layer with thickness variation
DDb=((w(loop))/c)*(ddB*0.5)*nB; %%% wave number of second half layer with thickness variation
Dair=((w(loop))/c)*(dair*0.5)*n0; %%% wave number of air layer
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transfer Matrix elements of air
a11=cos(Dair); a12=-1i*sin(Dair)/n0; a21=-1i*n0*sin(Dair); a22=cos(Dair);
AA=[a11 a12; a21 a22];
%%% Transfer Matrix elements of first layer
m11=cos(DA); m12=-1i*sin(DA)/nA; m21=-1i*nA*sin(DA); m22=cos(DA);
mA=[m11 m12; m21 m22];
%%% Transfer MAtrix elements of Second layer
l11=cos(DB); l12=-1i*sin(DB)/nB; l21=-1i*nB*sin(DB); l22=cos(DB);
mB=[l11 l12; l21 l22];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transfer Matrix elements of first half layer
ma11=cos(Da); ma12=-1i*sin(Da)/nA; ma21=-1i*nA*sin(Da); ma22=cos(Da);
ma=[ma11 ma12; ma21 ma22];
%%% Transfer MAtrix elements of Second half layer
lb11=cos(Db); lb12=-1i*sin(Db)/nB; lb21=-1i*nB*sin(Db); lb22=cos(Db);
mb=[lb11 lb12; lb21 lb22];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transfer Matrix elements of first layer with thickness variation
dm11=cos(DDA); dm12=-1i*sin(DDA)/nA; dm21=-1i*nA*sin(DDA); dm22=cos(DDA);
mA1=[dm11 dm12; dm21 dm22];
%%% Transfer MAtrix elements of Second layer with thickness variation
dl11=cos(DDB); dl12=-1i*sin(DDB)/nB; dl21=-1i*nB*sin(DDB); dl22=cos(DDB);
mB2=[dl11 dl12; dl21 dl22];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Transfer Matrix elements of first half layer with thickness variation
dma11=cos(DDa); dma12=-1i*sin(DDa)/nA; dma21=-1i*nA*sin(DDa); dma22=cos(DDa);
ma1=[dma11 dma12; dma21 dma22];
%%% Transfer MAtrix elements of Second half layer with thickness variation
dlb11=cos(DDb); dlb12=-1i*sin(DDb)/nB; dlb21=-1i*nB*sin(DDb); dlb22=cos(DDb);
mb2=[dlb11 dlb12; dlb21 dlb22];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Unit cell
m=(mA*mB);
M0=(m^25); %%% A-B structure
M1=(mb*mA*mb)^25; %%% B/2-A-B/2 structure
M2=(ma*mB*ma)^25; %%% A/2-B-A/2 structure
M3=(mb2*mA1*mb2)^25; %%% B/2-A-B/2 structure with thickness variation
M4=(ma1*mB2*ma1)^25; %%% A/2-B-A/2 structure with thickness variation
M = M1*M2;
% M = M2*M1;
% M = M0*AA*M0; %%% defect structure (air)
Mm = M1*M2*M3;
% M = M2*M1*M4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Reflection and Transmission
% R1(loop)=((ns*M(1,1)+ns*n0*M(1,2)-M(2,1)-n0*M(2,2))/(ns*M(1,1)+ns*n0*M(1,2)+M(2,1)+n0*M(2,2)));
% R(loop)=(R1(loop))*conj(R1(loop));
T1(loop)=(2*ns/(ns*M(1,1)+ns*n0*M(1,2)+M(2,1)+n0*M(2,2)));
T(loop)=(n0 / ns) * abs(T1(loop))^2;
Tt1(loop)=(2*ns/(ns*Mm(1,1)+ns*n0*Mm(1,2)+Mm(2,1)+n0*Mm(2,2)));
Tt(loop)=(n0 / ns) * abs(Tt1(loop))^2;
end
desired_freq = 60.895; % Change this to your desired peak frequency (THz)
peak_idx = find(f == desired_freq);
peak_val = Tt(peak_idx);
half_max = peak_val / 2;
peak_left_edge = find(Tt(1:peak_idx) < half_max, 1, 'last');
peak_right_edge = find(Tt(peak_idx:end) < half_max, 1, 'first') + peak_idx - 1;
peak_width = f(peak_right_edge) - f(peak_left_edge); %%% full width at half maximum
disp("peak width=")
disp(peak_width)
figure(1)
plot(f,T(:),'k') %%% Topological structure
hold on
plot(0.018+f,Tt(:),'r') %%% Topological coupled structure
hold off
xlim([60.5,61.5])
% xlim([58,67])
ylim([0,1])
xlabel("Frequency (THz)")
ylabel("Transmission")
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


