BPSK系统仿真及误码率计算源程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MATLAB程序:
主程序:
%Simulation of bpskAWGN
Max_SNR=10;
N_trials=1000;
N=200;
Eb=1;
ber_m=0;
for trial=1:1:N_trials
trial
msg=round(rand(1,N));
s=1-msg.*2;
n=randn(1,N)+j.*randn(1,N);
ber_v=[];
for snr_dB=1:2:Max_SNR
snr=10.^(snr_dB./10); N0=Eb./snr;
sgma=sqrt(N0./2);
y=sqrt(Eb).*s+sgma.*n; y1=sign(real(y));
y2=(1-y1)./2;
error=sum(abs( msg- y2)); ber_snr=error./N; %ber
ber_v=[ber_v,ber_snr];
end%for snr
ber_m=ber_m+ber_v;
end
ber=ber_m./N_trials; ber_theory=[];
for snr_db=1:2:Max_SNR
snr=10.^(snr_db./10);
snr_1=Qfunct(sqrt(2*snr));
ber_theory=[ber_theory,snr_1];
end
%绘图表示实际误码率与理论误码率
i=1:2:Max_SNR;
semilogy(i,ber,'-r',i,ber_theory,'*b');
xlabel('E_b/N_0 (dB)')
ylabel('BER')
legend('Monte Carlo', 'Theoretic')
子程序:
function y = Qfunct(x)
%QFUNC Q function.
% Y = QFUNC(X) returns 1 minus the cumulative distribution function of the
% standardized normal random variable for each element of X. X must be a real
% array. The Q function is defined as:
%
% Q(x) = 1/sqrt(2*pi) * integral from x to inf of exp(-t^2/2) dt
%
% It is related to the complementary error
function (erfc) according to
% Q(x) = 0.5 * erfc(x/sqrt(2))
if (~isreal(x) || ischar(x))
error('comm:qfunc:InvalidArg','The argument of the Q function must be a real array.');
end
y = 0.5 * erfc(x/sqrt(2));
return;