You are on page 1of 17

Misr International University

Faculty of Engineering

Electronics and Communications Department

Fall 2023

ECE447: Communications Lab 5


Experiment Title: CDMA Modulation using Simulink and
MATLAB

Name: Rawan Ashraf 2019/13921

Instructor: Dr. Mohamed Asaad


TA: Eng. Rana Karem
Table of Contents
Table of Figures...............................................................................................................................3
MATLAB code for CDMA..............................................................................................................4
Code Output.....................................................................................................................................6
Block Diagram on SIMULINK.......................................................................................................7
Parameters........................................................................................................................................8
1. PN sequence generator.........................................................................................................8
2. M-PSK modulator.................................................................................................................9
3. M-PSK demodulator...........................................................................................................10
4. Random integer generator...................................................................................................11
5. AWGN channel...................................................................................................................12
6. Integrate and Dump............................................................................................................12
7. Error rate calculation..........................................................................................................14
Output using BERTOOL...............................................................................................................15
BERTOOL Parameters...................................................................................................................16
Conclusion.....................................................................................................................................17

2|Page
Table of Figures
Figure 1 - BER Curve for CDMA...................................................................................................7
Figure 2 - Block diagram for CDMA..............................................................................................8
Figure 3 - PN sequence generator....................................................................................................9
Figure 4 - M-PSK modulator.........................................................................................................10
Figure 5 - M-PSK Demodulator....................................................................................................11
Figure 6 - Random integer generator.............................................................................................12
Figure 7 - AWGN channel.............................................................................................................13
Figure 8 - Integrate and Dump.......................................................................................................14
Figure 9 - Error rate calculation.....................................................................................................15
Figure 10 - BER Curve using BERTOOL.....................................................................................16
Figure 11 - BERTOOL Parameters................................................................................................17

3|Page
MATLAB code for CDMA
%%---------steps-----------%%
%1- Generate data @ Tx
%2- Generate code
%3- Spreading Code (data x code)
%4- Generate Noise
%5- Add noise effect to data
%6- xcode (Despreading)
%7- Get received data @Rx
%8- compare Rx data and Tx data
%9- count errors
%10- BER = no. of errors/no. of bits

clc
clear
%generate codes hadamard --> generate matrix of nxn (all it's rows & columns are
orthogonal on each other)
%orthogonal means: the dot product of the same row is the maximum
%correlation, but the dot product of different rows is no correlation = 0
code = hadamard(8); %support up to n codes (n=8) ---> up to 8 users bec, it
generates 8 codes
%in the matrix called code choose the row number (3) and all the columns
%(:) and put it in a variable called code_user --> we selected to work on
%user no. 3
code_user = code(3,:);
N_bits = 10000; %total no. of bits generated = 10000 bits
data = rand(1,N_bits)>0.5; %generate binary random numbers 0's and 1's from 1 to
N_bits
data = 2*data-1; %convert the data from binary to polar forms 1 and -1
spread_data=[]; %creation for empty matrix to be used for concatination
%we took a very low SNR values (low signal power compared to noise power) to see the
effect of
% the noise on BER because in the normal ranges the error is almost zero
Eb_No_dB = -10:0;
%multiply by 8 because each bit is spreaded by the factor 8 (SF=8), so if
%we have 10000 bits after spreading they'll be 80000 so we must multiply
%the noise by 8 for the noise and data have the same size so, they can be
%added

noise = 1/sqrt(2)*[randn(1,N_bits*8)+j*randn(1,N_bits*8)];
for i = 1:1:length(data) %iterates for 10000 bits
out = code_user*data(i); %multiply the code of user 3 by the user
data
spread_data = [spread_data out]; %concatinate spread data and out size at
the end will be 80000
end

for ii = 1:length(Eb_N0_dB)
% Add noise effect
y = spread_data + 10^(-Eb_N0_dB(ii)/20) * noise;

% Get the real part of noise to remove complexity


m = 2 * (real(y) > 0) - 1;

4|Page
%% Data recovery
recover_data = [];

% In this for loop, restore the spread bits to their original form
for i = 1:8:length(m)
% Get every 8 bits, multiply them with the code, and represent each 8 bits as
1 bit
out1 = code_user .* m(1, i:i+7);
x = sum(out1);

