您的当前位置:首页正文

BPSK的误比特率性能进行了仿真

2020-11-09 来源:好走旅游网


本代码对BPSK的误比特率性能进行了仿真,给出了Mente Carlo仿真结果与理论分析结果的对比。

以下是源代码和仿真结果图:

% -------------------------------------------------------------------------

% Main Program lavabin 2006.07.25

% -------------------------------------------------------------------------

% % This program is used to get the BPSK BER curve under AWGN condition

% % Assuming that Eb = 0

% % Theoretical BER = Q(sqrt(2*Eb/No))

% -------------------------------------------------------------------------

echo off

clc

clear all

close all

tic

% ---------------------------------------------------

coefNum = 2^16;

SNR_in_dB = [0:0.1:10];

signalTx = rand(1, coefNum);

signalTx(find(signalTx <= 0.5)) = -1;

signalTx(find(signalTx > 0.5)) = +1;

[Pe] = BPSK_AWGN_Pe(signalTx, SNR_in_dB);

for i = 1:length(SNR_in_dB)

SNR(i) = 10^(SNR_in_dB(i)/10);

Pe_theoretical(i) = qfunc(sqrt(2*SNR(i)));

end

% ---------------------------------------------------

figure(1);

grid on

semilogy(SNR_in_dB, Pe,'go-');

hold on

semilogy(SNR_in_dB, Pe_theoretical,'r*-');

legend('Pe Actual','Pe Theoretical');

title('BPSK BER Performance Evaluation');

xlabel('Eb/No');

ylabel('BPSK BER');

% ---------------------------------------------------

echo on

simulation_time = toc

% -------------------------------------------------------------------------

% End of Function

% -------------------------------------------------------------------------

%--------------------------------------------------------------------------

%% Avetis Ioannisyan

% 10/26/05

%--------------------------------------------------------------------------

% Given desired SNR and the input signal, function outputs prob of error

% occuring in AWGN environment such that N(0, No/2). The input signal is

% modulated digital using ASK with amplitude -1 and +1

%

% Example:

% coefNum = 2^17;

% SNR = [0:0.1:10];

%

% signalTx = rand(1, coefNum);

% signalTx(find(signalTx <= 0.5)) = -1;

% signalTx(find(signalTx > 0.5)) = +1;

%

% [Pe] = BPSK_AWGN_Pe(signalTx, SNR);

%

% semilogy(SNR, Pe);

% -------------------------------------------------------------------------

% lavabin 2006.07.25

% -------------------------------------------------------------------------

function [Pe] = BPSK_AWGN_Pe(signalTx, SNR)

% number of coef to generate (length)

coefNum = length(signalTx);

N0=[]; AWGN=[]; Pe=[]; signalRx=[];

% create white noise N(0, 0.5)

randn('state',sum(100*clock));

% % Reset randomizer

% % ------------------------------------------------------------

% % Return RANDN to its default initial state.

% % randn('state',0)

% % ------------------------------------------------------------

% % Initialize RANDN to a different state each time.

% % randn('state',sum(100*clock))

% % ------------------------------------------------------------

AWGN = randn(length(SNR), coefNum);

% Construction of AWGN Matrix

for i = 1:length(SNR)

% make noise level from specified SNR: No = 1/(10^(SNR/10)) assuming Eb=1

N0(i) = 1/(10^(SNR(i)/10)); %generate No, or, sqrt(variance) = No for the WGN noise

% adjust for the desired N(0,No/2) => X = mue + sqrt(var)*N(0, 0.5)

AWGN(i,:) = sqrt(N0(i)./2) .* AWGN(i,:);

% produce received signal

signalRx(i,:) = signalTx + AWGN(i,:);

% perform signal detection

signalRx(i, find(signalRx(i,:) <= 0)) = -1;

signalRx(i, find(signalRx(i,:) > 0)) = +1;

% estimate error probability

error = length(find(signalRx(i,:)-signalTx));

Pe(i) = error / coefNum;

end

% -------------------------------------------------------------------------

% End of Function

% -------------------------------------------------------------------------

下面是图形结果:

因篇幅问题不能全部显示,请点此查看更多更全内容