clear all;
close all;
clc;
[length,width] = meshgrid(0.5:0.05:5);
%length=5;
%width=5;
height=3;%墙面高度
Aroom=length.*width;%室内面积
Arx=50;%the receiveing area
d=3;
psi=30;%入射角
psic=70;%半功率角
phi_half=pi/3;
Tf=1%transmission coefficient
g=6;%the concentrator gain 光集中器增益
Ba=4.5E6; %amplifier bandwidth
amplifier_current = 0.01;%放大器电流
Pn=3.3*5.84E-3; %the noise power of the ambient light背景光噪声功率
q=1.602176487E-19;
R=0.4; %photodiode responsivity光电二极管的折射率
nLED=4;%LED数量
pLED=0.02;%单个LED功率
Rf = 0.15; %地面反射
Rc = 0.8; %天花板反射
Rw = 0.9; %墙面反射
Af=Aroom;%地面面积
Ac=Aroom;%天花板面积
Aw=length*d;%墙面面积
m=-log(2)./log(cos(phi_half));%the order of Lambertian emission
Ro=real(((m+1)./(2*pi))*cos(phi_half*2)^m);%Lambertian radiant intensity
%hlos = HLOS(Arx,d,psi,psic,Ro);
%Hlos = ones(1,length(Ro));
if ((psi >= 0) && (psic >= psi))
Hlos = Arx/(d^2)*Ro*cos(psi);
elseif (psi>psic)
Hlos = Hlos*0;
end;
Ptx=pLED*Ro;
Prxlos=Ptx.*Hlos*nLED;
I2=0.562; %the noise-bandwidth factor
Rb=5120000; %date rate
Bn=I2*Rb; %the nosie-bandwidth
rhof=Rf.*Af;%
rhoc=Rc.*Ac;
rhow=Rw.*Aw;
rho = (1./Aroom) .* (rhof + rhoc + rhow);%the average reflectivity
%功率
PtotalLED=nLED*pLED;%the total power of all the LEDs
Ii = rho .* (PtotalLED./Aroom);%i级反射强度
I = Ii./(1-rho);%the total intensity
Pdiff=Arx.*I;%the received diffuse power
%Pdiffloss=Pdiff/PtotalLED;
Prx=(Prxlos+Pdiff)*Tf*g;
%PDoutput_current=Prx*R;
%%噪声
%Ba=4.5E6; %amplifier bandwidth
%amplifier_current = 0.01;%放大器电流
%Pn=3.3*5.84E-3; %the noise power of the ambient light
%q=1.602176487E-19;
%R=0.4; %photodiode responsivity
sigmaamp=amplifier_current^2*Ba; %the amplifier noise variance
sigmaamb=2*q*R*(Prx+Pn)*I2*Rb;%the ambient noise
sigmatotal=sigmaamp+sigmaamb;
%%SNR
SNR=(R*Prx)^2./sigmatotal;%
SNRdb = 10*log10(SNR);
%length=0.5:0.05:5;
%[length,width] = meshgrid(length);
figure
mesh(length,width,SNRdb);
xlabel('Roomlength');ylabel('Roomwidth');zlabel('SNRdb');
%%误码率
Q = (1/2)*erfc((sigmatotal./(R*Prx.^2)./sqrt(2)));
BER=Q*sqrt(SNR);
figure
mesh(length,width,BER);
xlabel('Roomlength');ylabel('Roomwidth');zlabel('BER');