Vous êtes sur la page 1sur 12

1

ELEC450 EXPERIMENT 3 Simulation of a Digital Communication System in Additive White Gaussian Noise Channels

I. OBJECTIVE 1) Understand how to simulate a digital communication system 2) Apply communication theory to implement transmitter, channel and receiver in the Monte-Carlo simulation 3) Study the effect of bit encoding, pulse shaping, a priori distribution of information source, maximum likelihood (ML) and maximum a posteriori detection (MAP) on the error performance through simulation.

II. THEORY Fig. 1 is the block diagram of a simple baseband equivalent digital communication system. The information source generates independent binary data stream {bn } with P (bn = 0) = p and P (bn = 1) = 1 p. The bit-tosymbol mapping block maps every k bits into one of M symbols. The complex symbol stream {an } is passed through a pulse shaping lter p(t) and then transmitted. The transmitted signal is given by

x(t) =
n=

an p(t nT )

(1)

where the average energy in an is Ea = 1/2E[|an |2 ] and the expecation is averaging over all possible signal points in a constellation weighted by their a priori probabilities. The energy in p(t) is denoted by Ep . Hence, the average transmitted energy per symbol is given by Es = Ea Ep .

g
bn bittosymbol a n mapping x(t)

n(t)
y(t) * p(Tt)g yn MAP rule or ML rule an

p(t)

Fig. 1.

The block diagram of a digital communication system.

The channel introduces additive white Gaussian noise (AWGN) to the transmitted signal. The received signal from the antenna is therefore given by

r (t) = x(t) + n(t) =


n=

an p(t nT ) + n(t)

(2)

where n(t) is a zero-mean complex Gaussian random process with variance 2 = N0 in each of its real and imaginary part. After passing through the matched lter (MF) p(T t) and sampled at tn = nT , the received signal sample is given by
yn = an Ep + wn

(3)

2 = N E = 2 E in the real and where wn is a zero-mean complex Gaussian random variable with variance w 0 p p

imaginary part. The probability density function of yn given an is easily derived as


(yn an Ep )2 1 p(yn |an ) = ). exp( 2 2w 2w

(4)

For the n-th symbol, the maximum a posteriori (MAP) probability detection makes a decision on ak that maximizes the a posteriori probability
a map = argak ,1kM max p(ak |yn ) = argak ,1kM max log p(yn |ak ) + log p(ak ). n

(5)

where Bayes theorem p(ak |yn ) = p(yn |ak )p(ak )/p(yn ) has been used. Neglecting the terms that are independent of ak in (5) and (4), we have
2 a map = argak ,1kM max 2w log p(ak ) (yn an Ep )2 n

(6)

The maximum likelihood (ML) detection makes decision based on maximizing the likelihood function as
2 a ml n = argak ,1k M max p(yn |ak ) = argak ,1k M min(yn an Ep ) .

(7)

The ML rule is equivalent to minimum Euclidean distance rule and it is identical to the MAP rule when the M constellations signals occur with equal probability. The BER of Gray-coded QPSK in AWGN with ML detector is given by
Pb = Q( (2Eb /N0 )) = 1/2erfc( (Eb /N0 ))

(8)

In computer simulation, all signals are discrete. To simulate the analog transmitted signal, the channel, and the received antenna signal, we need to sample these analog signal at higher than Nyquist rate (i.e., more than 2 samples per symbol) and use these discrete samples to represent the analog siganl. In this simulation, we use 16

3 T 0

samples per symbol to represent the pulse p(t). The energy in the pulse p(t) is Ep =
Ep =
N 2 i=1 pi

p2 (t)dt. In the simulation,

where N is the number of samples per symbol, pi = p(iTs ) and Ts = T /N is the sampling interval.

In this simulation, we focus on the following set-ups and issues: 1) Using two bit-to-symbol mapping methods: a) 00 1 + j, 01 1 j, 10 1 + j, 11 1 j b) 00 1 + j, 01 1 + j, 10 1 j, 11 1 j 2) Using the following two shaping pulses: a) Rectangular pulse p(t) = uT (t) b) Time domain raised cosine pulse
p(t) = 1 2 1 cos 2t T uT (t)

(9)

