Professional Documents
Culture Documents
Nguyễn Đình Phong-B21DCVT342
Nguyễn Đình Phong-B21DCVT342
MSV : B21DCVT342
Bài 2 Mô phỏng BER hệ thống BPSK trong môi trường kênh AWGN
- Năng lượng bit Eb ảnh hưởng tới tỉ số lỗi bit qua công thức
-
Nếu Eb càng tăng thì Pe càng giảm
- Numbits là số bit được truyền vào
- X là tín hiệu nhiễu của kênh AWGN cộng với tín hiệu tại đầu vào và là biến
ngẫu nhiên phân bố chuẩn với trung bình 0
Câu 3 Mô phỏng
%==========================================================================
%=================== Sim_FWC_02_02_BER_BPSK_AWGN ==========================
%==========================================================================
clc; clear; close all;
%==========================================================================
SNRindB = 0:1:9; % signal to noise ratio dB
SNR = 10.^(SNRindB/10);
Eb = 1; % energy per bit
sgma = Eb./sqrt(2*SNR); % sigam, standard deviation of noise is
% noisepower = sgma.^2
NumBits = 10^7; % Number of Bits
%==========================================================================
% Theoretical error rate
% Calculation for error Probability: Orthogonal
% theo_Orthogonal_err_prb = Qfunct(sqrt(SNR));
theo_Orthogonal_err_prb = 0.5 *erfc(sqrt(SNR/2));
% Calculation for error Probability: Antipodal signal
% theo_Antipodal_err_prb = Qfunct(sqrt(2*SNR));
theo_Antipodal_err_prb = 0.5 *erfc(sqrt(SNR));
%==========================================================================
% Simulated error rate
h = waitbar(0,'Please wait...');
% minTime = Inf;
tic
for j=1:length(SNR)
tStart = tic; % TIC, pair 2
waitbar(j/length(SNRindB));
dsource_1 = 0.5*(sign(rand(1,NumBits)-0.5)+1);
numoferr = 0;
for i=1:NumBits
% Generation of the binary data source and Pass AWGN channel
temp = rand; % Uniform radom variable over (0,1)
if (temp<0.5),
dsource(i) =1; % With probability 1/2 source
output is 1
X = sgma(j)*randn(1);
Y = -sqrt(Eb) + X; % 1 with enrery is -sqrt(Eb);
and pass AWGN channel
else
dsource(i) = 0; % With probability 1/2 source
output is 0
X = sgma(j)*randn(1);
Y = sqrt(Eb) + X; % 0 with enrery is +sqrt(Eb);
and pass AWGN channel
end
% detector follows/Decission
if (Y<0)
decis(i) = 1; % Decission is '1'
else
decis(i) = 0; % Decission is '0'
end;
end;
numoferr = sum(decis~=dsource);
smld_err_prb(j) = numoferr/NumBits; % Probability of error estimate
%-------------------------
tElapsed = toc(tStart); % TOC, pair 2
% minTime = min(tElapsed, minTime)
end;
SimTime = max(tElapsed)
close(h);
%==========================================================================
save Sim_FWC_02_02_BER_BPSK_AWGN.mat;
%==========================================================================
h1 = figure(1);
% set(h1,'color','c');
set(h1,'Name','Sim_FWC_02_02_BER_BPSK_AWGN');
subplot(121)
G = semilogy(SNRindB,smld_err_prb,'-
vr',SNRindB,theo_Antipodal_err_prb,'-ob');
set(G,'LineWidth',[1.5]);
xlabel('SNR [dB]','FontName','.VnTime','color','b','FontSize',12);
ylabel('Xac suat loi
Pe','FontName','.VnTime','color','b','FontSize',18);
title(['Mo phong BER ho thong BPSK trong kenh AWGN; N_s_i_m_b_i_t =
',num2str(NumBits),' bits
'],'FontName','.VnTime','color','r','FontSize',14);
LT = legend('Mo phong ',' Tinh toan');
set(LT,'FontName','.VnTime','FontSize',16);
AX=gca;
set(AX,'FontSize',14);
axis([min(SNRindB) max(SNRindB), 1e-5 0.2]);
grid on
text(2,7e-5,'Mo hinh hoa ve mo
phong','FontName','.VnTimeh','Color','b','FontSize',14);
text(0.5,min(theo_Antipodal_err_prb),'Tinh chinh xac cua ket qua mo
phong, xac nhan ve pho chuan mo
hinh','FontName','.VnTimeh','Color','r','FontSize',9.9)
subplot(122)
G = semilogy(SNRindB,theo_Orthogonal_err_prb,'-vr');
G = semilogy(SNRindB,theo_Orthogonal_err_prb,'-
vr',SNRindB,theo_Antipodal_err_prb,'-ob');
set(G,'LineWidth',[1.5]);
xlabel('SNR [dB]','FontName','.VnTime','color','b','FontSize',12);
ylabel('Xac suat loi
Pe','FontName','.VnTime','color','b','FontSize',18);
title('So sanh xac suat loi bit he thong BPSK truc giao va doi cuc
trong k?nh AWGN','FontName','.VnTime','color','b','FontSize',15);
LT = legend(' Truc giao',' doi cuc');
set(LT,'FontName','.VnTime','FontSize',16,'fontweight','normal','fontAngle'
,'normal');
AX = gca;
set(AX,'FontSize',14);
axis([min(SNRindB) max(SNRindB), 1e-5 0.2]);
grid on;
text(2,7e-5,'Tinh toan so sanh hieu
nang','FontName','.VnTimeh','Color','b','FontSize',14);
%==========================================================================
% Measure multiple time spans simultaneously using two pairs of tic/toc
calls. To do this,
% measure the minimum and average time to compute a summation of Bessel
functions: