- 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.
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 ?
10 views (last 30 days)
Show older comments
Mashrur Zawad
on 30 Mar 2022
Answered: Shashi Kiran
on 11 Sep 2024
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
0 Comments
Accepted Answer
Shashi Kiran
on 11 Sep 2024
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).
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);
% 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 Comments
More Answers (0)
See Also
Categories
Find more on BPSK in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!