You are on page 1of 9

International Islamic University

Islamabad

Wireless Communication LAB

Experiment No. 11: CDMA implementation using MATLAB

Name: __________________________________________

Roll No.: ________________________________________

Lab conducted on: ________________________________

Report submitted on:______________________________

Marks Obtained: ___________________________________

Remarks: _________________________________________

Instructor’s Signature:_______________________________
Wireless Communication Lab.

Objective: To Study and Implement Coded Division Multiple Access?

Code Division Multiple Access


Code Division Multiple Access (CDMA) is a spread spectrum technique that uses neither frequency
channels nor time slots. With CDMA, the narrow band message (typically digitised voice data) is multiplied
by a large bandwidth signal that is a pseudo random noise code (PN code). All users in a CDMA system
use the same frequency band and transmit simultaneously. The transmitted signal is recovered by
correlating the received signal with the PN code used by the transmitter. Figure shows the general use of
the spectrum using CDMA.

CDMA technology was originally developed by the military during World War II. Researchers were
spurred into looking at ways of communicating that would be secure and work in the presence of jamming.
Some of the properties that have made CDMA useful are:
· Signal hiding and non-interference with existing systems.
· Anti-jam and interference rejection
· Information security
· Accurate Ranging
· Multiple User Access
· Multipath tolerance

For many years, spread spectrum technology was considered solely for military applications. However,
with rapid developments in LSI and VLSI designs, commercial systems are starting to be used.
CDMA Generation
CDMA is achieved by modulating the data signal by a pseudo random noise sequence (PN code), which
has a chip rate higher than the bit rate of the data. The PN code sequence is a sequence of ones and zeros
(called chips), which alternate in a random fashion. Modulating the data with this PN sequence generates
the CDMA signal. The CDMA signal is generated by modulating the data by the PN sequence. The
modulation is performed by multiplying the data (XOR operator for binary signals) with the PN sequence.
Figure shows a basic CDMA transmitter.

International Islamic University, Islamabad. 87


Wireless Communication Lab.

The PN code used to spread the data can be of two main types. A short PN code (typically 10-128 chips in
length) can be used to modulate each data bit. The short PN code is then repeated for every data bit allowing
for quick and simple synchronization of the receiver. Figure 13 shows the generation of a CDMA signal
using a 10-chip length short code. Alternatively a long PN code can be used. Long codes are generally
thousands to millions of chips in length, thus are only repeated infrequently. Because of this they are useful
for added security as they are more difficult to decode.

CDMA Forward Link Encoding


The forward link, from the base station to the mobile, of a CDMA system can use special orthogonal PN
codes, called Walsh codes, for separating the multiple users on the same channel. These are based on a
Walsh matrix, which is a square matrix with binary elements and dimensions that are a power of two. It is
generated from the basis that Walsh(1) = W1 = 0 and that:

Where Wn is the Walsh matrix of dimension n. For example:

International Islamic University, Islamabad. 88


Wireless Communication Lab.

Walsh codes are orthogonal, which means that the dot product of any two rows is zero. This is due to the
fact that for any two rows exactly half the number of bits match and half do not.
Each row of a Walsh matrix can be used as the PN code of a user in a CDMA system. By doing this the
signals from each user is orthogonal to every other user, resulting in no interference between the signals.
However, in order for Walsh codes to work the transmitted chips from all users must be synchronized. If
the Walsh code used by one user is shifted in time by more than about 1/10 of chip period, with respect to
all the other Walsh codes, it looses its orthogonal nature resulting in inter-user interference. This is not a
problem for the forward link as signals for all the users originate from the base station, ensuring that all the
signal remain synchronized.
CDMA Reverse Link Encoding
The reverse link is different to the forward link because the signals from each user do not originate from a
same source as in the forward link. The transmission from each user will arrive at a different time, due to
propagation delay, and synchronization errors. Due to the unavoidable timing errors between the users,
there is little point in using Walsh codes as they will no longer be orthogonal. For this reason, simple pseudo
random sequences are typically used. These sequences are chosen to have a low cross correlation to
minimize interference between users.
The capacity is different for the forward and the reverse links because of the differences in modulation. The
reverse link is not orthogonal, resulting in significant inter-user interference. For this reason the reverse
channel sets the capacity of the system.
CDMA Encoding and Decoding Mechanism
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CDMA coding and decoding mechanism
clc
clear
% Generation of Random Bits
r=round(rand(1,20));
% Chip Pattern for station A, B and C
a_one=[1 -1 -1 1 -1 1];
a_zero=-1*a_one;
b_one=[1 1 -1 -1 1 1];
b_zero=-1*b_one;
c_one=[1 1 -1 1 1 -1];
c_zero=-1*c_one;
% Random Allotment of bits to stations A,B and C
cdma_seq=[];

