hey i need to know how to get BER vs Distance Plot in VLC system Using Hamming Coding In MATLAB code

5 ビュー (過去 30 日間)
Our Final Year Project is Relaibility Improvement Of data transmisson in indoor VLC system. we doing it using hamming code and LDPC cdoe. our first part is simulation part. we need to get BER vs SNR and BER vs Distance plot. and we have to devided two part systematic code and non systematic code. by the way we have problem in get these plot. we try hard. but still we cant get our Plots Correctly. any one know about this ?
  2 件のコメント
Pavl M.
Pavl M. 2025 年 1 月 3 日
編集済み: Pavl M. 2025 年 1 月 3 日
Hi,
It is quite good question deserving entire answer.
Can it be completed without seeing many, without knowing the systematic and non-systematic parts of codes and scripts, as well as VLC system models and kinds of inputs and outputs?
What is about modulation/demodulation and coding/decoding models and real utile realizations devision?
Let not greedy people, but greedy algorithm to build to construct to do.
Is this assumption correct: BER is close to (correlated) with SNR, since the lower the SNR(the larger a noise) the higher will be BER (the larger will be a bit error rate), in physical sense and BER will grow vs distance increase?

サインインしてコメントする。

採用された回答

Hitesh
Hitesh 2025 年 1 月 3 日
Hi savandi,
I have made the following assumptions, since you have not provided the code, data and how the calculation need to perform:
  • Modulation Scheme: Assuming On-Off Keying (OOK) modulation for VLC systems due to its simplicity.
  • Channel Model: Considering a simple path loss model with additive white Gaussian noise. Assuming the indoor environment is free of multipath effects for simplicity.
  • Noise: Assuming noise is Gaussian with zero mean and a variance determined by the SNR.
  • Error Correction Codes:Uses a (7,4) Hamming code for simplicity, which can correct single-bit errors.For LDPC, assuming a small, predefined parity-check matrix for simplicity.
  • Distance and SNR: Assuming signal power decreases with distance, afecting the SNR. Assumeing a linear relationship between distance and path loss.
I have followed the below steps for simulation:
  • Encoding: Encoded the input data using Hamming codes.
  • Transmission: Simulate the transmission over the VLC channel by adding noise according to the SNR.
  • Decoding: Decoded the received signal using the corresponding decoding algorithm.
  • BER Calculation:Compared the decoded bits with the original bits to calculate the BER.
