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 nan conj profile sum close if rand
1

j realmax ones plot mean figure size

pi realmin zeros stem fft for fliplr

eps length tictoc awgn clc while conv

inf reshape clock sin clear switch randn

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
0111

Imag
0110 0010 0011 0001 0000

1 Real

0 Real 1

0101 0100 1100 1101 1111 1110 1010

Real
1000 1001 1011

Figure 2: Constellation for BPSK, QPSK, 16PSK

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

Dimensionality must agree! (+ - * /) * vs .* / vs ./ If the vector/matrixs 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, ....

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.

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.

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); sgma=E/sqrt(2*SNR); N=10000; % generation of the binary data source follows for i=1:N, % signal to noise ratio % sigma, standard deviation of noise

temp=rand; (0,1) if (temp<0.5), dsource(i)=0; output is 0 else dsource(i)=1; 1 end end;

% a uniform random variable over

% with probability 1/2, source

% with probability 1/2, source output is

% 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); else r=E+sgma*randn(1,1); end; % detector follows if (r<0), decis=0; else decis=1; end; if (decis~=dsource(i)), error counter numoferr=numoferr+1; end; end; p=numoferr/N; % probability of error estimate % if it is an error, increase the % decision is "1" % decision is "0" % if the source output is "1" % if the source output is "0"

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