- For each trail, the MC method generates random bits and noise transmitted and received.
- At the end, for all the trails, error is averaged out for reliable estimation of ‘BER (Bit Error Rate)’.
how to apply the monte carlo (MC) method on my BPSK_TX_RX code?
4 ビュー (過去 30 日間)
古いコメントを表示
I made this code and I would like some help to apply the Monte Carlo (MC) method in this programming.
Help me!!!
the code follows below:
% BPSK
M = 2;
% número de bits ou símbolos
N = 1000000;
% transmissor
% Gera bits aleatórios ( matriz de variaveis binarias)
Bits_ale = randi([0 M-1],1,N);
% Modulação BPSK 0 -> -1; 1 -> 1
Bits_bpsk = 2 * Bits_ale-1;
% Gera bits de marca d'água aleatórios
Bit_wat = randi([0 M-1],1,N);
Theta = pi/8;
b = 1/sqrt(2)*(randn(1,N) + 1i*randn(1,N)); % white gaussian noise with 0dB variance
Eb_N0_dB = 0:20; % multiple Eb/N0 values
for k = 1:N
if Bit_wat(k)==1
Bit_enviado(k) = Bits_bpsk(k) * exp(1i * Bits_bpsk(k) * Theta);
else
Bit_enviado(k) = Bits_bpsk(k) * exp(-1i * Bits_bpsk(k) * Theta);
end
end
for iter = 1:length(Eb_N0_dB)
% Noise addition
d = Bit_enviado + 10^(-Eb_N0_dB(iter)/20)*b; % additive white guassian noise
% receiver - hard decision decoding
ipHat = real(d)>0;
% counting the errors
nErr(iter) = size(find(Bits_ale- ipHat),2);
end
simBer = nErr/N; % simulated ber
theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber
% plot
close all
figure
semilogy(Eb_N0_dB,theoryBer,'b.-');
hold on
semilogy(Eb_N0_dB,simBer,'mx-');
axis([0 10 10^-5 1])
grid on
legend('theory', 'simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for BPSK modulation');
hold on
grid on
0 件のコメント
回答 (1 件)
Drishti
2024 年 10 月 9 日
Hi Adriane,
To implement Monte Carlo (MC) method, an outer loop for fixed number of ‘MonteCarloTrials’ can be applied over the provided code.
The outer loop on ‘MonteCarloTrails’ is used for the following reasons:
Also, to store the errors for each value ‘nErr’ is utilized.
Refer to the implementation below for better understanding. The ‘nErr’ variable is used to store the errors for each iteration:
nErr = zeros(length(Eb_N0_dB), 1);
for trial = 1:MonteCarloTrials
% Generate random bits (matrix of binary variables)
Bits_ale = randi([0 M-1], 1, N);
% BPSK modulation: 0 -> -1, 1 -> 1
Bits_bpsk = 2 * Bits_ale - 1;
% Generate random watermark bits
Bit_wat = randi([0 M-1], 1, N);
Theta = pi/8;
b = 1/sqrt(2)*(randn(1, N) + 1i*randn(1, N));
% Preallocate transmitted bits
Bit_enviado = zeros(1, N);
% Apply watermark modulation
for k = 1:N
%similar to original code
end
% Loop over each Eb/N0 value
for iter = 1:length(Eb_N0_dB)
%similar to original code
end
end
% Calculate the average error rate over all trials
simBer = nErr / (N * MonteCarloTrials);
% Theoretical BER for BPSK (without watermarking)
theoryBer = 0.5 * erfc(sqrt(10.^(Eb_N0_dB/10)));
Refer to the attached output graph for reference.
I hope this works.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で BPSK についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!