You might find the following File Exchange resource helpful for Hamming Code Simulation: https://www.mathworks.com/matlabcentral/fileexchange/10774-hamming-7-4-code-simulation
% Parameters
snr_range = 0:1:20; % SNR values from 0 to 20 dB
distances = 1:1:10; % Distances from 1 to 10 meters
num_bits = 1000; % Number of bits to simulate
% Initialize BER arrays
ber_snr = zeros(size(snr_range));
ber_distance = zeros(size(distances));
% BER vs SNR simulation
for i = 1:length(snr_range)
snr = snr_range(i);
noise_var = 10^(-snr/10); % Noise variance based on SNR
errors = 0;
for j = 1:num_bits
% Generate random 4-bit block
bit = randi([0 1], 1, 4);
encoded = encodeHamming74(bit); % Custom function for Hamming encoding
% Add noise
received = encoded + sqrt(noise_var) * randn(size(encoded));
% Decode
decoded = decodeHamming74(received); % Custom function for Hamming decoding
% Count errors
errors = errors + sum(decoded ~= bit);
end
ber_snr(i) = errors / (num_bits * 4);
end
% BER vs Distance simulation
for i = 1:length(distances)
distance = distances(i);
snr = 20 - 2 * distance; % Simple path loss model
noise_var = 10^(-snr/10);
errors = 0;
for j = 1:num_bits
bit = randi([0 1], 1, 4);
encoded = encodeHamming74(bit);
received = encoded + sqrt(noise_var) * randn(size(encoded));
decoded = decodeHamming74(received);
errors = errors + sum(decoded ~= bit);
end
ber_distance(i) = errors / (num_bits * 4);
end
% Plot BER vs SNR
figure;
plot(snr_range, ber_snr, '-o');
xlabel('SNR (dB)');
ylabel('BER');
title('BER vs SNR');
grid on;
% Plot BER vs Distance
figure;
plot(distances, ber_distance, '-o');
xlabel('Distance (m)');
ylabel('BER');
title('BER vs Distance');
grid on;
% Hamming (7,4) Encoding Function
function encoded = encodeHamming74(bits)
G = [1 0 0 0 1 1 0; 0 1 0 0 1 0 1; 0 0 1 0 0 1 1; 0 0 0 1 1 1 1];
encoded = mod(bits * G, 2);
end
% Hamming (7,4) Decoding Function
function decoded = decodeHamming74(received)
% Hard decision decoding: Round the received signal to the nearest bit (0 or 1)
received = round(received);
% Parity-check matrix for (7,4) Hamming code
H = [1 1 0 1 1 0 0;
1 0 1 1 0 1 0;
0 1 1 1 0 0 1];
% Calculate the syndrome
syndrome = mod(received * H', 2);
% Error patterns corresponding to syndromes
error_patterns = [
0 0 0 0 0 0 0; % No error
0 0 0 0 0 0 1; % Error in bit 7
0 0 0 0 0 1 0; % Error in bit 6
0 0 0 0 1 0 0; % Error in bit 5
0 0 0 1 0 0 0; % Error in bit 4
0 0 1 0 0 0 0; % Error in bit 3
0 1 0 0 0 0 0; % Error in bit 2
1 0 0 0 0 0 0; % Error in bit 1
];
% Convert syndrome to decimal index
error_index = bi2de(syndrome, 'left-msb') + 1;
% Correct the received codeword using the error pattern
corrected = mod(received + error_patterns(error_index, :), 2);
% Extract the original 4-bit data from the corrected codeword
decoded = corrected(1:4);
end
  2 件のコメント
savandi navodya
savandi navodya 2025 年 1 月 5 日
thank you for your answers. its very helpfull for us. and also i have question for what you think about LoS(Line of Site). that is the what we need to add our code. but still we cant get correct plot for BER vs Distance plot
Pavl M.
Pavl M. 2025 年 1 月 5 日
編集済み: Pavl M. 2025 年 1 月 5 日
Good question of course desires to be entirely solved, resolved.
Not to undermine, not to diminsh, not to mess, not to deceit You, no, not to gamble, not to fool us for sure as well.
  1. I don't really know much about Hamming coding/decoding and have nothing known to me about LDPC, VLC besides this question. I am not knowledgeable in many digital and analog communication domains. It requires of course dense, narrow, specific, prolonged successfull ordered, well organized study to provide something useful within the domain/scope.
  2. I have some skills in Signal Processing, Research, Operations and want to improve my skills, learn only new useful skill, sharpen existing skill, to apply, de geste existing skills to the benefit of society and not contrary.
I think more accurate channel modeling, analysis should be.
I came up with next code, it runs in TCE, added Hamming(8,4), wanted to add Hamming(7,5)(again I don't know specific Hamming encoding, while 1 other specific encoding and decoding I implemented successfully, which is more like cyphering/decyphering on my personal disk stored, who wants to buy or exchgange it on very needed to me 4 wheeled vehicle car keys modest carriage to drive, pls. let me know) and so tried to add some very novel encoding/decoding as much fast, in high speed r&d fasion hope entire parts of it will be useful after special review and enhancements:
%To be continued, to do, version of 05 Jan 2025
% Parameters
snr_range = 0:1:20; % SNR values from 0 to 20 dB
distances = 0:2:20; % Distances from 2 to 10 meters
num_bits = 1024; % Number of bits to simulate
CodeNBits = 5;
% Initialize BER arrays
ber_snr = zeros(size(snr_range));
ber_distance = zeros(size(distances));
% Hamming (7,4) Encoding Function
function encoded = encodeHamming75(bits)
G1 = [1 0 0 0 1 1 0; 0 1 0 0 1 0 1; 0 0 1 0 0 1 1; 0 0 0 1 1 1 1;1 1 0 0 1 1 1];
G2 = [1 0 0 0 1 1 0; 0 1 0 0 1 0 1; 0 0 1 0 0 1 1; 0 0 0 1 1 1 1;1 1 1 1 0 0 0];
G = [1 0 0 0 1 1 0; 0 1 0 0 1 0 1; 0 0 1 0 0 1 1; 0 0 0 1 1 1 1];
G3 = [1 0 1 0 1 0 1 0; 0 1 1 0 0 1 1 0;0 0 0 1 1 1 1 0;1 1 1 1 1 1 1 1];
encoded = mod(bits * G2, 2);
end
% Hamming (7,4) Decoding Function
function decoded = decodeHamming75(received,CodeNBits)
% Hard decision decoding: Round the received signal to the nearest bit (0 or 1)
received = round(received);
% Parity-check matrix for (7,4) Hamming code
H = [1 1 0 1 1 0 0;
1 0 1 1 0 1 0;
0 1 1 1 0 0 1];
G = [1 0 0 0 1 1 0; 0 1 0 0 1 0 1; 0 0 1 0 0 1 1;0 0 0 1 1 1 1];
%Hamming 8,4:
H2 = [1 0 1 0 1 0 1 0;
0 1 1 0 0 1 1 0;
0 0 0 1 1 1 1 0;
1 1 1 1 1 1 1 1];
G2 = [1 0 1 0 1 0 1 0; 0 1 1 0 0 1 1 0;0 0 0 1 1 1 1 0;1 1 1 1 1 1 1 1];
% Calculate the syndrome
syndrome = mod(received * H', 2);
% Error patterns corresponding to syndromes ?
error_patterns = [
0 0 0 0 0 0 0; % No error
0 0 0 0 0 0 1; % Error in bit 7
0 0 0 0 0 1 0; % Error in bit 6
0 0 0 0 1 0 0; % Error in bit 5
0 0 0 1 0 0 0; % Error in bit 4
0 0 1 0 0 0 0; % Error in bit 3
0 1 0 0 0 0 0; % Error in bit 2
1 0 0 0 0 0 0; % Error in bit 1
];
% error_patterns = [
% 0 0 0 0 0 0 0 0; % No error
% 0 0 0 0 0 0 0 1; %Error in bit 8
% 0 0 0 0 0 0 1 0; % Error in bit 7
% 0 0 0 0 0 1 0 0; % Error in bit 6
% 0 0 0 0 1 0 0 0; % Error in bit 5
% 0 0 0 1 0 0 0 0; % Error in bit 4
% 0 0 1 0 0 0 0 0; % Error in bit 3
% 0 1 0 0 0 0 0 0; % Error in bit 2
% 1 0 0 0 0 0 0 0; % Error in bit 1
% ];
% Convert syndrome to decimal index
error_index = bi2de(syndrome, 'left-msb') + 1;
% Correct the received codeword using the error pattern
corrected = mod(received + error_patterns(error_index, :), 2);
% Extract the original CodeNBits-bit data from the corrected codeword
decoded = corrected(1:CodeNBits);
end
% BER vs SNR simulation
for i = 1:length(snr_range)
snr = snr_range(i);
noise_var = 10^(-snr/10); % Noise variance based on SNR
errors = 0;
for j = 1:num_bits
% Generate random 4-bit block
bit = randi([0 1], 1, CodeNBits);
encoded = encodeHamming75(bit); % Custom function for Hamming encoding
% Add noise
received = encoded + sqrt(noise_var) * randn(size(encoded));
% Decode
decoded = decodeHamming75(received,CodeNBits); % Custom function for Hamming decoding
% Count errors
errors = errors + sum(decoded ~= bit);
end
ber_snr(i) = errors / (num_bits * CodeNBits);
end
% BER vs Distance simulation
for i = 1:length(distances)
distance = distances(i);
snr = 20 - 2 * distance; % Simple path loss model
%Line of Site:
%LOS = f?(distance) ...
noise_var = 10^(-snr/10);
errors = 0;
for j = 1:num_bits
bit = randi([0 1], 1, CodeNBits);
encoded = encodeHamming75(bit);
received = encoded + sqrt(noise_var) * randn(size(encoded));
decoded = decodeHamming75(received,CodeNBits);
errors = errors + sum(decoded ~= bit);
end
slength = num_bits + CodeNBits
ber_distance(i) = errors / (slength);
end
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
slength = 1029
% Plot BER vs SNR
figure;
plot(snr_range, ber_snr, '-o');
xlabel('SNR (dB)');
ylabel('BER');
title('BER vs SNR');
grid on;
% Plot BER vs Distance
figure;
plot(distances, ber_distance, '-o');
xlabel('Distance (m)');
ylabel('BER');
title('BER vs Distance');
grid on;
%Ref: https://fr.wikipedia.org/wiki/Code_de_Hamming, https://en.wikipedia.org/wiki/Hamming(7,4),https://en.wikipedia.org/wiki/Hamming_code
%https://se.mathworks.com/matlabcentral/answers/2068346-what-is-the-relation-between-bit-error-rate-ber-distance-d-and-snr-db
3.
If to address your concern regarding :"but still we cant get correct plot for BER vs Distance plot"
What with ber_distance(i) = errors / (length_of_signal); ?
4.
If to think intuitively, some digital communication accurate practices, modulations are likely, may control nonlinear systems/plants. There are many other things that might be not really needed.
Can you please show example of most accurate control/regulation of natural nonlinear system with help
of a digital communication algorithm?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeError Detection and Correction についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by