3) The channel is AWGN with gain g = ej/8 . 4) Using matched lter receiver with the following detection schemes: (1) ML detector; (2) MAP detector 5) The performance of system is measured by bit-error-rate (BER). At least 10,000 symbols must be used to evaluate the BER of the system.

III. PREPARATION Read the matlab code provided in next section before the lab. In MATLAB workspace, use help conv help rand help randn help reshape help fliplr help sum help sumsqr help min help conj help find to understand the usage of these functions.

IV. PROCEDURE A MATLAB program named awgn_lab3.m is given in the directory /home/student/ELEC450_lab/. It simulates a QAM digital communication system. The detection rule is ML. The following is the matlab le: clear all;

T=16;

% Number of samples per symbol period used in the simulation % This is denoted as N in Section II.

alpha=[[1+1i 1-1i -1+1i -1-1i] [1+1i -1+1i -1-1i 1-1i]]; % Mapping to symbols, QPSK % two rows represent two different % bit-to-symbol mapping P=[0.1 0.2 0.5 0.9]; % source Ns=1e4; % Number of total simulated symbols, that is, simulation length % A priori probablilities of bit 0 in information

g=exp(1i*pi/8); % Channel gain B=[ 0 1 0 1; 0 0 1 1]; % bit encoding/decoding, the i-th column contains bits

% that correspond to the i-th constellation symbol

bps=log2(length(alpha));

% number of bits per symbol

SNRb_dB=0:10;

% SNR values we test. This is SNR per bit.

SNR=10.(SNRb_dB/10)*bps; % change to SNR per symbol in linear scale

Nsnr=length(SNR);

% number of SNR values simulated

BER_ML=zeros(Nsnr,4,2); %initialize BER_ML to 0 BER_MAP=zeros(Nsnr,4,2); %initialize BER_MAP to 0

rand(state,0);

%initialize the state of uniform RNG to 0

randn(state,0); %initialize the state of Gaussian RNG to 0

% Generate noise with variance=1 in real and imaginary part each noise=(randn(T*(Ns+1)-1,1)+1i*randn(T*(Ns+1)-1,1));

%Generate information source. b is a column vector with length Ns*bps %and each element is uniformly distributed in (0,1) b=rand(Ns*bps,1); p=ones(T,1); % p is a column vector containing T samples of a

% rectangular pulse % p(t) for one symbol duration

for P0=1:4 p0=P(P0); %get the a priori probability for bit 0 % generate information binary bit sequence

bits=floor(b+(1-p0));

% for simulation with a given priori % probability of bit 0 (p0), from b. % reshape bits into a "bps(=2 in this example)" X "Ns" matrix, % so that each column with "bps" bits will be mapped to one % symbol later bits=reshape(bits,bps,Ns);

for ALPHA=1:2, % two different bit-to-symbol mapping patterns alphabet=alpha(ALPHA,:); % Map information bit sequence to symbol sequence % "symbol" is a complex row vector. Each element is a symbol symbols=alphabet(1+2.((1:bps)-1)*bits); % Pad each symbol with (T-1) zeros to be convolved with the pulse

% "symbols" is then a "T" X "Ns" matrix symbols=[symbols;zeros(T-1,Ns)]; % Pass symbols through shaping pulse % "symbols(:)" stacks the "symbols" matrix column by column % and creat a column vector. transmit=conv(p,symbols(:));

% Received noiseless signal is the result of transmit signal % multiplied by the channel gain. receive=g*transmit;

% We will compare the received signal (after matched filter) % to the constellation that is also transmitted through the channel % without noise and passed through the matched filter. % The received noiseless constellation is represented by A % A is a "Ns" X "4" matrix, each row contains 4 constellation % symbols and all rows are the same A=ones(Ns,1)*(alphabet*g*sumsqr(p));

for s=1:Nsnr % SNR=Ea*Ep/sig (***)

% where Ea=1/M sum(|alphabet|2)*1/2 is the % average energy of the bandpass signaling, or 1/2 of the % average energy of the complex constellation, % Ep=integral p(t)2 dt, sig is the noise variance % of the real and imaginary part each. Ea=abs(alphabet).2; Ea=1/4*sum(Ea)*1/2; sig=Ea*sumsqr(p)/SNR(s); % sig is calculated from (***) % received signal with a given SNR

