You are on page 1of 21

EDC 310: Practical 1

BPSK and QPSK through an AWGN channel


Gavin Jaime Fouche
August 21, 2015

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

The role of digital communications


As the amount of information at our fingertips increases and the demand for
increasingly rapid transfer rates grows greater - The common denominator of all
interaction in the digital sphere is encompassed by the concept of digital communication. Digital communication is defined as the physical transfer of data
over a communication channel. We are surrounded by digital communications
every minute of every day, from the mouse you use on your computer to the
mobile telephone in your pocket right now.

Figure 1: Example communication network showing Rx and Tx

Random number generation


Random number generators use algorithms and techniques to produce strings
of numbers that appear to be unrelated and as a result seem to be random.
Computational algorithms generally produce pseudo-random numbers because
their creation is not dependant on a truly random natural process such as atmospheric noise.

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

Problem Definition and Methodology


Uniform random number generation

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

Gaussian random number generation

The normal distribution can be described by a probability distribution function


of
f (x|, ) =

1 e
2

(x)2
2 2
2

f (x|0, 1) =

x
1 e 2
2

Which by definition has mean of 0 and variance 1.[2]

0.2.3

Modulation through an AWGN channel

An Additive Gaussian Noise (AWGN) channel is a path channel described by:


rk = sk + nk
Where r is the received symbol, s is the sent symbol and n is a noise term. It
can be deduced from the inequality present by the non-zero n term that the
received signal will differ slightly by the sent signal s. The AWGN network will
be simulated as described in the flow-chart.

Figure 2: Flow chart depicting the methodology behind simulating the AWGN
channel

0.2.4

BPSK with a phase offset

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.

Figure 3: Constellation maps of BPSK and offset BPSK

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.

Figure 4: Plot of the uniform distribution generated from the Wichmann-Hill


Algorithm for 1 million samples and the theoretical plot.

0.3.2

Gaussian random number generation

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

Modulation through an AWGN channel

Figure 6: BER plot for BPSK on an AWGN channel vs. Theoretical

Figure 7: BER plot for QPSK on an AWGN channel vs. Theoretical

0.3.4

BPSK with a phase offset

Figure 8: A plot showing offset BPSK vs regular BPSK bit error rates.

0.4

Discussion and Conclusion

Random number generation performed as expected with the limited sample


count, matching the theoretical graphs exceptionally well with very small deviation error.
Results for the BPSK/QPSK graphs showed that both phase-shift keying methods shared the exact same BER plots. This is further illustrated in figure 9.

Figure 9: Plot showing BER for BPSK vs QPSK


This is not initially intuitive, transmitting multiple bits at a time seems like it
should have a trade-off in fidelity. However, QPSK symbol mapping is simply
a duo of BPSK signals that are perfectly orthogonal to each other - one BPSK
system on the real axis and another on the imaginary axis. Due to their orthogonality, they hence do not interfere. Analysis (in figure 8) shows that the BER
plots for offset BPSK and regular BPSK do in-fact match each other perfectly.
This is due to the fact that the bit error rate is a function of orthogonality, since
both offset and regular BPSK share the same 180 deg phase shift between their
associated symbols.
It can be concluded that, BPSK and QPSK are digital modulation schemes
with a good fidelity when transmitting through an additive white Gaussian
noise channel provided that the SNR is of an acceptable degree. We can also
conclude that signal fidelity is a function of orthogonality between symbols. It
can be seen (by figure 9) that QPSK and BPSK both share the same BER
plot. If the symbol rate (bandwidth) is the same for BPSK and QPSK, QPSK
will perform considerably worse with the same signal power. This performance
consideration is alleviated by QPSKs higher symbol rate so it appears to have
the same BER as BPSK. Therefore, QPSK achieves the same bit error rate at
the cost of added signal power required to transmit.

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

Appendix A: MATLAB code


Question 1.m
close all
clear
clc
% sample size:
sample size = 1000000; % no of numbers to generate.
samples = zeros(1,sample size);
a = clock;
s1 = sum(a(1:6));
s2 = floor(prod(a(4:6)));
s3 = floor(prod(a(1:2)));

for i=1:sample size


[ r , s1, s2, s3 ] = WichmannHill(s1,s2,s3);
samples(i) = r;
end
[y,x] = hist(samples, 100);
bar(x, y/sum(y)/(x(2)-x(1)));
hold on;
% Create three distribution objects with different parameters
pd1 = makedist('Uniform');
% Compute the pdfs
x = -0.5:.01:1.5;
pdf1 = pdf(pd1,x);
stairs(x,pdf1,'r','LineWidth',2);
ylim([0 1.1]);
hold off;

