Sie sind auf Seite 1von 7

Code 8.

2
%%
theta=70;
% semi-angle at half power
m=-log10(2)/log10(cosd(theta));
%Lambertian order of emission
P_LED=20;
%transmitted optical power by individual LED
nLED=60;
% number of LED array nLED*nLED
P_total=nLED*nLED*P_LED;
%Total transmitted power
Adet=1e-4;
%detector physical area of a PD
rho=0.8;
%reflection coefficient
Ts=1;
%gain of an optical filter; ignore if no filter is used
index=1.5;
%refractive index of a lens at a PD; ignore if no lens is used
FOV=70;
%FOV of a receiver
G_Con=(index^2)/(sind(FOV).^2);
%gain of an optical concentrator; ignore if no lens is used
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%
lx=5; ly=5; lz=2.15;
% room dimension in meter
[XT,YT,ZT]=meshgrid([-lx/4 lx/4],[-ly/4 ly/4],lz/2);
% position of Transmitter (LED);
Nx=lx*5; Ny=ly*5; Nz=round(lz*5);
% number of grid in each surface
dA=lz*ly/(Ny*Nz);
% calculation grid area
x=linspace(-lx/2,lx/2,Nx);
y=linspace(-ly/2,ly/2,Ny);
z=linspace(-lz/2,lz/2,Nz);
[XR,YR,ZR]=meshgrid(x,y, -lz/2);
%%
%first transmitter calculation
TP1=[XT(1,1,1) YT(1,1,1) ZT(1,1,1)];
% transmitter position
TPV=[0 0 -1];
% transmitter position vector
RPV=[0 0 1];
% receiver position vector
%%
%%%%%%%%%%%%%%%calculation for wall 1%%%%%%%%%%%%%%%%%%
WPV1=[1 0 0];
% position vector for wall 1
for ii=1:Nx
for jj=1:Ny
RP=[x(ii) y(jj) -lz/2];
% receiver position vector

h1(ii,jj)=0;
% reflection from North face
for kk=1:Ny
for ll=1:Nz
WP1=[-lx/2 y(kk) z(ll)];
D1=sqrt(dot(TP1-WP1,TP1-WP1));
cos_phi=abs(WP1(3)- TP1(3))/D1;
cos_alpha=abs(TP1(1)- WP1(1))/D1;
D2=sqrt(dot(WP1-RP,WP1-RP));
cos_beta=abs(WP1(1)-RP(1))/D2;
cos_psi=abs(WP1(3)- RP(3))/D2;
if abs(acosd(cos_psi))<=FOV
h1(ii,jj)=h1(ii,jj)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
end
end
end
end
%%
WPV2=[0 1 0];
% position vector for wall 2
for ii=1:Nx
for jj=1:Ny
RP=[x(ii) y(jj) -lz/2];
% receiver position vector
h2(ii,jj)=0;
for kk=1:Nx
for ll=1:Nz
WP2=[x(kk) -ly/2 z(ll)];
D1=sqrt(dot(TP1-WP2,TP1-WP2));
cos_phi=abs(WP2(3)-TP1(3))/D1;
cos_alpha=abs(TP1(2)-WP2(2))/D1;
D2=sqrt(dot(WP2-RP,WP2-RP));
cos_beta=abs(WP2(2)-RP(2))/D2;
cos_psi=abs(WP2(3)-RP(3))/D2;
if abs(acosd(cos_psi))<=FOV
h2(ii,jj)=h2(ii,jj)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
end
end
end
end
WPV3=[-1 0 0];
for ii=1:Nx
for jj=1:Ny
RP=[x(ii) y(jj) -lz/2];
% receiver position vector
h3(ii,jj)=0;
for kk=1:Ny
for ll=1:Nz
WP3=[lx/2 y(kk) z(ll)];
D1=sqrt(dot(TP1-WP3,TP1-WP3));

