BPSK Vs QPSK in An AWGN Channel
BPSK Vs QPSK in An AWGN Channel
Contents
0.1
0.2
0.3
0.4
Introduction . . . . . . . . . . . . . . . . . . . .
Problem Definition and Methodology . . . . . .
0.2.1 Uniform random number generation . .
0.2.2 Gaussian random number generation . .
0.2.3 Modulation through an AWGN channel
0.2.4 BPSK with a phase offset . . . . . . . .
Results . . . . . . . . . . . . . . . . . . . . . . .
0.3.1 Uniform random number generation . .
0.3.2 Gaussian random number generation . .
0.3.3 Modulation through an AWGN channel
0.3.4 BPSK with a phase offset . . . . . . . .
Discussion and Conclusion . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2
3
3
3
3
5
6
6
7
8
9
9
0.1
Introduction
Phase-shift Keying
Phase-shift keying is a scheme of digital modulation that deals with representation of different data signals through the use of a phase-shift on the reference
signal of varying degrees. Two forms of PSK are explored in this practical namely Binary phase shift keying (BPSK) and Quadrature Phase shift keying
(QPSK). [1]
Using a phase shift allows a signal of fixed amplitude to represent multiple
distinct values. These representations (or symbols) can be expressed as a
function of their binary equivalents in a constellation map.
0.2
0.2.1
The probability distribution function of the uniform distribution can be described by [2]:
f (x) =
1
ba
for a x b
f (x) = 0 elsewhere
The uniform distribution required in this practical has bounds a = 0 and b = 1
This can be described by the plot.
From the moment generating functions we can calculate the theoretical mean
() and variance ( 2 ) [2] can be described as:
=
1
1
(a + b) =
2
2
(b a)2
1
=
= 0.083
12
12
To generate random numbers conforming to this uniform distribution, we will
use the Wichmann-Hill Algorithm.
2 =
0.2.2
1 e
2
(x)2
2 2
2
f (x|0, 1) =
x
1 e 2
2
0.2.3
Figure 2: Flow chart depicting the methodology behind simulating the AWGN
channel
0.2.4
This report will also explore the effects of a constant phase-shift applied to the
BPSK coding and whether or not this has an effect even in an AWGN channel
with additive real and imaginary noise. If the bit error rate truly is a function
of orthogonality, there should be no apparent difference in BER plots.
0.3
0.3.1
Results
Uniform random number generation
The uniform number generation results proved consistent with the theoretical
approximation. Slight subtleties visible are due to a finite number of samples
limited to 1 million, with an increase in samples the inconsistencies tend to become less prevalent. Despite the differences, the mean still stays exceptionally
close to the theoretical mean of 0.5 and theoretical variance of 0.0833. Calculated values for the simulation can be seen in figure 3.
0.3.2
Gaussian number generation proved to work well, with a mean difference from
the theoretical value that was extremely small.
Figure 5: Results of the Marsaglia-Bray algorithm for 1 million samples and the
theoretical normal distribution
0.3.3
0.3.4
Figure 8: A plot showing offset BPSK vs regular BPSK bit error rates.
0.4
10
Bibliography
[1] J. G. Proakis, M. Salehi, N. Zhou, and X. Li, Communication systems engineering, vol. 1. Prentice-hall Englewood Cliffs, 1994.
[2] D. Wackerly, W. Mendenhall, and R. Scheaffer, Mathematical statistics with
applications. Cengage Learning, 2007.
11
12
Question 2.m
close all
clear
clc
% sample size:
sample size = 10000000; % no of numbers to generate.
samples = zeros(1,sample size);
for i=1:sample size
r1 = MarsagliaBray();
samples(i) = r1;
end
[ y,x ] = hist(samples, sample size ./ 1000);
bar(x, y/sum(y)/(x(2)-x(1)));
hold on;
x = [-3:.1:3];
norm = normpdf(x,0,1);
plot(x,norm, 'r');
13
Question 3 BPSK.m
% question 3 new:
close all;
clear all;
clc;
% run loop for: minimum of n=100 bits have been run and min of 50 error
% bits detected.
SNRdB = -4:1:8 ; % run from -4 to 8 dB.
BERvalues = zeros(1,length(SNRdB));
noRunsEach = 20;
% seeds:
a = clock;
s1 = sum(a(1:6));
s2 = floor(prod(a(4:6)));
s3 = floor(prod(a(1:2)));
for i=1:length(SNRdB)
% for every dB of SNR we want to iterate through, we need to generate
% and test bits through the AWGN channel until we get min of 50 errors
% or min of 100 bits.
nErrorsAvg = 0;
for n=1:noRunsEach
if ( ((s+1)/2) ~= (r > 0) )
nErrors = nErrors + 1;
end
nBits = nBits + 1;
end
nErrorsAvg = nErrorsAvg + nErrors;
end
14
15
Question 3 QPSK.m
% question 3:
%%%%%%%%
% QPSK %
%%%%%%%%
close all;
clear all;
clc;
% run loop for: minimum of n=100 bits have been run and min of 50 error
% bits detected.
SNRdB = -4:1:8 ; % run from -4 to 8 dB.
BERvalues = zeros(1,length(SNRdB));
noRunsEach = 20;
% seeds:
a = clock;
s1 = sum(a(1:6));
s2 = floor(prod(a(4:6)));
s3 = floor(prod(a(1:2)));
tTime = 0;
for i=1:length(SNRdB)
% for every dB of SNR we want to iterate through, we need to generate
% and test bits through the AWGN channel until we get min of 50 errors
% or min of 100 bits.
tic;
nErrorsAvg = 0;
for n=1:noRunsEach
16
% demodulate:
dR = (sign(real(r))+1)/2; % sign function divides component by mag.
dI = (sign(imag(r))+1)/2; % and convert to binary rep.
% dR and dI now hold the demodulated components of the sent
% signal sR and sI after AWGN.
% does the logical binary interpretation of r match that of s ?
if ( ((sR+1)/2) ~= dR )
nErrors = nErrors + 1;
end
if ( ((sI+1)/2) ~= dI )
nErrors = nErrors + 1;
end
nBits = nBits + 2;
end
nErrorsAvg = nErrorsAvg + nErrors;
end
17
WichmannHill.m
function [r , x, y, z] = WichmannHill(x,y,z)
x = 171 * mod(x, 177) - 2 * (x / 177);
if ( x < 0 )
x = x + 30269;
end
y = 172 * mod(y, 176) - 35 * (y /176);
if (y < 0 )
y = y + 30307;
end
z = 170 * mod(z, 178) - 63 * (z / 178);
if ( z < 0 )
z = z+30323;
end
temp = x/30269.0 + y/30307.0 + z/30323.0;
r = mod( temp , 1.0 );
end
MarsagliaBray.m
% marsaglia-bray
function R1 = MarsagliaBray()
s = 1;
while ( s >= 1 )
v1 = 2 * rand - 1;
v2 = 2 * rand - 1;
s = v1*v1 + v2*v2;
end
L = sqrt(-2 * log(s) / s);
R1 = v1 * L;
end
getSigma.m
function [ outputS ] = getSigma( SNR , fbit )
% SNR in dB
% fbit for BPSK (=1) or QPSK (=2)
outputS = 1 ./ sqrt(power(10, SNR./10) * 2 * fbit);
end
18
ExtraBPSK.m
% BPSK with a pi/4 phase shift.:
close all;
clear all;
clc;
% run loop for: minimum of n=100 bits have been run and min of 50 error
% bits detected.
SNRdB = -4:1:8 ; % run from -4 to 8 dB.
BERvalues = zeros(1,length(SNRdB));
noRunsEach = 20;
constS1 = (1./sqrt(2)) + (1i./sqrt(2));
constS2 = (-1./sqrt(2)) + (-1i./sqrt(2));
% seeds:
a = clock;
s1 = sum(a(1:6));
s2 = floor(prod(a(4:6)));
s3 = floor(prod(a(1:2)));
for i=1:length(SNRdB)
% for every dB of SNR we want to iterate through, we need to generate
% and test bits through the AWGN channel until we get min of 50 errors
% or min of 100 bits.
nErrorsAvg = 0;
for n=1:noRunsEach
= s + (getSigma(SNRdB(i), 1) * MarsagliaBray());
= r + (getSigma(SNRdB(i), 1) * MarsagliaBray())*1i; % complex noise.
now we know we received r.
does the logical binary interpretation of r match that of s ?
now for the comparative logic:
19
end
nErrorsAvg = nErrorsAvg + nErrors;
end
% at this point, we have a pretty good estimation of the number of
% errors so:
BERvalues(i) = (nErrorsAvg/ noRunsEach) / nBits;
disp('Finished an SNR level');
end
20