BPSK bpsk in awgn not matching theoretical results

11 Ansichten (letzte 30 Tage)
Russell Geschrey
Russell Geschrey am 19 Jan. 2021
Beantwortet: Umeshraja am 6 Mär. 2025 um 5:36
I am doing a monte carlo simulation for BPSK signals and I am getting a result of (roughly):
I know the result is supposed to be:
Can someone please look at my code provide some pointers as to what I'm doing wrong?
Fs = 10; %Sample Frequency
Ts= 1/Fs;
t= 0:Ts:1;
degree=1; %Degree of the space ie. BPSK= 1
sim_length= 40000; %Number of symbols sent in the simulation
error_count=0;
%Define the two symbols to transmit
p{1,1}= sqrt(2)*sin(2*pi*t);
p{1,2}= sqrt(2)*sin(2*pi*t+pi);
x=0;
for Eb_No= 0:10
%Begin Monte Carlo for the desired SNR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:sim_length
%ceil rounds up always
symbol= ceil(2*degree*rand); %Pick rand Symbol index
symbol_to_tx= cell2mat(p(symbol)); %Create that symbol to transmit
%%%%%%%%% https://www.mathworks.com/help/comm/ug/awgn-channel.html
Eb_No_SAMPLE = Eb_No+10*log10(1/Fs) ;
noisy_sig= awgn(symbol_to_tx, Eb_No_SAMPLE, 'measured' ); %Signal is injected with noise
for j=1:2*degree
%%Multiply against each symbol in the dicationary, and then
%%integrate over one period
symbol_dictinory= cell2mat(p(j));
test_funct= noisy_sig .* symbol_dictinory;
ML_vector(j)=trapz(test_funct)* (1/Fs);
% (1/Fs) is required to normalize because of sampling
% note that trapz is an approximation
%Highest output in ML vector is the "most likely" symbol that was tx'ed.
end
[~,ML_symbol] = max(ML_vector);
%If the ML decoder was wrong, incrment the error count
if ML_symbol ~= symbol
error_count=error_count+1;
end
P_error= error_count/sim_length;
end
%End Monte Carlo for the desired SNR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=x+1;
ber(x)=P_error;
%https://www.mathworks.com/help/comm/ug/bit-error-rate-ber.html
%%%This is just the theoretical error of the AWGN QPSK to compare
Eb_No_db(x)=Eb_No;
Eb_No_lin=10.^(Eb_No_db./10);
% theory_ber=0.5.*erfc(sqrt(Eb_No_lin));
theory_ber= qfunc( sqrt(2*Eb_No_lin) );
%%%Reset counters for next dB iteration
error_count=0;
P_error=0;
end
semilogy(Eb_No_db,ber,'-bo',Eb_No_db,theory_ber,'-mh')
grid on
title('BPSK with AWGN');
xlabel('E_b/N_o');
ylabel('P_b = BER');
legend('Simulated BPSK','bpsk theory')

Antworten (1)

Umeshraja
Umeshraja am 6 Mär. 2025 um 5:36
I understand that you are looking to generate the Bit Error Rate (BER) curve for Binary Phase Shift Keying (BPSK) using both theoretical and simulation methods. Below is a another version to address any potential issues:
clear all; close all;
sim_length = 1e5; % Number of bits to simulate
Eb_No_dB = 0:1:9; % Eb/N0 range in dB
% Preallocate BER vector
ber = zeros(size(Eb_No_dB));
% Monte Carlo simulation
for i = 1:length(Eb_No_dB)
Eb_No = 10^(Eb_No_dB(i)/10); % Linear Eb/N0
% Generate random bits
bits = randi([0 1], 1, sim_length);
% Map bits to symbols
tx_signal = (1-2*bits); % 0 -> +1, 1 -> -1
% Generate noise
noise = randn(1, sim_length) / sqrt(2*Eb_No);
% Add noise to create received signal
rx_signal = tx_signal + noise;
% Detect symbols
detected_bits = rx_signal < 0;
% Count errors
errors = sum(bits ~= detected_bits);
% Calculate BER
ber(i) = errors / sim_length;
end
% Theoretical BER
theory_ber = qfunc(sqrt(2*10.^(Eb_No_dB/10)));
% Plot results
semilogy(Eb_No_dB, ber, 'bo-', Eb_No_dB, theory_ber, 'r-');
grid on;
xlabel('Eb/N0 (dB)');
ylabel('Bit Error Rate (BER)');
title('BPSK BER Performance in AWGN');
legend('Simulation', 'Theory');
Hope this helps!

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by