clear all;
EbN0_dB = 0:2.5:30;
EbN0 = 10.^(EbN0_dB/10);
Analytical_BER_ASK = Q(sqrt(EbN0));
Analytical_BER_BPSK = Q(sqrt(2*EbN0));
L = 1000;
Numerical_BER_ASK = zeros(1,length(EbN0));
Numerical_BER_BPSK = zeros(1,length(EbN0));
for i=1:length(EbN0)
ASK_error = 0;
BPSK_error = 0;
noOfL = 0;
while BPSK_error < 100
N0 = 1/(EbN0(i));
s = randi([0,1],1,L);
ASK_TX_signal = s*sqrt(2);
BPSK_RX_signal = 2*s - 1;
noise = sqrt(N0/2) * randn(1,L);
channel = sqrt(1/2)*(randn(1,L) + 1i*randn(1,L));
ASK_RX_signal = channel.*ASK_TX_signal + noise;
BPSK_RX_signal = channel.*BPSK_RX_signal + noise;
ASK_RX_signal = conj(channel).*ASK_RX_signal;
BPSK_RX_signal = conj(channel).*BPSK_RX_signal;
ASK_s = double(ASK_RX_signal > sqrt(2)/2);
BPSK_s = double(BPSK_RX_signal > 0);
ASK_error = ASK_error + sum(ASK_s~=s);
BPSK_error = BPSK_error + sum(BPSK_s~=s);
noOfL = noOfL + 1;
end
Numerical_BER_ASK(i) = ASK_error/L/noOfL;
Numerical_BER_BPSK(i) = BPSK_error/L/noOfL;
end
A_ASK = semilogy(EbN0_dB,Analytical_BER_ASK,'-');
hold on
A_BPSK = semilogy(EbN0_dB,Analytical_BER_BPSK,'--');
N_ASK = semilogy(EbN0_dB,Numerical_BER_ASK,'o');
N_BPSK = semilogy(EbN0_dB,Numerical_BER_BPSK,'s');
xlabel('Eb/N0 in dB');
ylabel('BER');
legend([A_ASK A_BPSK N_ASK N_BPSK],'Analytical ASK','Analytical BPSK',...
'Numerical ASK','Numerical BPSK');
Best Answer