title(sprintf('Probability Distribution for the Wichmann-Hill algorithm\nMean : %f \nVariance: %f\nSt


ylabel('Probability');
xlabel('Values');
legend('Simulated Distribution', 'Theoretical Distribution');

fprintf('Mean : %f \nVariance: %f\nStandard Deviation: %f\n', mean(samples), var(samples), std(sample

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');

title(sprintf('Probability Distribution for the Marsaglia-Bray algorithm\nMean : %f \nVariance: %f\nS


ylabel('Probability');
xlabel('Values');
legend('Simulated Distribution', 'Theoretical Distribution');
fprintf('Mean : %f \nVariance: %f\nStandard Deviation: %f\n', mean(samples), var(samples), std(sample

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

nBits = 0; % start at zero.


nErrors = 0; % no errors for this SNR.
while (nBits < 100000 && nErrors < 50000)
%
%
[
s
r
%
%

just keep going.


generate a new bit:
randWich , s1, s2, s3 ] = WichmannHill(s1,s2,s3);
= 2 * (randWich > 0.5) - 1; % transmitted symbol.
= s + (getSigma(SNRdB(i), 1) * MarsagliaBray());
now we know we received r.
does the logical binary interpretation of r match that of s ?

if ( ((s+1)/2) ~= (r > 0) )
nErrors = nErrors + 1;
end
nBits = nBits + 1;

end
nErrorsAvg = nErrorsAvg + nErrors;
end

14

% 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

BERideal=(1/2)*erfc(sqrt(10.(SNRdB/10))); % ideal BER.


semilogy(SNRdB, BERvalues);
title('A bit-error rate curve for BPSK on an AWGN channel');
hold on;
semilogy(SNRdB,BERideal, '.r');
legend('Simulation', 'Theoretical');
xlabel('SNR (in dB)');
ylabel('BER');

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

nBits = 0; % start at zero.


nErrors = 0; % no errors for this SNR.
while (nBits < 100000 && nErrors < 50000)
%
%
[
[
%

just keep going.


generate two symbol components (Quadrature and In-phase)
randWich1 , s1, s2, s3 ] = WichmannHill(s1,s2,s3);
randWich2 , s1, s2, s3 ] = WichmannHill(s1,s2,s3);
now map these double digits to their const maps:

sR = 2 * (randWich1 > 0.5) - 1;


sI = 2 * (randWich2 > 0.5) - 1;
% add noise, NOTICE fbit changes.
r = (sR + sI*1i) + (getSigma(SNRdB(i), 1) * MarsagliaBray());
r = r + ((getSigma(SNRdB(i), 1) * MarsagliaBray())*1i); % add complex noise.

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

% 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');
tTime = (tTime + toc);
tAvg = tTime./i; % record the time taken for this run, estimate further runs.
fprintf('Estimated time to simulation completion: %d minutes.', round(tAvg*(length(SNRdB) - i)./6
end
BERideal=(1/2)*erfc(sqrt(10.(SNRdB/10))); % ideal BER.
semilogy(SNRdB, BERvalues);
title('A bit-error rate curve for QPSK on an AWGN channel');
hold on;
semilogy(SNRdB,BERideal, '.r');
legend('Simulation', 'Theoretical');
xlabel('SNR (in dB)');
ylabel('BER');

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

nBits = 0; % start at zero.


nErrors = 0; % no errors for this SNR.
while (nBits < 100000 && nErrors < 50000)
%
%
[
%

just keep going.


generate a new bit:
randWich , s1, s2, s3 ] = WichmannHill(s1,s2,s3);
round for bit representation.

if (randWich > 0.5)


s = (1./sqrt(2)) + (1i./sqrt(2)); % if bit is 1 then map to top right
else
s = (-1./sqrt(2)) + (-1i./sqrt(2)); %
end
r
r
%
%
%

= 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

% if the delta value of S1 is smaller than delta of S2 we know


% that it is S1.
if ( abs( r - constS1 )2 < abs( r - constS2)2)
dR = (1./sqrt(2)) + (1i./sqrt(2)); % S1
else
dR = (-1./sqrt(2)) + (-1i./sqrt(2)); % S2
end
if (dR ~= s)
nErrors = nErrors + 1;
end
nBits = nBits + 1;

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

BERideal=(1/2)*erfc(sqrt(10.(SNRdB/10))); % ideal BER.


semilogy(SNRdB, BERvalues);
title('A bit-error rate curve for 45 degree phase-offset BPSK on an AWGN channel');
hold on;
semilogy(SNRdB,BERideal, '.r');
legend('Offset BPSK', 'Normal BPSK');
xlabel('SNR (in dB)');
ylabel('BER');

20