Download S-72

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
S-72.227 Digital Communication Systems
Spring 2002 MATLAB Assignment #1 Solution
Grading Policy: Out of 5 points
1. Report : 1.5 points
2. MATLAB Script: 2 points
3. Testing: 1.5 points
The codes are given below:
%*******************************************************************
%*******************************************************************
% Spring 2002
% S-72.227 Digital Communications Course
% MATLAB script for MATLAB Assignment-1.
% Course Assistant: Muhamamd Imadur Rahman
%*******************************************************************
%*******************************************************************
echo on
SNRindB1=0:2:15;
SNRindB2=0:0.1:15;
M=16;
k=log2(M);
for i=1:length(SNRindB1),
smld_err_prb(i)=errsim(SNRindB1(i));
% simulated error rate
end;
for i=1:length(SNRindB2),
SNR=exp(SNRindB2(i)*log(10)/10);
% signal to noise ratio
% theoretical symbol error rate
theo_err_prb(i)=4*Qfunct(sqrt(3*k*SNR/(M-1)));
end;
% Plotting commands follow
semilogy(SNRindB1,smld_err_prb,'*');
hold
semilogy(SNRindB2,theo_err_prb);
%*******************************************************************
%*******************************************************************
function [p]=errsim(snr_in_dB)
% [p]=errsim(snr_in_dB)
%
errsim finds the probability of error for the given
%
value of snr_in_dB, SNR in dB.
N=10000;
d=1;
% min. distance between symbols
Eav=10*d^2;
% energy per symbol
snr=10^(snr_in_dB/10);
% SNR per bit (given)
sgma=sqrt(Eav/(8*snr));
% noise variance
M=16;
% generation of the data source follows
for i=1:N,
temp=rand;
% a uniform R.V. between 0 and 1
dsource(i)=1+floor(M*temp);
% a number between 1 and 16, uniform
end;
% Mapping to the signal constellation follow
mapping=[-3*d 3*d;
-d 3*d;
d 3*d;
3*d 3*d;
Course Assistant: Muhammad Imadur Rahman, Phone: 09-4514905, e-mail: [email protected]
1
-3*d d;
-d d;
d d;
3*d d;
-3*d -d;
-d -d;
d -d;
3*d -d;
-3*d -3*d;
-d -3*d;
d -3*d;
3*d -3*d];
for i=1:N,
qam_sig(i,:)=mapping(dsource(i),:);
end;
% received signal
for i=1:N,
[n(1) n(2)]=gngauss(sgma);
r(i,:)=qam_sig(i,:)+n;
end;
% detection and error probability calculation
numoferr=0;
for i=1:N,
% metric computation follow
for j=1:M,
metrics(j)=(r(i,1)-mapping(j,1))^2+(r(i,2)-mapping(j,2))^2;
end;
[min_metric decis] = min(metrics);
if (decis~=dsource(i)),
numoferr=numoferr+1;
end;
end;
p=numoferr/(N);
%*******************************************************************
%*******************************************************************
function [gsrv1,gsrv2]=gngauss(m,sgma)
% [gsrv1,gsrv2]=gngauss(m,sgma)
% [gsrv1,gsrv2]=gngauss(sgma)
% [gsrv1,gsrv2]=gngauss
%
GNGAUSS generates two independent Gaussian random variables with mean
%
m and standard deviation sgma. If one of the input arguments is missing
%
it takes the mean as 0, and the standard deviation as the given parameter.
%
If neither mean nor the variance is given, it generates two standard
%
Gaussian random variables.
if nargin == 0,
m=0; sgma=1;
elseif nargin == 1,
sgma=m; m=0;
end;
u=rand;
% a uniform random variable in (0,1)
z=sgma*(sqrt(2*log(1/(1-u)))); % a Rayleigh distributed random variable
u=rand;
% another uniform random variable in (0,1)
gsrv1=m+z*cos(2*pi*u);
gsrv2=m+z*sin(2*pi*u);
%*******************************************************************
%*******************************************************************
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));
%*******************************************************************
%*******************************************************************
Course Assistant: Muhammad Imadur Rahman, Phone: 09-4514905, e-mail: [email protected]
2
Bit error probability versus SNR curve is plotted here:
0
10
-1
10
-2
The error probability
10
-3
10
-4
10
-5
10
-6
10
-7
10
0
5
10
15
SNR in dB
Course Assistant: Muhammad Imadur Rahman, Phone: 09-4514905, e-mail: [email protected]
3
Related documents