In BER SIMULATION of BPSK IN RAYLEIGH FADING ENVIRONMENT when I place h=sqrt(1/2​)*(randn+j​*randn) before while loop I don't get any curve and total BER result why is that ?

9 ビュー (過去 30 日間)
clear
EbN0dB_vector=0:2:20
Eb=1;
for snr_i=1:length(EbN0dB_vector);
EbN0dB=EbN0dB_vector(snr_i);
EbN0=10.^(EbN0dB/10)
N0=Eb/EbN0;
sym_cnt=0
err_cnt=0
h=sqrt(1/2)*(randn+j*randn);
while err_cnt<500
s=sqrt(Eb)*sign(rand-0.5) ;
n=sqrt(N0/2)*(randn+j*randn);
r=h*s + n;
D=r*exp(-j*angle(h));
s_hat=sign(real(D));
if s_hat~=s
err_cnt=err_cnt+1;
end
sym_cnt=sym_cnt+1;
end
BER(snr_i)=err_cnt/sym_cnt
end
figure
semilogy(EbN0dB_vector, BER)%y in logarithm scale
xlabel('E_b/N_0 [dB]')
ylabel('BER')
grid
%Get result upto this
BER =
0.0543 0.0001 0.0057 0.0008 0.0007 0.0031 0.0049

採用された回答

Shashi Kiran
Shashi Kiran 2024 年 9 月 11 日
Hi Mashrur,
I understand that you are encountering an issue of not getting the complete Bit Error Rate (BER) results for all Signal to Noise Ratio (SNR) values when you place the channel matrix (h) before the while loop in your code.
This occurs because, placing channel matrix h outside the loop results in a constant channel for all symbols, simulating a slow fading scenario (Constant Channel Effect).
  • If the channel is poor, errors accumulate quickly, ending the loop sooner.
  • If the channel is good, it takes longer to reach the error threshold, causing the program to run continuously, as you observed.
To simulate fast fading, generate h inside the loop so the channel changes for each symbol. This approach offers a more robust and realistic evaluation of system performance across varying conditions.
Here is how the code can be modified to simulate a fast fading scenario:
clear;
EbN0dB_vector = 0:2:20;
Eb = 1;
BER = zeros(1, length(EbN0dB_vector)); % Pre-allocate BER array
for snr_i = 1:length(EbN0dB_vector)
EbN0dB = EbN0dB_vector(snr_i);
EbN0 = 10^(EbN0dB / 10);
N0 = Eb / EbN0;
sym_cnt = 0;
err_cnt = 0;
while err_cnt < 500
% Generate a random BPSK symbol
s = sqrt(Eb) * (2 * (rand > 0.5) - 1);
% Rayleigh fading channel
h = (1/sqrt(2)) * (randn + 1i * randn);
% AWGN noise
n = sqrt(N0/2) * (randn + 1i * randn);
% Received signal
r = h * s + n;
% Coherent detection
D = r * exp(-1i * angle(h));
% Decision
s_hat = sign(real(D));
% Error counting
if s_hat ~= s
err_cnt = err_cnt + 1;
end
sym_cnt = sym_cnt + 1;
end
% Calculate BER
BER(snr_i) = err_cnt / sym_cnt;
end
disp(BER);
0.1465 0.1067 0.0777 0.0538 0.0336 0.0240 0.0150 0.0098 0.0060 0.0037 0.0025
% Plotting
figure;
semilogy(EbN0dB_vector, BER, 'b-o'); % Plot with blue circles
xlabel('E_b/N_0 [dB]');
ylabel('BER');
title('BER vs E_b/N_0 for BPSK over Rayleigh Channel');
grid on;
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBPSK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by