CDMA MATLAB Code
This section of MATLAB source code covers CDMA MATLAB code. CDMA stands for Code Division Multiple Access.
As shown in the figure, CDMA uses codes to modulate the user data for spreading in the transmitter. The same code is used at the receiver for despreading. In actual CDMA system base station allocates different codes to different users. Only the user having the correct code can only retrieve its information back.
The block diagram covers CDMA transmitter and CDMA receiver. CDMA transmitter consists of FEC encoder(convolution encoder), BPSK modulator and spreading module. CDMA receiver consists of reverse modules of transmitter part viz. despreading, BPSK demodulator and viterbi decoder.
Following is the CDMA matlab code and BER curve. BER curve is obtained after passing the data through the AWGN.
CDMA MATLAB Code for 1 user
n1=1;
n2=14;
FFT_SIZE=256;
%CP=16;
conv_in=[];
%% Data Generator
Data_gen = randint(1,11,255)
Data_IN=dec2bin(Data_gen);
s=0;
%% BER PARAMETERS
EbNo=0:1:15;
BER = zeros(1,length(EbNo));
numPackets=15;
frmLen = 1000;
for idx = 1: length(EbNo)
for packetidx = 1 : numPackets
%% Convolution Encoder
conv_in=[];
for index =1:11
conv_in=[conv_in double(Data_IN(index,:))-48];
end
conv_in=[conv_in 0 0 0 0 0 0 0 0]; %%8 bits padding
DIN=conv_in;
trel = poly2trellis(7, [171 133]); % Define trellis.
code = convenc(conv_in,trel);
inter_out=code;
%% BPSK Data Mapping
mapper_out=mapping(inter_out',1,1);
clear inter_out;
D=mapper_out;
%% CDMA MATLAB TRANSMITTER
% encode bits and transmit
% CDMA specific parameters
C = [ -1 1 -1 1 ]; % code for the user which will be multiplied with
%data stream of the user#1 i.e.mapper_out
M = length(C); % length (number of bits) of code
Y = size(mapper_out);
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
G = zeros(I,M);
for n = 1:N
Z = zeros(I,M);
for i = 1:I
for m = 1:M
Z(i,m) = [D(n,i)*C(n,m)];
end
end
G = G + Z; %G is the data to be transmitted after IFFT
end
%% Adding AWGN
G = awgn(G./sqrt(16), EbNo(idx) , 'measured');
G = awgn(G./sqrt(16), EbNo(idx) , 'measured');
G = awgn(G./sqrt(16), EbNo(idx) , 'measured');
%% CDMA MATLAB RECEIVER
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
RECON
rx_data1=RECON;
Demap_out=demapper(rx_data1,1,1);
%%viterbi decoder
vit_out=vitdec(Demap_out,trel,7,'trunc','hard');
DOUT=vit_out;
[number,ratio] = biterr(DIN,vit_out);
error(packetidx) = biterr(DIN,vit_out);
end % End of for loop for numPackets
BER21(idx) = sum(error)/(log2(4)*numPackets*frmLen);
end
h=gcf;clf(h); grid on; hold on;
set(gca,'yscale','log','xlim',[EbNo(1), EbNo(end)],'ylim',[0 1]);
xlabel('Eb/No (dB)'); ylabel('BER'); set(h,'NumberTitle','off');
set(h,'Name','BER Results');
set(h, 'renderer', 'zbuffer'); title('CDMA alone BER PLOTS');
semilogy(EbNo(1:end),BER21(1:end),'b-*');
BER Curve
DOWNLOAD Source Code
Download CDMA MATLAB source code files.
Useful Links to MATLAB codes
Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation
Time off estimation corr
Freq off estimation corr
channel estimation
11a WLAN channel
PN sequence generation
OFDMA Tx Rx
AES DES
carrier aggregation
CCDF
FIR Filter
IIR Filter
Low Pass FIR
Viterbi decoder
CRC8 CRC32
RF and Wireless tutorials
WLAN 802.11ac 802.11ad wimax Zigbee z-wave GSM LTE UMTS Bluetooth UWB IoT satellite Antenna RADAR