0% found this document useful (0 votes)
48 views3 pages

Cdma Program For N Bits Per Each User: Here 4 Bits Are Taken For Each User and Totally 4 Users

This MATLAB code simulates CDMA for 4 users, each transmitting 4 bits. It defines the data bits for each user, encoding vectors for each user, encodes the data by multiplying the bits with the codes and transmitting the combined signal. It then decodes the received signal by multiplying with each user's code and reconstructs the original data bits.

Uploaded by

Akshaya Hegde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views3 pages

Cdma Program For N Bits Per Each User: Here 4 Bits Are Taken For Each User and Totally 4 Users

This MATLAB code simulates CDMA for 4 users, each transmitting 4 bits. It defines the data bits for each user, encoding vectors for each user, encodes the data by multiplying the bits with the codes and transmitting the combined signal. It then decodes the received signal by multiplying with each user's code and reconstructs the original data bits.

Uploaded by

Akshaya Hegde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Cdma program for n bits per each user:

Here 4 bits are taken for each user and totally 4 users.

clc
close all
clear all

% CDMA Simulation for N Transmitter/Receiver Pairs

% data bit stream for each sender


D = [ -1 -1 0 1;-1 -1 0 1;-1 -1 0 1;-1 -1 0 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);
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

%D=reshape(D,1,16);
figure(1)

subplot(2,2,1);
stairs(D(1,:));
title('data 1');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,2);
stairs(D(2,:));
title('data 2');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,3);
stairs(D(3,:));
title('data 3');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,4);
stairs(D(4,:));
title('data 4');
xlim([1 5]);
ylim([-2 2]);
grid on

figure(2)

stairs(T(1,:));
grid on
xlim([1 16]);
ylim([-5 5]);
title('encoded data');

figure(3)
subplot(2,2,1);
stairs(RECON(1,:));
title('RECONSTRUCTED DATA 1');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,2);
stairs(RECON(2,:));
title('RECONSTRUCTED DATA 2');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,3);
stairs(RECON(3,:));
title('RECONSTRUCTED DATA 3');
xlim([1 5]);
ylim([-2 2]);
grid on

subplot(2,2,4);
stairs(RECON(4,:));
title('RECONSTRUCTED DATA 4');
xlim([1 5]);
ylim([-2 2]);
grid on

You might also like