Vous êtes sur la page 1sur 13

Examples of MATLAB code

Examples of Modulation Schemes


Reference:
Mathuranathan Viswanathan, Simulation of
Digital Communication Systems Using
Matlab, 2nd edition
Ex. BPSK Over AWGN

It is assumed that the noise is AWG with


variance:
2
0
=
2
The symbol energy is also given by:
=
Symbol energy Code Rate
log 2 Bit energy
Ex. BPSK Over AWGN

Thus

= =
0 0 2 2

Or
1
2

= 2
0
Ex. BPSK Over AWGN
% BER for BPSK modulation scheme
clear;
clc;
%---------Input Fields------------------------
N=10000000; %Number of input bits
EbN0dB = -6:2:10;
data=randn(1,N)>=0; %Generating a uniformly
distributed random bits
bpskModulated = 2*data-1; %Mapping 0->-1 and 1->1
M=2; %Number of Constellation points M=2^k for BPSK
k=1
Rm=log2(M); %Rm=log2(M) for BPSK M=2
Rc=1; %Rc = code rate for a coded system (no coding
is used Rc=1)
BER = zeros(1,length(EbN0dB)); index=1;
Ex. BPSK Over AWGN
for k=EbN0dB,

%--------------------------------------
=
%Channel Noise for various Eb/N0
%--------------------------------------
%Adding noise with the corresponding variance
EbN0 = 10.^(k/10); % dB to linear scale
noiseSigma = sqrt(1./(2*Rm*Rc*EbN0));
noise = noiseSigma*randn(1,length(bpskModulated));
received = bpskModulated + noise;
%-------------------------------------------
%Threshold Detector
estimatedBits=(received>=0);
%Bit Error rate Calculation
BER(index) = sum(xor(data,estimatedBits))/length(data);
index=index+1;
end
Ex. BPSK Over AWGN
%Plot commands follows
plotHandle=semilogy(EbN0dB,BER,'r--');
set(plotHandle,'LineWidth',1.5);
title('SNR per bit (Eb/N0) Vs BER Curve for BPSK
Modulation Scheme');
xlabel('SNR per bit (Eb/N0) in dB');
ylabel('Bit Error Rate (BER) in dB');
grid on;
hold on;
theoreticalBER = 0.5*erfc(sqrt(10.^(EbN0dB/10)));
plotHandle=semilogy(EbN0dB,theoreticalBER,'k*');
set(plotHandle,'LineWidth',1.5);
legend('Simulated','Theoretical');
grid on;
Ex. BPSK Over AWGN

0
SNR per bit (Eb/N0) Vs BER Curve for BPSK Modulation Scheme
10
Simulated
Theoretical
-1
10
Bit Error Rate (BER) in dB

-2
10

-3
10

-4
10

-5
10

-6
10
-6 -4 -2 0 2 4 6 8 10
SNR per bit (Eb/N0) in dB
Ex. QPSK Over AWGN
% BER for QPSK modulation scheme
clear;
clc;
%---------Input Fields------------------------
N=1000000;%Number of input bits
EbN0dB = -6:2:10; % Eb/N0 range in dB for simulation
%---------------------------------------------
data=randn(1,N)>=0; %Generating a uniformly distributed bits
oddData = data(1:2:end);
evenData = data(2:2:end);
qpskModulated = ;%QPSK Mapping
M=; %Number of Constellation points for QPSK
Rm=log2(M); %Rm=log2(M) for QPSK M=4
Rc=1; %Rc = code rate for a coded system. Since no coding is
used Rc=1
BER = zeros(1,length(EbN0dB)); %Place holder for BER values
for each Eb/N0
Ex. QPSK Over AWGN
index=1;
for k=EbN0dB,
%-------------------------------------------
%Channel Noise for various Eb/N0
%-------------------------------------------
%Adding noise with variance according to the required Eb/N0
EbN0 = 10.^(k/10); %Converting Eb/N0 dB value to linear scale
noiseSigma = sqrt(1./(2*Rm*Rc*EbN0)); %Standard deviation for
AWGN Noise
%Creating a complex noise for adding with QPSK modulated
signal
%Noise is complex since QPSK is in complex representation
(?) noise = ;
received = qpskModulated + noise;
%-------------------------------------------
%Threshold Detector
(?) detected_real = ;
(?) detected_img = ;
estimatedBits=reshape([detected_img;detected_real],1,[]);
%Bit Error rate Calculation
BER(index) = sum(xor(data,estimatedBits))/length(data);
index=index+1;
end
Ex. QPSK Over AWGN
plotHandle=semilogy(EbN0dB,BER,'r--');
% set(plotHandle,'LineWidth',1.5);
title('SNR per bit (Eb/N0) Vs BER Curve for QPSK
Modulation Scheme');
xlabel('SNR per bit (Eb/N0) in dB');
ylabel('Bit Error Rate (BER) in dB');
grid on;
hold on;
theoreticalBER =0.5*erfc(sqrt(10.^(EbN0dB/10)));
plotHandle=semilogy(EbN0dB,theoreticalBER,'b*');
set(plotHandle,'LineWidth',1.5);
legend('Simulated','Theoretical-QPSK');
grid on;
Ex. QPSK Over AWGN

0
SNR per bit (Eb/N0) Vs BER Curve for QPSK Modulation Scheme
10
Simulated
Theoretical-QPSK
-1
10
Bit Error Rate (BER) in dB

-2
10

-3
10

-4
10

-5
10

-6
10
-6 -4 -2 0 2 4 6 8 10
SNR per bit (Eb/N0) in dB

What do you observe by comparing with BER of BPSK?


Modulation
You can further simulate other modulation
schemes 0
10

-1
10

-2
10

-3
10
BER

-4
10

-5
10

-6
BPSK
10 QPSK
16-QAM
-7 32-QAM
10
64-QAM
BPSK with Conv. Code
-8
10
0 2 4 6 8 10 12 14 16 18
Eb/N0 (dB)

Vous aimerez peut-être aussi