Wednesday 15 May 2013

Modelling a Communication System and Bit Error Rate

In this example, we will see how we can model a simple communication channel. We will consider two cases : A simple Additive Gaussian noise channel and Rayleigh fading channel. Our signals are complex variables here which signifies both I and Q components.
Fig1: Communication System
Channel
A channel is the medium between the transmitter and receiver. The signals (for example electromagnetic waves) transmitted from the source face different materials in the medium (air, water, buildings, dust or static charges around) it may increase the signal strength or decrease it by some random factor. This is called fading and this factor is called fading variable.
It can also add some random component to the transmitted signal. We can see this as additive noise. When this component follows a Gaussian distribution we call it additive Gaussian Noise.

Signal Modelling
Let us generate a random bit stream which signifies the date need to be sent. We choose the probability of 1 occurring is 0.6. First we generate a random uniform random vector.
u=rand(1000,1)           
Now let us turn  all the elements bigger than 0.4 to 1 and rest to 0. Note that since the original vector is uniform between 0 and 1, the output vector will have 1 with 0.6 probability.
d=zeros(1000,1);
u(d>0.4)=1;
Modulation:

We can further modulate this signal using any modulation scheme. Let us choose few of modulation schemes and compare their outputs. 

a) BPSK
This means -1 denotes 0 bit and +1 denotes 1 bit. let us change all the 0s to -1 and 1s to +1. The transmitted signal can we written as
y=zeros(1000,1);
y(d==0)=-1;
y(d==1)=+1;
Note that each -1 and 1 denotes a sin pulse with phase -180 and +180 with time length equal to symbol duration . We will not consider the anolog signal which is in form concatenated sin signals. The receiver considers whole duration pulse as one and decide the phase. This requires synchronization which is not covered in this tutorial.

B) QPSK or QAM
Let us first divide the signal into I and Q data streams components. Each even numbered data bit is for Q.
dI=d(1:2:999);
dQ=d(2:2:1000);
The transmitted signal can we written as
x=zeros(500,1);x(dI==0 && dQ==0)=sqrt(1/2)*(1+1j);
x(dI==0 && dQ==1)=sqrt(1/2)*(-1+1j);
x(dI==1 && dQ==1)=sqrt(1/2)*(-1-1j);
 x(dI==1 && dQ==0)=sqrt(1/2)*(1-1j);


Channel Modeling
1. Additive gaussian Noise
Let us first consider the simple channel which just adds the Gaussian noise. noise vector is of the same dimension , one noise value for each symbol duration and each noise value  is independent of  previous
symbol. We choose the noise variance as 0.01 and mean as 0.
m=0;
s=sqrt(.01);
N=size(x);
n=m+s*rand(N);
So the output signal which is received at receiver is 
y=x+n;
2. Fading
Let us consider the fading which multiplies to the transmitted signal. As previous, here also each value is independent. We consider Rayleigh fading which means each symbol is Rayleigh distributed. .
h=sqrt(1/2)(randn(N,1)+1j*randn(N,1));
y=h*x+n; 
Receiver Model
We implement simple decoder which computes the phase of signal (as both of them are PSK) and decide upon this. For BPSK, it is equivalent to the following rule

dhat= 1 if y >0
dhat =0 if y<0

for QPSK, the rule is 
dIhat = 1 if imaginary part of y<0 otherwise dIhat=1;
dQhat = 1 if real part of y<0 otherwise dQhat=1;  

Let us implement both of these
BPSK:
dhat=zeros(1000,1);
dhat(y>0)=1;
QPSK:
dIhat=zeros(500,1);
dIhat(imag(y)<0)=1;
dQhat=zeros(500,1);
dQhat(real(y)<0)=1;
dhat=zeros(1000,1);
dhat(1:2:999)=dIhatl
dhat(2:2:1000)=dQhat;

BER performance
Now let us compare the bit error rate which is defined as the ratio of error bit to the total bits transmitted.

e=(d!=dhat);
ber=sum(e)/1000;