r=receive+sqrt(sig)*noise; % Matched filter. "r" is a column vector r=conv(r,fliplr(p)); % Samples filter output every symbol interval (T) r=r((1:Ns)*T);

% y(i,j)=|received(i)-symbol(j)|2, % 1 <= i <= Ns, 1 <= j <= 4 y=r*ones(1,length(alphabet))-A; y=y.*conj(y); y=y; % y is now 4 X Ns

% Detection. Find the minimum distance symbol for each % received symbol. S_est_ml is the detected symbol row vector. [temp,S_est_ml]=min(y);

S_est_ml=B(:,S_est_ml); % decode symbols to bits % Total bits simulated = Ns*bps % Error bits when "S_est_ml" not equal to "bits" BER_ML(s,P0,ALPHA)=length(find(S_est_ml = bits))/(Ns*bps); % s is snr index, P0 is the a priori prob. index, ALPHA is % encoding method index

end % s end % ALPHA end % P0 1) Add plot functionality to the end of the program to plot the bit error rate (BER) of the ML detector as a function of signal-to-noise ratio (SNR) per bit. Plot the BER vs SNR with P (bn = 0) = 0.5 and P (bn = 0) = 0.1, Gray coding and non-Gray coding. You can try to add the following sample code at the end of the program:

figure(1) semilogy(SNRb_dB,squeeze(BER_ML(:,3,1)),rx-); hold on; semilogy(SNRb_dB,squeeze(BER_ML(:,3,2)),-.rx); legend(ML - Gray coding, ML - Non-Gray coding) title(Comparison of different mappings, p_0 = 0.5, rectangular pulse) xlabel(Average E_b/N_0 (dB)); ylabel(BER); hold off;

figure(2) semilogy(SNRb_dB,squeeze(BER_ML(:,1,1)),rx-); hold on; semilogy(SNRb_dB,squeeze(BER_ML(:,1,2)),-.rx); legend(ML - Gray coding, ML - Non-Gray coding) title(Comparison of different mappings, p_0 = 0.1, rectangular pulse) xlabel(Average E_b/N_0 (dB)); ylabel(BER); hold off; Run the program and save the gure les. You can save the gure les in different format in the gure window. 2) Add the theoretical BER result obtained from the BER formula for QPSK with Gray coding (see Eqn. (8)) and plot it on gure(1) to compare the simulation result with the analytical result. Heres the sample code: figure(1) semilogy(SNRb_dB,squeeze(BER_ML(:,3,1)),rx-); hold on; semilogy(SNRb_dB,squeeze(BER_ML(:,3,2)),-.rx); legend(ML - Gray coding, ML - Non-Gray coding) title(Comparison of different mappings, p_0 = 0.5, rectangular pulse) xlabel(Average E_b/N_0 (dB));

ylabel(BER);

%%%%%%%%%%%%%%%%%%% Add in %%%%%%%%%%%%%%%%%%%%%% % Theoretical Pb of QPSK as a function of Eb/N0 % Pb=Q(sqrt(2Eb/N0))=1/2*erfc(sqrt(Eb/N0)) BER_ML_theory=0.5*erfc(sqrt(SNR/bps)); semilogy(SNRb_dB,BER_ML_theory,ko); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hold off; Run the program and save the gure le. Please comment why the SNR variable must be divided by bps in the calculation of BER ML theory. 3) Modify the MATLAB code to include a MAP detector in addition to the ML detector. Add the following sample code after the ML detector y1=(2*sig*log(p_map)*sumsqr(p))*ones(1,Ns); y=y1-y;

[temp,S_est_map]=max(y); S_est_map=B(:,S_est_map); BER_MAP(s,P0,ALPHA)=length(find(S_est_map = bits))/Ns/bps; and the following lines before the for s=1:Nsnr loop %################################################## p_map=[p0*p0 p0*(1-p0) (1-p0)*p0 (1-p0)*(1-p0)]; %################################################## Please comment why Ep (=sumsqr(p)) is required in the MAP detector? What do you expect the performance of MAP detector compared to that of the ML detector? 4) Add plot functionality for the BER of MAP detector. Plot the BER curves together with ML curves for
P (bn = 0) = 0.5 and P (bn = 0) = 0.1, Gray coding and non-Gray coding. Sample codes:

figure(1)

10

semilogy(SNRb_dB,squeeze(BER_ML(:,3,1)),rx-); hold on; semilogy(SNRb_dB,squeeze(BER_ML(:,3,2)),-.rx); %%%%%%%%%%%% Add in %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% semilogy(SNR,squeeze(BER_MAP(:,3,1))); semilogy(SNR,squeeze(BER_MAP(:,3,2)),-.); legend(ML - Gray coding,ML - Non-Gray coding, ... MAP - Gray coding,MAP - Non-Gray coding) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% title(Comparison of different mappings, p_0 = 0.5, rectangular pulse) xlabel(E_b/N_0); ylabel(BER);

% Theoretical Pb of QPSK as a function of Eb/N0 % Pb=Q(sqrt(2Eb/N0))=1/2*erfc(sqrt(Eb/N0)) BER_ML_theory=0.5*erfc(sqrt(SNR/bps)); semilogy(SNRb_dB,BER_ML_theory,ko); hold off;

figure(2) semilogy(SNRb_dB,squeeze(BER_ML(:,1,1)),rx-); hold on; semilogy(SNRb_dB,squeeze(BER_ML(:,1,2)),-.rx); %%%%%%%%%%%%%%%%% Add in %%%%%%%%%%%%%%%%%%%%%%%%%%%%% semilogy(SNR,squeeze(BER_MAP(:,1,1))); semilogy(SNR,squeeze(BER_MAP(:,1,2)),-.); legend(ML - Gray coding, ML - Non-Gray coding, ... MAP - Gray coding, MAP - Non-Gray coding) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

11

title(Comparison of different mappings, p_0 = 0.1, rectangular pulse) xlabel(E_b/N_0); ylabel(BER); hold off; Please comment on the effect of different bit-to-symbol mapping methods on the ML and MAP detector performance. 5) Change the rectangular pulse shape to a time domain raised cosine pulse given by (9). Replace p=ones(T,1); with p=(1-cos(2*pi*(0:(T-1))/T))/2; Run the program and comment on the impact of the shaping pulses on the ML and MAP detector performance. To see the power spectrum of the two pulses, figure(3)

spectrmcos=20*log10(abs(fft(0.5*(1-cos(2*pi*(0:(T-1))/T))/(T/2),1024))); f=linspace(0,pi,512); plot(f,spectrmcos(1:end/2),r) hold on; spectrmrec=20*log10(abs(fft(ones(1,T)/T,1024))); plot(f,spectrmrec(1:end/2),-.); title(Comparing PSD of Shaping Pulses) xlabel(Normalized Frequency) ylabel(|P(f)|2/|P(0)|2 (dB)) legend(time-Limited Raised Cosine, Rectangular) axis([0 3.14 -100 20]) hold off; Which pulse occupies wider bandwidth? 6) Study the impact of the probability distribution of binary data on the ML and MAP detector performance. Output the appropriate simulation data, plot the curves and describe your observation. For example,

12

figure(4)

semilogy(P,squeeze(BER_MAP(1,:,1)),ko); hold on; semilogy(P,squeeze(BER_ML(1,:,1)),-.r); semilogy(P,squeeze(BER_MAP(11,:,2)),kx); semilogy(P,squeeze(BER_ML(11,:,2)),--); title(Impact of P_0) legend(MAP,E_b/N_0=0dB,Gray,ML,E_b/N_0=0dB,Gray, ... MAP,E_b/N_0=5dB,non-Gray,ML,E_b/N_0=5dB,non-Gray) hold off; 7) Choose better bit-to-symbol mapping method and shaping pulse. Plot the BER versus SNR (range from 0-15 dB) when P (bn = 0) = 0.1, 0.2, 0.5, 0.9, respectively. 8) Bonus question. Suppose there is a timing error at the matched lter sampler, that is, the matched lter output is not sampled at the multiple integers of T . Instead, the MF output is taken at 2 samples earlier from the optimum sampling point. Can you modify the program, get the BER result in the presence of timing error and plot it together with the previous BER result (no timing error) for comparison?

Vous aimerez peut-être aussi