International Islamic University, Islamabad. 89


Wireless Communication Lab.

for counter=1:20
switch(randint(1,1,[1 3]))
case(1)
if r(1,counter)==0;
cdma_seq=[cdma_seq a_zero];
else
cdma_seq=[cdma_seq a_one];
end
case(2)
if r(1,counter)==0;
cdma_seq=[cdma_seq b_zero];
else
cdma_seq=[cdma_seq b_one];
end
case(3)
if r(1,counter)==0;
cdma_seq=[cdma_seq c_zero];
else
cdma_seq=[cdma_seq c_one];
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Decoding the Signal
cntr=0;
for selector=1:6:120
cntr=cntr+1;
temp=[cdma_seq(1,selector) cdma_seq(1,selector+1) cdma_seq(1,selector+2)
...
cdma_seq(1,selector+3) cdma_seq(1,selector+4)
cdma_seq(1,selector+5)];
result1=dot(a_one,temp);
result2=dot(b_one,temp);
result3=dot(c_one,temp);
if (result1==6)|(result1==-6)
fprintf('\nThe bit # %d is from Station A',cntr);
else
if (result2==6)|(result2==-6)

International Islamic University, Islamabad. 90


Wireless Communication Lab.

fprintf('\nThe bit # %d is from Station B',cntr);


else
if (result3==6)|(result3==-6)
fprintf('\nThe bit # %d is from Station C',cntr);
end
end
end
end

CDMA Implementation with Walsh codes


% CDMA Simulation for N Transmitter/Receiver Pairs
% data bit stream for each sender
clc
clear all
D = [ 1 -1 1 -1 1 1 -1 -1 ;
-1 -1 1 1 1 -1 -1 1 ;
1 1 -1 -1 -1 1 1 -1 ;
1 1 1 1 -1 -1 -1 -1 ];
% unique code for each sender (determined using the Walsh Set)
C = [ -1 -1 -1 -1 ;
-1 1 -1 1 ;
-1 -1 1 1 ;
-1 1 1 -1 ];
% parameters
M = length(C); % length (number of bits) of code
Y = size(D);
N = Y(1); % number of unique senders / bit streams
I = Y(2); % number of bits per stream
T = []; % sum of all transmitted and encoded data on channel
RECON = []; % vector of reconstructed bits at receiver
% show data bits and codes
'Vector of data bits to be transmitted:', D
'Vector of codes used for transmission:', C
% encode bits and transmit
G = zeros(I,M);
for n = 1:N
Z = zeros(I,M);

International Islamic University, Islamabad. 91


Wireless Communication Lab.

for i = 1:I
for m = 1:M
Z(i,m) = [D(n,i)*C(n,m)];
end
end
G = G + Z;
end
% show channel traffic
for i = 1:I
T = [ T G(i,:) ];
end
'Resulting traffic on the channel:', T
% decode and reconstruct
for n = 1:N
TOT = zeros(1,I);
R = zeros(I,M);
for i = 1:I
for m = 1:M
R(i,m) = G(i,m) * C (n,m);
TOT(i) = TOT(i) + R (i,m);
end
end
RECON = [RECON ; TOT / M];
end
'Reconstructed data at the receiver:'
RECON

Detailed Example of CDMA Transmission


