Simple Code for VLC (Visible Light Communications)

how can i write simple code for SNR distribution for indoor VLC

2 comentarios

Which meaning of VLC is intended for this question?
Désiré_RM
Désiré_RM el 26 de Feb. de 2024
Hello everybody. Hope all of you're doing well? I'm working on VLC combinate with NOMA. Can you help me with Matlab code for to estimate the indoor coverage with VLC and allocate ressources with NOMA?

Iniciar sesión para comentar.

 Respuesta aceptada

pratik panchal
pratik panchal el 10 de Mayo de 2017
Editada: Walter Roberson el 10 de Mayo de 2017
I hope it is useful for you.
clear all;
clc;
close all;
% SNR Performance For VLC SYSTEM %
% Coded BY Er. PANCHAL PRATIK
% pattu310@gmail.com
% Easy USe Consider Following Example
%
%
% BASIC PARAMETER REQUIRED %
Incidence = 70*pi/180;
TX_FOV = 70; % Transmitter Field Of View
RX_FOV = 90; % Receivers Field Of View
Tx = [2,2,2]; % Transmitter Location
%Rxp = [2,2]; % Receiver Location
W_Room = 4; % Width of Room
L_Room = 4; % Length of Room
H_Room = 2; % Height Between Transmitter and Receiver
R = 1; % Responsivity of Photodiode
Apd = 1e-4; % Area of PhotoDetector
Rb = 1e6; % Data rate of system
Iamp = 5e-12; % Amplifier Current
q = 1.6e-19; % Electron Charge
Bn = 50e6; % Noise Bandwidth
I2 = 0.562; % Noise Bandwidth Factor
PLED = 1; % Power Emitted by LED
index =1;
HLED = 1;
[W L] = meshgrid(-(W_Room/2) : 0.50 : (W_Room/2)); % Consideer Length of BLock for Room
xydist = sqrt((W).^2 + (L).^2);
hdist = sqrt(xydist.^2 + HLED.^2);
%D = Tx - Rx;
%d = norm(D);
%Incidence = acos()
A_Irradiance = ((Tx(3)-HLED)./hdist);
%I(index) = Irradiance*180/pi;
%if abs(Incidence <= RX_FOV)
p = TX_FOV ;
Tx_FOV = (TX_FOV*pi)/180;
% BASIC CALCULATION IN VLC SYSTEM %
% Lambertian Pattern
m = real(-log(2)/log(cos(Tx_FOV)));
% Radiation Intensity at particular point
Ro = real(((m+1)/(2*pi)).*A_Irradiance^m);
% Transmitted power By LED
Ptx = PLED .* Ro;
% Channel Gain ( Channel Coefficient Of LOS Channel )
%Theta=atand(sqrt(sum((Tx-Rx).^2))/H_Room);
HLOS = (Apd./hdist.^2).*cos(Incidence).*Ro;
% Received Power By PhotoDetector
Prx = HLOS.*Ptx;
% Calculate Noise in System
Bs = Rb*I2;
Pn = Iamp/Rb;
Ptotal = Prx+Pn;
new_shot = 2*q*Ptotal*Bs;
new_amp = Iamp^2*Bn;
% Calculate SNR
new_total = new_shot + new_amp;
SNRl = (R.*Prx).^2./ new_total;
SNRdb = 10*log10(SNRl);
% else
% SNRl = 0;
% SNRdb = 0;
% end
index = index + 1;
% Plot Graph %
figure;
mesh(W,L,SNRdb);
%mesh(SNRdb);
%ylim([0 30]);
title('SNR Distribution in Room');
xlabel('Length of Room');
ylabel('Width of Room');
zlabel('SNR in dB');

17 comentarios