cos_phi=abs(WP3(3)-TP1(3))/D1;
cos_alpha=abs(TP1(1)-WP3(1))/D1;
D2=sqrt(dot(WP3-RP,WP3-RP));
cos_beta=abs(WP3(1)-RP(1))/D2;
cos_psi=abs(WP3(3)-RP(3))/D2;
if abs(acosd(cos_psi))<=FOV
h3(ii,jj)=h3(ii,jj)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
end
end
end
end
WPV4=[0 -1 0];
for ii=1:Nx
for jj=1:Ny
RP=[x(ii) y(jj) -lz/2];
% receiver position vector
h4(ii,jj)=0;
for kk=1:Nx
for ll=1:Nz
WP4=[x(kk) ly/2 z(ll)];
D1=sqrt(dot(TP1-WP4,TP1-WP4));
cos_phi=abs(WP4(3)-TP1(3))/D1;
cos_alpha=abs(TP1(2)-WP4(2))/D1;
D2=sqrt(dot(WP4-RP,WP4-RP));
cos_beta=abs(WP4(2)-RP(2))/D2;
cos_psi=abs(WP4(3)-RP(3))/D2;
if abs(acosd(cos_psi))<=FOV
h4(ii,jj)=h4(ii,jj)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
end
end
end
end
%% calculation of the channel gain is similar to wall1
P_rec_A1=(h1+h2+h3+h4)*P_total.*Ts.*G_Con;
% h2, h3 and h4 are channel gain for walls 2,3 and 4, respectively.
P_rec_A2=fliplr(P_rec_A1);
% received power from source 2, due to symmetry no need separate
% calculations
P_rec_A3=flipud(P_rec_A1);
P_rec_A4=fliplr(P_rec_A3);
P_rec_total_1ref=P_rec_A1+P_rec_A2+P_rec_A3+P_rec_A4;
P_rec_1ref_dBm=10*log10(P_rec_total_1ref);
%Fig.(1)
surf(x,y,P_rec_1ref_dBm);

Code8.3
%%
C=3e8*1e-9;
% time will be measured in ns in the program
theta=70;
% semi-angle at half power
m=-log10(2)/log10(cosd(theta));
% Lambertian order of emission
% P_LED=20;
% %transmitted optical power by individual LED
% nLED=60;
% number of LED array nLED*nLED
P_total=1;
% Total transmitted power
Adet=1e-4;
% detector physical area of a PD
rho=0.8;
% reflection coefficient
Ts=1;
% gain of an optical filter; ignore if no filter is used
index=1.5;
% refractive index of a lens at a PD; ignore if no lens is used
FOV=60;
% FOV of a receiver
G_Con=(index^2)/(sind(FOV).^2);
% gain of an optical concentrator; ignore if no lens is used
%%
%%%%%%
lx=5; ly=5; lz=3-0.85;
% room dimension in metre
[XT,YT,ZT]=meshgrid([-lx/4 lx/4],[-ly/4 ly/4],lz/2);
% position of Transmitter (LED);
Nx=lx*3; Ny=ly*3; Nz=round(lz*3);
% number of grid in each surface
dA=lz*ly/(Ny*Nz);
% calculation grid area
x=-lx/2:lx/Nx:lx/2;
y=-ly/2:ly/Ny:ly/2;
z=-lz/2:lz/Nz:lz/2;
%%
% first transmitter calculation
TP1=[0 0 lz/2];
% transmitter position
TPV=[0 0 -1];
% transmitter position vector
RPV=[0 0 1];
% receiver position vector
%%
WPV1=[1 0 0];
WPV2=[0 1 0];
WPV3=[-1 0 0];
WPV4=[0 -1 0];