Example
Always remember write +1 for data = 1 and write -1 for data = -1
1) Sender (A’s) data A = 1 this shows Bipolar A = +1 and Sender (B’s) data B = 0 this
shows Bipolar B = -1
2) A Chip code is 0 0 1 1 0 0 1 1 this Shows -1 -1 +1 +1 -1-1 +1 +1 and B Chip code is 0 1 1 0 0 1 1
0 this Shows-1+1 +1 -1 -1 +1 +1 -1
3) Encoding ( Spread ) A data:- A =1 * (-1 -1 +1 +1 -1 -1 +1 +1) = (-1 -1 +1 +1 -1 -1 +1 +1) This mean
when data is 1 transmit chipping code as it is and Encoding ( Spread ) B data: Bs = -1 * (-1 +1 +1 -1 -
1 +1 +1 -1) = (+1 -1 -1 +1 +1 -1 -1 +1) This mean when data is -1 transmit Inverse of chipping code
as it is.

International Islamic University, Islamabad. 92


Wireless Communication Lab.

4) Now calculate sum of A data + B data and Sum( C ) = A + B = (0 -2 0 2 0 -2 0 2)


5) Decode ( Recover ) Received Signal at receiver is C ( Recieved Sigal ) * ( Chipping code of A ) = (0
-2 0 2 0 -2 0 2) * (-1 -1 +1 +1 -1-1 +1 +1) = (0 2 0 2 0 2 0 2)
If Sum = 8 > 0 hence A transmitted data was A=1
6) Decode ( Recover ) Received signal Cs C ( Recieved Sigal ) * ( Chipping code of B ) = (0 -2 0 2 0 -2
0 2) * (-1 +1 +1 -1 -1 +1 +1 -1) = (0 -2 0 -2 0 -2 0 -2) and Sum = -8 < 0 hence B transmitted data was B =
0
A Mean A-Data and B Mean B-Data
Algorithm
1) Define sender A data: then Convert into bipolar or directly define in bipolar.
2) Define sender A data: then Convert into bipolar or directly define in bipolar.
4) Define PN sequence Code of A and then Convert into bipolar.
5) Define PN sequence Code of A and then Convert into bipolar.
6) Encode ( Spread ) A data : A( E ) = A(Data) * code A[ ].
7) Encode ( Spread ) B data : B ( E ) = B(Data) * code B[ ].
8) Add A(E) and B(E) : c[ ] = A(E) + B(E).
9) Decode ( Despread ) A data signals. Final Result Decoding using Chipping code A …….. A [ ] =
c[ ] * code A[ ]. Add all values(Array) of Result A[ ]. If finally sum > 0 then the A transmitted data is 1
else is 0.
10) (DeCrypt ) De spread B signals. Result B [ ] = c[ ] * code B[ ]. Add values of Result B[ ]
If sum > 0 then A’s transmitted data is 1 else 0.
Now Implementing CDMA in MATLAB by using following symbols as inputs:-
Signal A: 1 1 0 1 0 0 1 1 0
Signal B: 0 1 0 0 1 1 0 1 1
Chip code for Signal A is: 0 1 0 1
Chip Code for Signal B is: 1 0 1 0
Encoding the Signal A and B using these chip codes.
At the receiver end signals are decoded back into original message and observe what happens when a
signal gets corrupted.

MATLAB Code
A =[ 1 -1 -1 1 -1 -1 1 -1 -1 ];
B =[ -1 1 -1 -1 1 1 -1 1 1 ];
CA = [ -1 1 -1 1];
CB = [ 1 -1 1 -1];
CC= [ 1 1 -1 -1 ];
encodeA=[];
j=1;

International Islamic University, Islamabad. 93


Wireless Communication Lab.

for i=1:length(A)
if(A(i)==1)
encodeA(i,:)=CA;
else
encodeA(i,:)=-1.*CA;
end
if(B(i)==1)
encodeB(i,:)=CB;
else
encodeB(i,:)=-1.*CB;
end
end

disp('Encoding Message')
encode = encodeA+encodeB
disp('Decoding Message')
for i=1:length(A)
decode(i,:) = CA .* encode(i,:);
decodeB(i,:)= CB .* encode(i,:);
decodeC(i,:) = CC .* encode(i,:);
if (sum(decode(i,:))>0)
signalA(i)=1;
else
signalA(i)=-1;
end
if (sum(decodeB(i,:))>0)
signalB(i)=1;
else
signalB(i)=-1;
end
if (sum(decodeC(i,:))>0)
signalC(i)=1;
else
signalC(i)=-1;
end
end
A
signalA
B
signalB
disp('decodeing with chiping code C')
signalC

International Islamic University, Islamabad. 94

You might also like