Muso
Muso el 7 de Nov. de 2017
Thanks you so much, it was helpful
thank u
if this helpful for you upvote my answer
Rashi Gautam
Rashi Gautam el 14 de Oct. de 2020
Editada: Rashi Gautam el 14 de Oct. de 2020
Can you please help me with code for outdoor VLC as in for vehicle to vehicle will be more helpful but at this point anything related to VLC outdoor or if any minor changes in this code
Hello Dear, I truly need your help on a Machine Learning-based Hybrid VLC/RF networks implementation code, which I need to resolve by these months.
Sincerely,
Shimelis.
he fact that I do not have it but I hope to learn it if you get it please send it to me
alzubydea@gmail.com
and if I got it I will send it to you
Hi guys thank you for your responce. But i left this Application now. So cant give you update more.
sarah ayashm
sarah ayashm el 12 de Abr. de 2021
sorrry, but what's the HLED?
Good question @sarah ayashm . It is not at all obvious to me what any of the h* variables refer to.
HLED is height of LED.
%% clear environment
clc; clear all; close all;
%% parameters setting
Psi = 70; % LED half-power semiangle [degree]
rho = 0.95; % Reflection coefficient
A_pd = 1e-04; % Physical area of the PD [m^2] % [C2022]
T_of = 1; % Optical Filter Gain
a = 1.5; % Refractive index
Phi_FoV = 70; % Field of view [degree]
B = 20e3; % System bandwidth [Hz]
R_pd = 0.53; % Responsivity [A][m^2] / [W] -> %R_pd = 0.53; %(Sensitivity) [A/W]
q = 3; % Conversion ration of optical-to-electrical power
N = 10e-21; % Power spectral density [A^2/Hz]
%p = 5; % transmission power [Watt] % [SAA+2022]%[SCA+2022]
p = 8.78; % transmission power 6000 [Lumens] -> [Watt] ???????????????????????
% noise parameter
q_0 = 1.602e-19; % electronic charge [Coulombs]
I_bg = 84e-6; % background light current [A] -> 84 [µA]
k_B = 1.38064852e-23; % Boltzmann constant [Joule/Kelvin]
T_k = 295; % absolute temperature [K]
G_0 = 10; % open-loop voltage gain
eta = 1.12e-6; % fixed capacitance of photo detector per unit area [F/m^2]
Gamma = 1.5; % FET channel noise factor
g_m = 0.030; % FET transconductance [Siemens] [mS]
I_2 = 0.562; % noise BW factor
I_3 = 0.0868; % noise BW factor
% room size
x_max = 4; % room size x-axis % [SCA+2022]
y_max = 4; % room size y-axis % [SCA+2022]
z_max = 3; % room size z-axis % 3 in [SCA+2022]
granularity = 0.1; % plot accuracy
number_of_samples = 150;
% plot info
PLOT3D_enabled = 0;
PLOT2D_enabled = 1;
single_entity_d_estimation = 0;
Entity_enabled = [1 0 0 0 0]; % LED - RIS - RIS2 - RIS3 - RIS4
estimate_position_section = 1;
number_of_plot_needed = 18;
% tilt info
alpha = 0;
beta = 0;
%% set entities position
LED = [x_max/2 , y_max/2 , z_max ];
RIS1 = [x_max/2 , 0 , z_max/2+0.3*z_max];
RIS2 = [0 , y_max/2 , z_max/2+0.3*z_max];
RIS3 = [x_max , y_max/2 , z_max/2+0.3*z_max];
RIS4 = [x_max/2 , y_max , z_max/2+0.3*z_max];
%% Estimate light power
matrix_size = [length(0:granularity:x_max), length(0:granularity:y_max), length(0:granularity:z_max)];
distance_error_check = struct();
distance_error_check.LED = struct();
distance_error_check.RIS1 = struct();
impulseMatrix = zeros(matrix_size);
overlap_info = zeros(matrix_size);
%dataRateMatrix = zeros(matrix_size);
x_probe = 0:granularity:x_max;
y_probe = 0:granularity:y_max;
z_probe = 0:granularity:z_max;
x_len = length(x_probe);
y_len = length(y_probe);
z_len = length(z_probe);
tic;
%PDect = struct();
%data rate (scelto da me)
R_b1 = 35560; %espresso in bit/s
R_b2 = 266600;
%esprimo in questo modo queste matrici, perchè "NaN" è un valore speciale utilizzato per rappresentare dati mancanti o non validi in Matlab.
%Queste matrici possono poi essere utilizzate per memorizzare e manipolare i dati in un contesto specifico all'interno dello script.
%receivedPowerMatrix = nan(x_len, y_len, z_len);
%noiseMatrix = nan(x_len, y_len, z_len);
SNR1 = nan(x_len, y_len, z_len);
SNR2 = nan(x_len, y_len, z_len);
lowerBoundDataRateMatrix = nan(x_len, y_len, z_len);
for x_index = 1:x_len
for y_index = 1:y_len
for z_index = 1:z_len
PDect = [x_probe(x_index), y_probe(y_index), z_probe(z_index)];
% se attivato rallenta di molto il processo di calcolo
if PLOT3D_enabled
plotCube(LED, RIS1, RIS2, RIS3, RIS4, PDect, x_max, y_max, z_max);
end
[impulseMatrix(x_index,y_index,z_index), overlap_info(x_index,y_index,z_index)] = ...
drawChannelResponse...
(Psi, LED, RIS1, RIS2, RIS3, RIS4, PDect, Phi_FoV, A_pd, T_of, rho, a, Entity_enabled, alpha, beta );
%potenza ricevuta
receivedPowerMatrix(x_index,y_index,z_index) = impulseMatrix(x_index,y_index,z_index) * (R_pd) * p;
%rumore
[n_shoot, n_thermal, var_shoot, var_thermal] = noiseEstimation(receivedPowerMatrix(x_index,y_index,z_index), q_0, R_pd, k_B, T_k, eta, I_2, I_3, Gamma, A_pd, g_m, I_bg, G_0, B);
potenza = receivedPowerMatrix(x_index,y_index,z_index)
noise = sqrt(var_shoot + var_thermal)
noiseMatrix(x_index,y_index,z_index) = sqrt(var_shoot + var_thermal); %assegnamento del valore di noise alla posizione specificata
% nuova matrice delle potenze (potenza ricevuta) = potenza (p) * R_pd * impulseMatrix //numeratore della funzione SNR
% per ogni valore contenuto nella matrice delle potenze
% calcolare il rumore
% esempio calcolo rumore:
% noiseEstimation(potenza_ricevuta, q_0, R_pd, k_B, T_k, eta,I_2, I_3, Gamma, A_pd, g_m, I_bg, G_0, B);
% ci servono i primi 2 output della funzione, cioè shoot noise
% e termhal noise e questo rappresenta N0
%
% SNR = log10(Potenza/rumore)
%
% plot SNR in 3D
% plot DataRate in 3D
lowerBoundDataRateMatrix(x_index,y_index,z_index) = lowerBoundDataRate(impulseMatrix(x_index,y_index,z_index), B, p, R_pd, q, N);
end
end
end
Unrecognized function or variable 'drawChannelResponse'.
%rapporto segnale rumore
SNR1 = (receivedPowerMatrix) ./ (R_b1 * noiseMatrix(x_index,y_index,z_index));
SNR2 = (receivedPowerMatrix) ./ (R_b2 * noiseMatrix(x_index,y_index,z_index));
%disp(SNR1);
%disp(SNR2);
toc;
%plot section
% Crea una griglia tridimensionale per gli assi x, y e z
[x, y, z] = meshgrid(x_probe, y_probe, z_probe);
% Visualizza SNR1
figure;
mesh(x, y, z, SNR1);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('SNR1');
% Visualizza SNR2
figure;
mesh(x, y, z, SNR2);
xlabel('X');
ylabel('Y');
zlabel('Z');
title('SNR2');
Hi, I have a similar problem to solve for my studio. I calculated my SNR from an online formula. But what I'm focusing on and would like some help is the 3D plot of the result of the 2 calculated SNRs (SNR1 e SNR2). In the plot section, after the run of the script, matlab gives me an error and doesn't plot the 3D graph I need. I share the whole script to better understand everything.
@pratik panchal can you help me with my problem?
or someone else? @Walter Roberson
@Alessandro Petroni we do not have your drawChannelResponse() to test with.
SNR1 = (receivedPowerMatrix) ./ (R_b1 * noiseMatrix(x_index,y_index,z_index));
SNR2 = (receivedPowerMatrix) ./ (R_b2 * noiseMatrix(x_index,y_index,z_index));
Those statements are after all three for loops, so the values of x_index, y_index, z_index will be whatever they were last set to -- x_len, y_len, z_len in this case. So you would be dividing the matrix by a scalar.
If you were to calculate
temp = receivedPowerMatrix) ./ noiseMatrix(x_index,y_index,z_index);
then you would have
SNR1 = temp ./ R_b1;
SNR2 = temp ./ R_b2;
Are you sure that is correct, that the two are linear scalings of each other?
Alessandro Petroni
Alessandro Petroni el 17 de Mayo de 2023
Editada: Alessandro Petroni el 17 de Mayo de 2023
@Walter Roberson yes, the applied formula and calculations for the SNR are correct and already checked.
the problem remains the plot of that SNR, being a 41x41x31 three-dimensional matrix. How can I model this matrix to be able to display correctly with the mesh function?
That is, in order to plot 3 independent variables and one dependent variable, you are probably getting into volume viewing techniques, unless you want to draw isosurface

Iniciar sesión para comentar.

Más respuestas (1)

Désiré_RM
Désiré_RM el 15 de Abr. de 2024
Editada: Désiré_RM el 15 de Abr. de 2024

0 votos

Hello dears. I sincerely need your help on NOMA-VLC code for power allocation and number of users considered to complete my work.
Sincerely!

Categorías

Preguntada:

el 17 de Abr. de 2017

Editada:

el 15 de Abr. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by