charly87
Newbie level 5
- Joined
- Dec 1, 2012
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,348
clear all;
N = 10^6 ;% number of bits or symbols
SNR_db = [0: 25]; % multiple Eb/N0 values
SNR= 10.^(SNR_db./10);
%Transmitter
d = rand(1,N)>0.5; % generating 0,1 with equal probability
Signal = 2*d - 1; % BPSK modulation 0 -> -1; 1 -> 1
for i = 1:length(SNR_db)
w = awgn(Signal,SNR_db(i),-3);
%decision
%errors(i)= zeros(errors);
errors(i)= nnz(Signal.*w <0); % counting errors
end
BER = errors/N; % practical ber
a = 0.5*erfc(sqrt(SNR)); % theoretical ber
figure
semilogy(SNR_db, a,'b.-');
hold on;
semilogy(SNR_db, BER,'or');
axis([0 25 10^-5 0.5])
hold on;
grid on;
legend('theory', 'practical');
xlabel('SNR, db');
ylabel('BER');
title('Bit error probability for BPSK over AWGN channel');
N = 10^6 ;% number of bits or symbols
SNR_db = [0: 25]; % multiple Eb/N0 values
SNR= 10.^(SNR_db./10);
%Transmitter
d = rand(1,N)>0.5; % generating 0,1 with equal probability
Signal = 2*d - 1; % BPSK modulation 0 -> -1; 1 -> 1
for i = 1:length(SNR_db)
w = awgn(Signal,SNR_db(i),-3);
%decision
%errors(i)= zeros(errors);
errors(i)= nnz(Signal.*w <0); % counting errors
end
BER = errors/N; % practical ber
a = 0.5*erfc(sqrt(SNR)); % theoretical ber
figure
semilogy(SNR_db, a,'b.-');
hold on;
semilogy(SNR_db, BER,'or');
axis([0 25 10^-5 0.5])
hold on;
grid on;
legend('theory', 'practical');
xlabel('SNR, db');
ylabel('BER');
title('Bit error probability for BPSK over AWGN channel');