clc
clear;
close;
%% =============================================> Simulation Parameters <=================================================%%
n_tx = 2; % Number of Transmitters
n_rx = 1; % Number of Receivers
N = 1e4; % Total Data Bits
minSNR = 0; % SNR Lower Limit
maxSNR = 20; % SNR Maximum Limit
intval = 2; % Interval of SNR Loop
SNR = minSNR:intval:maxSNR; % SNR Loop
L = 4; % Length of the Wall
W = 4; % Width of the Room
PD_FOV = 80; % Field of View of Receiver
led_sep = 0.5; % Separation between LEDs
led_p1 = 1.75; % LED 1 Placement from the Left Wall
led_p2 = 1.75; % LED 2 Placement from the Right Wall
pd_p = 2.5; % Photo-diode placement
irr1 = 10; % Irradiance angle of LED 1
irr2 = 15; % Irradiance angle of LED 2
%% =============================================> Binary Data Generation <================================================%%
DataBits = randi([0 1],1,N);
%% =============================================> Data for 2 Transmitters <===============================================%%
s2p = reshape(DataBits,n_tx,N/n_tx);
%% =============================================> Repition Coding for 2 Tx <==============================================%%
RC = [];
for it1 = 1:length(s2p)
RC = [RC s2p(:,it1) s2p(:,it1)];
end
%% =============================================> VLC Channel for 2 Tx <==================================================%%
[HLOS,P_t] = los_channel(L,W,PD_FOV,led_sep,led_p1,led_p2,pd_p,irr1,irr2);
P_t = 1e3*P_t;
H = 1/sqrt(2)*[randn(1,n_tx)];
%% =====================================> Signal Passing Through Channel <================================ %%
chann_arr = [];
Tx = reshape(RC,n_tx,n_tx,N/n_tx);
for it3 = 1:length(Tx)
G = H * Tx(:,:,it3);
chann_arr = [chann_arr G];
end
W = H';
%% =============================================> Data Transmission <=====================================================%%
data_tx = chann_arr;
%% =============================================> Data Reception <========================================================%%
data_rx = data_tx;
%% =============================================> Noise Addition <========================================================%%
for ss = 1:length(SNR)
n = 1/sqrt(2)*[randn(n_rx,N)];
y = chann_arr + 10^(-SNR(ss)/20)*n;
%% =============================================> Zero Forcing Equalizer <================================================%%
Y = reshape(y,1,n_tx,N/n_tx);
eq_blocks = [];
for l = 1:length(Y)
eq = W*Y(:,:,l);
eq_blocks = [eq_blocks eq];
end
%% =============================================> Repition Decoding for 2 Tx <============================================%%
DRC = [];
for it2 = 1:2:length(eq_blocks)
DRC = [DRC eq_blocks(:,it2)];
end
%% =============================================> Parallel 2 Serial <=====================================================%%
p2s = reshape(DRC,1,N);
p2s(p2s<0) = 0;
p2s(p2s>0) = 1;
RBits = p2s;
%% =============================================> Bit Error Rate Calculations <===========================================%%
[num_of_errors(ss),bits_in_error(ss)] = biterr(DataBits,RBits)
end