You are on page 1of 6

Mini-Project

System Simulation over AWGN Using BPSK Modulation


Due Date: June 5, 2006.
Part I: MATLAB Environment

This exercise will guide you to realize the basic operating environment. Some
useful instructions will also be introduced. As MATLAB is executed, the
MATLAB desktop window will be shown as figure 1.

Figure 1: MATLAB desktop window

All instructions can be looked up and executed in the Command Window. We


encourage you to use help as much as possible and trace the relative instructions
at the same time. Command Window is convenient for execution and finding the
immediate results. If a series of instructions are going to be executed, it is
necessary to edit the .m file. Here are some useful constants and instructions. Try
to explain and reveal how they work.

i j pi eps inf
nan realmax realmin length reshape
conj ones zeros tic、toc clock
profile plot stem awgn sin
sum mean fft clc clear
close figure for while switch
if size fliplr conv randn
rand

1
Part II: Constellation

In modulation systems, each scheme has different error performance. Assume


that 108 random bits are transmitted. In the transmission process, additive white
Gaussian noise (AWGN) is involved in the original data. Encode them according
to BPSK, QPSK, and 16-PSK, and the constellation is depicted as figure 2.
Imag Imag Imag

0110 0010
0111 0011
1
0 0101 0001
0100 0000
Real Real Real
1100 1000
1101 1001
1 1111
0 1011
1110 1010

Figure 2: Constellation for BPSK, QPSK, 16PSK

Part III:

Vector and Matrices


Creation of variables: Call for values:
>> v = zeros(1, 5) >> v ( or v(:) )
>> m = ones(2, 2) >> v(5)
>> v = [1 2 4 8 16] >> w(2:4)
>> w = [ 0: 0.5 : 3 ] >> m(1,2)
>> m = [0.1 0.3 ; 0.2 3] >> m(:,1)

¾ Dimensionality must agree! (+ - * /)


¾ * vs .* / vs ./
¾ If the vector/matrix’s dimensionality is too large (say 100000), cut it into
segments to avoid memory overflow

Math Function
¾ Built-in constants:
„ pi
„ eps --- the smallest value MATLAB can handle
„ inf --- the largest value MATLAB can handle
¾ Built- in functions:
„ sqrt, sin, cos, sort, find, ....

2
Plots & Figures
>> dB = 0: 0.1: 10;
>> SNR = 10.^ (db ./ 10);
>> Pb = 0.5 * erfc(sqrt(SNR));
>> semilogy (dB, Pb);
>> % same as: plot(dB, log10(Pb));
>> grid on;
>> xlabel(‘SNR (dB)’);
>> ylabel(‘Bit error rate’);
>> title(‘Performance of antipodal signal over AWGN channel’);

¾ Several plots in one figure:


>> x = [0: 0.05: 2*pi];
>> figure(1);
>> subplot(1, 2, 1); plot(x, sin(x));
>> title(‘sin’); grid on; axis([0 2*pi -1 1]);
>> subplot(1, 2, 2); plot(x, cos(x));
>> title(‘cos’); grid on; axis([0 2*pi -1 1]);

¾ Other commands: (check help)


„ figure, axis, stem, bar, legend, hold,…

For loops
>> B = [[1 2 3]’ [3 2 1]’ [2 1 3]’];
>> for j = 2: 3
for i = j: 3
B(i,:) = B(i,:) - B(j-1,:) * B(i,j-1) / B(j-1,j-1);
end
end

¾ Avoid loops in your program. Use reasonable vector operation instead


if possible.
¾ Make operations inside loops as few as possible.

3
MATLAB Files
¾ MATLAB script (executable) files (M-file):
„ Edit it in any text editor.
„ Save it with extension ‘.m’ (say ‘hello.m’)
„ Type file name (‘hello’) to start running.

¾ MATLAB data file (mat-file)


>> save result.mat dB , Pb % save variables dB and Pb in result.mat
>> load result.mat % load file
>> whos % check what variables are loaded

Note: MATLAB execution files must end with ‘.m’. Likewise data files end with
‘.mat’. Be sure to be in the appropriate directory to access files.

Exercise
Due Date: June 5, 2006.
Lab: EC634
You have to hand in the report on time. In your report, you should answer the
following three questions.
(a) Execute the attached MATLAB programs to perform estimate and plot the error
probability performance (bit error rate vs SNR(dB)) of a binary antipodal (BPSK)
communication system. In your figure, you should show 2 curves:
(i)The result by simulation.
(ii)The results by analysis.
Note your curve is (log scale in Y axis for BER and X axis for SNR).
(b) Understand the programs and explain why “sgma=E/sqrt(2*SNR)” is used in
subroutine bpsk_sim.m
(c) Modify the code to plot the error probability performance of a QPSK
communication system. In your figure, you should show the result by simulation.

4
Source code
BPSK.m
% MATLAB script for BPSK Performance in AWGN Channel (Simulation
and Theoretical Analysis)
SNRindB1=0:1:10;
SNRindB2=0:0.1:10;
echo on;
for i=1:length(SNRindB1),
% simulated error rate
smld_err_prb(i)=bpsk_sim(SNRindB1(i));
echo off;
end;
echo on;
for i=1:length(SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10);
% theoretical error rate
theo_err_prb(i)=Qfunct(sqrt(2*SNR));
echo off;
end;
echo on;
% Plotting commands follow
semilogy(SNRindB1,smld_err_prb,'*');
hold
semilogy(SNRindB2,theo_err_prb);
xlabel('Eb/N0');
ylabel('Pb');

bpsk_sim.m
function [p]=bpsk_sim(snr_in_dB)
%[p]=bpsk_sim(snr_in_dB)
%simulates the probability of error for the particular
%value of snr_in_dB, signal to noise ratio in dB.
E=1;
SNR=exp(snr_in_dB*log(10)/10); % signal to noise ratio
sgma=E/sqrt(2*SNR); % sigma, standard deviation of noise
N=10000;
% generation of the binary data source follows
for i=1:N,

5
temp=rand; % a uniform random variable over
(0,1)
if (temp<0.5),
dsource(i)=0; % with probability 1/2, source
output is 0
else
dsource(i)=1; % with probability 1/2, source output is
1
end
end;
% the detection, and probability of error calculation
for i=1:N,
% The matched filter outputs
if (dsource(i)==0),
r=-E+sgma*randn(1,1); % if the source output is "0"
else
r=E+sgma*randn(1,1); % if the source output is "1"
end;
% detector follows
if (r<0),
decis=0; % decision is "0"
else
decis=1; % decision is "1"
end;
if (decis~=dsource(i)), % if it is an error, increase the
error counter
numoferr=numoferr+1;
end;
end;
p=numoferr/N; % probability of error estimate

Qfunct.m
function [y]=Qfunct(x)
%[y]=Qfunct(x)
%QFUNCT evaluates the Q-function.
%y = 1/sqrt(2*pi) * integral from x to inf of exp(-t^2/2) dt.
%y = (1/2) * erfc(x/sqrt(2)).
y=(1/2)*erfc(x/sqrt(2));

You might also like