Electric
Electric
clear
tic;
%Step 1
Rs=0.5159985;
%Step 2
filename = 'outdata2.xlsx';
[VI,name,raw] = xlsread(filename,1);
[elpar,ename,eraw] = xlsread(filename,2);
[RFt,fname,fraw] = xlsread(filename,3);
IF=0.01:0.1:1;
UT = 0.0296;
Tref = 70;
TJ = VI(2:size(VI),1);
%TJ=[30 50 70 85 110]';
m=2.2668532;
Io=6.59762*10^-19;
Vf=IF.*Rs+m*UT.*(log(IF./Io)+1); %Eq.(E1)
y=0.0681*log(IF)+2.8612; % Line fitting based on R^2
Abs=Vf-y;
RE=Abs./y;
z=plot(IF,Vf,'+');
%x = logspace(1,2,3);
figure (1)
semilogx(IF,Vf,'--x','MarkerFaceColor','b','Markersize', 20)
hold on
semilogx(IF,y,'--','MarkerFaceColor','r','Markersize', 20)
hold off
grid on
grid minor
legend('Measured forward characteristics of a power LED (+ markers)','Logarithmic
equation of best fit')
figure (2)
plot(IF,Vf,'--x','MarkerFaceColor','b','Markersize', 20)
hold on
plot(IF,y,'--','MarkerFaceColor','r','Markersize', 20)
grid on
grid minor
legend('Measured forward characteristics of a power LED (+ markers)','Logarithmic
equation of best fit')
xlabel('If[A]')
ylabel('Vf[V]')
title('Exponential fitting of Eq.(E1)to the measured isothermal')
hold off
%Step 3
Vcal = VI(2:size(VI),2:size(VI,2));
IF = VI(1,2:9);
IF = repmat(IF,5,1);
ifzero = find(Vcal == 0);
IF(ifzero) = 0;
%IF = VI(1,2:size(VI,2));
%IF = repmat(IF,5,1);
maxit = 3000;
Npar = 9;
popsize = 1000;
mutrate = 0.2;
selection = 0.5;
Nt = Npar;
keep = floor(selection*popsize);
M = (popsize-keep)/2;
nmut = ceil((popsize-1)*Nt*mutrate);
%Calculation of the full ?f ? If characteristics by the pre-calculated IF
%dependent K-factor values with Eqs. (E2)-(E4)
m = 3*rand(popsize,1);
Rs = 0.5*rand(popsize,1);
oo = fix(popsize/6);
Io1 = 1e-14*rand(1,oo);
Io2 = 1e-16*rand(1,oo);
Io3 = 1e-18*rand(1,oo);
Io4 = 1e-20*rand(1,oo);
Io5 = 1e-22*rand(1,oo);
Io6 = 1e-24*rand(1,popsize-5*oo);
Io = cat(2,Io1,Io2,Io3,Io4,Io5,Io6)';
S= 4;
ael = -S*1e-5+2*S*1e-5*rand(popsize,1);
bel = -S*1e-5+2*S*1e-5*rand(popsize,1);
cel = -S*1e-6+2*S*1e-6*rand(popsize,1);
del = -S*1e-3+2*S*1e-3*rand(popsize,1);
eel = -S*1e-3+2*S*1e-3*rand(popsize,1);
fel = -S*1e-3+2*S*1e-3*rand(popsize,1);
par = [m Rs Io ael bel cel del eel fel];
for j = 1:popsize
dVV = (par(j,4)*(TJ.^2-Tref^2)+par(j,7)*(TJ-Tref)).*IF.^2 + ...
(par(j,5)*(TJ.^2-Tref^2)+par(j,8)*(TJ-Tref)).*IF+...
(par(j,6)*(TJ.^2-Tref^2)+par(j,9)*(TJ-Tref));
%Eq 3
VFn = par(j,1)*UT*log(IF./par(j,3)+1)+IF*par(j,2)+dVV;
%Eq 2
for k = 1:5
for i =1:8
if Vcal(k,i) == 0
e1(k,i) = 0;
else
e1(k,i) = abs(VFn(k,i)-Vcal(k,i))./Vcal(k,i);
end
end
end
erro(j) = max(max(e1));
end
ind = 1:popsize;
errmat = [ind' erro'];
[er,idx] = sort(errmat(:,size(errmat,2)));
par = par(idx,:);
iga = 0;
Coords{iga+1}=par;
while iga<maxit
iga=iga+1;
prob=flipud([1:keep]'/sum([1:keep]));
odds=[0 cumsum(prob(1:keep))'];
pick1=rand(1,M);
pick2=rand(1,M);
ic=1;
while ic<=M
for id=2:keep+1
if pick1(ic)<=odds(id) && pick1(ic)>odds(id-1)
ma(ic)=id-1;
end
if pick2(ic)<=odds(id) && pick2(ic)>odds(id-1)
pa(ic)=id-1;
end
end
ic=ic+1;
end
ix=1:2:keep;
xp=ceil(rand(1,M)*Nt);
r=rand(1,M);
%
for ic=1:M
xy=par(ma(ic),xp(ic))-par(pa(ic),xp(ic));
par(keep+ix(ic),:)=par(ma(ic),:); % 1st offspring
par(keep+ix(ic)+1,:)=par(pa(ic),:); % 2nd offspring
par(keep+ix(ic),xp(ic))=par(ma(ic),xp(ic))-r(ic).*xy; % 1st
par(keep+ix(ic)+1,xp(ic))=par(pa(ic),xp(ic))+r(ic).*xy; % 2nd
if xp(ic)<Npar
par(keep+ix(ic),:)=[par(keep+ix(ic),1:xp(ic))...
par(keep+ix(ic)+1,xp(ic)+1:Npar)];
par(keep+ix(ic)+1,:)=[par(keep+ix(ic)+1,1:xp(ic)) ...
par(keep+ix(ic),xp(ic)+1:Npar)];
end
end
mrow=sort(ceil(rand(1,nmut)*(popsize-1))+1);
% mcol=ceil(rand(1,nmut)*Nt);
m = 3*rand(nmut,1);
Rs = 0.5*rand(nmut,1);
oo = fix(nmut/6);
Io1 = 1e-14*rand(1,oo);
Io2 = 1e-16*rand(1,oo);
Io3 = 1e-18*rand(1,oo);
Io4 = 1e-20*rand(1,oo);
Io5 = 1e-22*rand(1,oo);
Io6 = 1e-24*rand(1,nmut-5*oo);
Io = cat(2,Io1,Io2,Io3,Io4,Io5,Io6)';
ael = -S*1e-5+2*S*1e-5*rand(nmut,1);
bel = -S*1e-5+2*S*1e-5*rand(nmut,1);
cel = -S*1e-6+2*S*1e-6*rand(nmut,1);
del = -S*1e-3+2*S*1e-3*rand(nmut,1);
eel = -S*1e-3+2*S*1e-3*rand(nmut,1);
fel = -S*1e-3+2*S*1e-3*rand(nmut,1);
% Io = logspace(-24,-15,nmut)';
% m= linspace(1,4,nmut)';
% Rs = linspace(0.1,1,nmut)';
% ael = logspace(-5,-3,nmut)';
% bel = logspace(-5,-3,nmut)';
% cel = logspace(-6,-4,nmut)';
% del = logspace(-4,-2,nmut)';
% eel = logspace(-4,-2,nmut)';
% fel = logspace(-4,-2,nmut)';
m= linspace(1,4,nmut)';
Rs = linspace(0.1,0.9,nmut)';
Io = logspace(-24,-15,nmut)';
ael = cat(1,-logspace(-5,-3,floor(nmut/2))',logspace(-5,-3,nmut-floor(nmut/2))');
bel = cat(1,-logspace(-5,-3,floor(nmut/2))',logspace(-5,-3,nmut-floor(nmut/2))');
cel = cat(1,-logspace(-6,-4,floor(nmut/2))',logspace(-6,-4,nmut-floor(nmut/2))');
del = cat(1,-logspace(-4,-2,floor(nmut/2))',logspace(-4,-2,nmut-floor(nmut/2))');
eel = cat(1,-logspace(-4,-2,floor(nmut/2))',logspace(-4,-2,nmut-floor(nmut/2))');
fel = cat(1,-logspace(-4,-2,floor(nmut/2))',logspace(-4,-2,nmut-floor(nmut/2))');
%
for ii=1:nmut
par(mrow(ii),:)=[m(ii) Rs(ii) Io(ii) ael(ii) bel(ii) cel(ii) del(ii)
eel(ii) fel(ii)];
end
% m = ep(1)*ones(nmut,1);
% Rs = ep(2)*ones(nmut,1);
% Io = ep(3)*ones(nmut,1);
%
for j = 1:popsize
dVV = (par(j,4)*(TJ.^2-Tref^2)+par(j,7)*(TJ-Tref)).*IF.^2 + ...
(par(j,5)*(TJ.^2-Tref^2)+par(j,8)*(TJ-Tref)).*IF+...
(par(j,6)*(TJ.^2-Tref^2)+par(j,9)*(TJ-Tref));
VFn = par(j,1)*UT*log(IF./par(j,3)+1)+IF*par(j,2)+dVV;
for k = 1:5
for i =1:8
if Vcal(k,i) == 0
e1(k,i) = 0;
else
e1(k,i) = abs(VFn(k,i)-Vcal(k,i))./Vcal(k,i);
end
end
end
erro(j) = max(max(e1));
end
ind = 1:popsize;
errmat = [ind' erro'];
% errmat1 = [ind' err1];
[er,idx] = sort(errmat(:,size(errmat,2)));
par = par(idx,:);
Coords{iga+1}=par;
x(iga,:) = [iga er(1)];
end
figure (3)
subplot(1,3,1)
plot(x(:,1), x(:,2)); grid
grid minor
subplot(1,3,2)
plot(RE)
grid minor
subplot(1,3,3)
plot(x(:,1), x(:,2)); grid
hold on
plot(RE)
hold on
plot(er(1),'x','MarkerFaceColor','g','Markersize',60)
sgtitle('Max relative error:(Measured Vs. Expected)&(Measured Vs. Genetic
Algorithm) ','FontSize', 10)
grid minor
%legend('Error at cross-over stage', 'Relative error=max=0.1697','Mutation
stage:Final Error=0.0043');
hold off
err = er(1)
m = par(1,1);
Rs = par(1,2);
Io = par(1,3);
ael = par(1,4);
bel = par(1,5);
cel = par(1,6);
del = par(1,7);
eel = par(1,8);
fel = par(1,9);
elapsedTime = toc;
figure (4)
TJ = TJ;
IF = IF;
dVV = (par(1,4)*(TJ.^2-Tref^2)+par(1,7)*(TJ-Tref)).*IF.^2 + ...
(par(1,5)*(TJ.^2-Tref^2)+par(1,8)*(TJ-Tref)).*IF+...
(par(1,6)*(TJ.^2-Tref^2)+par(1,9)*(TJ-Tref));
VFnn = par(1,1)*UT*log(IF./par(1,3)+1)+IF*par(1,2)+dVV;
mycolor = [0 0 1; 0.5 0.1 0; 0 1 0; 0.3 0.4 0.6; 0 0 1];
mymarker = ['+','+','+','+','+'];
hold on
for i=1:length(TJ)
l = 1; IFn =0; Vcaln = 0; Vsimn=0;
for j = 1:size(IF,2)
if IF(i,j) ~= 0
IFn(l) = IF(i,j);
Vcaln(l) = Vcal(i,j);
Vsimn(l) = VFnn(i,j);
l = l+1;
end
end
plot(IFn,Vcaln,'color',mycolor(i,:),'linewidth',1.5);
plot(IFn,Vsimn,'color',mycolor(i,:),'LineStyle','none',
'Marker',mymarker(i),'MarkerSize',6, 'linewidth',1.5);
end
hold off
grid on
legend('Meas 30C^{O}', 'Sim 30C^{O}', 'Meas 50C^{O}', 'Sim 50C^{O}',...
'Meas 70C^{O}', 'Sim 70C^{O}','Meas 85C^{O}', 'Sim 85C^{O}',...
'Meas 110C^{O}', 'Sim 110C^{O}');
xlabel('IF[mA]')
ylabel('V[V]')
title('IV_ Curve' )
elcpar ={'m' 'R' 'Io' 'a_el' 'b_el' 'c_el' 'd_el' 'e_el' 'f_el';...
m Rs Io ael bel cel del eel fel};
arr1 = zeros(6,9);
arr1(2:6,1) = TJ';
arr1(1,2:9) = IF(1,:);
arr1(2:6, 2:9) = VFnn(:,:);
arr1(2:6, 2:9) = VFnn(:,:);
filename1=strcat('out',filename);
xlswrite(filename1,arr1,'electric');
xlswrite(filename1,arr1,'VFnn');
xlswrite(filename1,elcpar,'electrical parameters');
xlswrite(filename1,er(1),'MRE');
xlswrite(filename1,erro,'error');
xlswrite(filename1,elapsedTime,'tic');
%Optical part
a=Vcal;
b=VFn;
c=dVV;
d=IF.*Rs;
Vfrad=a-b-c-d