% Decide whether it is 1 or -1
if x > 0
y = 1;
recover_data = [recover_data y];
else
y = -1;
recover_data = [recover_data y];
end
end

% Counting the errors


nErr(ii) = sum(abs(data - recover_data) / 2);
ber(ii) = nErr(ii) / N_bits;
end

semilogy(Eb_N0_dB, ber, 'rx-');

5|Page
Code Output

Figure 1 - BER Curve for CDMA

The semilogy plot depicts the Bit Error Rate (BER) against Signal-to-Noise Ratio (Eb/No) in a
communication system. Utilizing Hadamard codes for spreading and introducing noise, the
logarithmic scale on the y-axis enhances visibility of small BER values. A decreasing trend in
BER with increasing Eb/No signals effective data recovery, while a flat or increasing trend
indicates challenges in maintaining data integrity with higher noise levels. This plot provides
insights into the system's robustness and performance under varying signal-to-noise conditions.

6|Page
Block Diagram on SIMULINK

Figure 2 - Block diagram for CDMA

The Simulink block diagram for CDMA (Code Division Multiple Access) comprises several key
blocks to simulate the communication system. The Random Integer Generator generates binary
data, which is then converted from unipolar to bipolar using the Unipolar to Bipolar Converter.
The system employs a Bipolar to Unipolar Converter before modulating the signal using BPSK
modulation. Each user is assigned a unique code generated by the PN Sequence Generator. The
signal is then transmitted through an Additive White Gaussian Noise (AWGN) channel,
simulating real-world communication challenges. On the receiving end, the BPSK demodulator
processes the signal, followed by integration and dumping. The Sign block is used to extract sign
information. Finally, the Error Rate Calculation block assesses the system's performance, and the
results are displayed. This comprehensive block diagram allows for a detailed simulation and
analysis of CDMA communication system functionality and error performance.

7|Page
Parameters
1. PN sequence generator

Figure 3 - PN sequence generator

PN Sequence Generator: Generator polynomial defines the sequence, initial states set the
starting point, and sample time is 1/32*1000 with 1 sample per frame.

2. M-PSK modulator

8|Page
BPSK Modulator: Configured for Binary Phase Shift Keying with M-ary number set to 2.

3. M-PSK demodulator

9|Page
Figure 5 - M-PSK Demodulator

BPSK Demodulator: M-ary number set to 2 for Binary Phase Shift Keying demodulation.

4. Random integer generator

10 | P a g e
Random Integer Generator: Generates binary data with a set size of 2, sample time of 1/1000,
and 1 sample per frame.

5. AWGN channel

Figure 7 - AWGN channel

11 | P a g e
AWGN Channel: Simulates channel noise with Eb/No values ranging from -12 dB to -2 dB, 1
bit per symbol, and 32 samples per symbol.

6. Integrate and Dump

12 | P a g e
Figure 8 - Integrate and Dump
Integrate and Dump: Performs integration and dumping over every 32 samples.

7. Error rate calculation

13 | P a g e
Error Rate Calculation: Configured with a receive delay of 1 and output data sent to a port for
error rate calculation.

Output using BERTOOL

14 | P a g e

Figure 10 - BER Curve using BERTOOL


The curve provides insights into its compatibility with varying signal-to-noise ratios, a crucial
factor for understanding the robustness of the CDMA setup. The analysis of the Bit Error Rate
(BER) curve, generated using BERTOOL with CDMA parameters from Simulink, helps assess
how well the system performs under different levels of noise, providing valuable information
about its ability to maintain data integrity and reliability.

BERTOOL Parameters

15 | P a g e
Figure 11 - BERTOOL Parameters

The Bit Error Rate (BER) curve, generated using BERTOOL with CDMA parameters from
Simulink, depicts the performance of the communication system across a range of Eb/No values
(-12 dB to -2 dB).

16 | P a g e
Conclusion

The BER curve is a vital metric for evaluating the quality of communication systems. A
descending BER curve with increasing Eb/No suggests improved performance in the presence of
noise, indicating effective error correction. Conversely, a flat or ascending curve may signify
challenges in maintaining data integrity. The detailed analysis of the BER curve obtained from
BERTOOL assists in optimizing CDMA parameters for reliable communication under different
signal conditions.

17 | P a g e

You might also like