% wall vectors
delta_t=1/2;
% time resolution in ns, use in the form of 1/2m
for ii=1:Nx+1
for jj=1:Ny+1
RP=[x(ii) y(jj) -lz/2];
t_vector=0:25/delta_t; % time vector in ns
h_vector=zeros(1,length(t_vector));
% receiver position vector
% LOS channel gain
D1=sqrt(dot(TP1-RP,TP1-RP));
cosphi=lz/D1;
tau0=D1/C;
index=find(round(tau0/delta_t)==t_vector);
if abs(acosd(cosphi))<=FOV
h_vector(index)=h_vector(index)+(m+1)*Adet.*cosphi.^(m+1)./(2*pi.*D1.^2);
end
%% reflection from first wall
count=1;
for kk=1:Ny+1
for ll=1:Nz+1
WP1=[-lx/2 y(kk) z(ll)];
D1=sqrt(dot(TP1-WP1,TP1-WP1));
cos_phi=abs(WP1(3)-TP1(3))/D1;
cos_alpha=abs(TP1(1)-WP1(1))/D1;
D2=sqrt(dot(WP1-RP,WP1-RP));
cos_beta=abs(WP1(1)-RP(1))/D2;
cos_psi=abs(WP1(3)-RP(3))/D2;
tau1=(D1+D2)/C;
index=find(round(tau1/delta_t)==t_vector);
if abs(acosd(cos_psi))<=FOV
h_vector(index)=h_vector(index)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
count=count+1;
end
end
%% Reflection from second wall
count=1;
for kk=1:Nx+1
for ll=1:Nz+1
WP2=[x(kk) -ly/2 z(ll)];
D1=sqrt(dot(TP1-WP2,TP1-WP2));
cos_phi=abs(WP2(3)-TP1(3))/D1;
cos_alpha=abs(TP1(2)-WP2(2))/D1;
D2=sqrt(dot(WP2-RP,WP2-RP));
cos_beta=abs(WP2(2)-RP(2))/D2;
cos_psi=abs(WP2(3)-RP(3))/D2;
tau2=(D1+D2)/C;
index=find(round(tau2/delta_t)==t_vector);
if abs(acosd(cos_psi))<=FOV
h_vector(index)=h_vector(index)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
count=count+1;

end
end
%% Reflection from third wall
count=1;
for kk=1:Ny+1
for ll=1:Nz+1
WP3=[lx/2 y(kk) z(ll)];
D1=sqrt(dot(TP1-WP3,TP1-WP3));
cos_phi=abs(WP3(3)-TP1(3))/D1;
cos_alpha=abs(TP1(1)-WP3(1))/D1;
D2=sqrt(dot(WP3-RP,WP3-RP));
cos_beta=abs(WP3(1)-RP(1))/D2;
cos_psi=abs(WP3(3)-RP(3))/D2;
tau3=(D1+D2)/C;
index=find(round(tau3/delta_t)==t_vector);
if abs(acosd(cos_psi))<=FOV
h_vector(index)=h_vector(index)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
count=count+1;
end
end
%% Reflection from fourth wall
count=1;
for kk=1:Nx+1
for ll=1:Nz+1
WP4=[x(kk) ly/2 z(ll)];
D1=sqrt(dot(TP1-WP4,TP1-WP4));
cos_phi=abs(WP4(3)-TP1(3))/D1;
cos_alpha=abs(TP1(2)-WP4(2))/D1;
D2=sqrt(dot(WP4-RP,WP4-RP));
cos_beta=abs(WP4(2)-RP(2))/D2;
cos_psi=abs(WP4(3)-RP(3))/D2;
tau4=(D1+D2)/C;
index=find(round(tau4/delta_t)==t_vector);
if abs(acosd(cos_psi))<=FOV
h_vector(index)=h_vector(index)+
(m+1)*Adet*rho*dA*G_Con*cos_phi^m*cos_alpha*cos_beta*cos_psi/
(2*pi^2*D1^2*D2^2);
end
count=count+1
end
end
t_vector=t_vector*delta_t;
mean_delay(ii,jj)=sum((h_vector).^2.*t_vector)/sum(h_vector.^2);
Drms(ii,jj)=sqrt(sum((t_vectormean_delay(ii,jj)).^2.*h_vector.^2)/sum(h_vector.^2));
end
end
surf(x,y, Drms);
% surf(x,y,mean_delay);
% plot(t_vector*delta_t, h_vector)
save Drms_1LED mean_delay Drms x y z theta m P_total rho FOV
TP1;
axis([-lx/2 lx/2 -ly/2 ly/2 min(min(Drms)) max(max(Drms))]);

Das könnte Ihnen auch gefallen