Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CDMA simulation by matlab

Status
Not open for further replies.

Aya2002

Advanced Member level 4
Joined
Dec 12, 2006
Messages
1,140
Helped
184
Reputation
376
Reaction score
117
Trophy points
1,343
Location
Iraq
Activity points
8,006
Hello Friends,

I have simulated the CDMA system by matlab. I used Walsh code of length 2^n where this number will be the number of users as well. The message will be a binary numbers randomly generated of same length for each user where the message length will be more than 2 bits (may be 2000 or more bits).

My question is:

after the summation of the coded messages, shall i use a bit mapping, i mean shall i use a baseband digital modulation such as BPSK or others before sending it to the channel?

thanks
 

Hello Friend,

Yes, its better to use baseband modulation. Are you using walsh codes in bipolar format or in boolean format?

If you are using it in bipolar format that you have an automatic BPSK modulation. If you are using it in boolean format then you'd better convert it into modulated symbols, especially if you are thinking of simulating noise in the channel (although you could use Binary Symmetric Channel to represent channel effects on boolean data)
 

    Aya2002

    Points: 2
    Helpful Answer Positive Rating
this is a sample for a Walsh of length 8:

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
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

and this is a randomly generated data for 8 users where each row is a message for a user:

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 -1 1 1
1 1 -1 -1 -1 -1 1
1 -1 -1 -1 1 -1 1
-1 1 1 1 -1 -1 1

guide me please, as this is the first time for me to simulate a CDMA.

regards
 

hello, yes of course you must modulate your data , you can see my simulation :
Code:
K = 32; 
N = 32;
x_num = 500;
%generate BPSK symbols randomly with value +1 or -1
x = bingen(x_num);
pause
%DS-SS modulate symbols with user code
UserCode = hadamard(N);          % generation de code de walsh
c = UserCode(1,: ) ;           %code column vector
y = ds_mod(c( : ) ,x );          %modulation ( i wrote a function named ds_mod wich do that we call this operation modulation or spreading.i used direc sequence of course
 
Last edited by a moderator:

    Aya2002

    Points: 2
    Helpful Answer Positive Rating
ige1986 said:
hello, yes of course you must modulate your data , you can see my simulation :
K = 32;
N = 32;
x_num = 500;
%generate BPSK symbols randomly with value +1 or -1
x = bingen(x_num);
pause
%DS-SS modulate symbols with user code
UserCode = hadamard(N); % generation de code de walsh
c = UserCode(1,: ) ; %code column vector
y = ds_mod(c( : ) ,x ); %modulation ( i wrote a function named ds_mod wich do that we call this operation modulation or spreading.i used direc sequence of course
i'm in service :D

ok my friend,

so far i used to generate the users messages as a sequences of ±1 and by default the Walsh code has the same format.

I used the kron(x,y) function to do the spreading.

now, do i have some mistake? and what is the next step?

thanks
 

Aya2002 said:
this is a sample for a Walsh of length 8:

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
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

and this is a randomly generated data for 8 users where each row is a message for a user:

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 -1 1 1
1 1 -1 -1 -1 -1 1
1 -1 -1 -1 1 -1 1
-1 1 1 1 -1 -1 1

guide me please, as this is the first time for me to simulate a CDMA.

regards

Well, your spreading code is already in bipolar format, so you have by-default BPSK modulation.

I'm in office now, I will write a tutorial for you on how to simulate CDMA and email it to you (yahoo address)

I have also developed Matlab programs for this. I'll, InshaAllah, send it tomorrow.

But this what you need to do,

1) Over sample your user data by a factor equal to spreading factor using
Code:
a = rectpulse(User1Data,SF)

2) Repeat the spreading sequence for every bit/symbol of user data using
Code:
 b = repmat(WalshCode,1,length(User1Data))

3) finally, multiply both of them to get spread signal

Important: before multiplying make sure you normalize the energy of the spreading sequence to one (unity), do this by dividing WalshCode by sqrt(SF) i.e
Code:
WalshCodeNorm = WalshCode/sqrt(SF)

I'm here you help you



Note:

I assume,
Code:
WalshCode =     
     [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
     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];
Code:
UserData =

  [  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    -1     1     1
     1     1    -1    -1    -1    -1     1
     1    -1    -1    -1     1    -1     1
    -1     1     1     1    -1    -1     1];

and
Code:
User1Data = UserData(1,:);
Walsh4User1 = WalshCodeNorm(1,:);


so, the final program looks like this (atleast a single user TX)

%%
Code:
WalshCodeNorm = WalshCode/sqrt(SF)
User1Data = UserData(1,:);
Walsh4User1 = WalshCodeNorm(1,:);

a = rectpulse(User1Data,SF)
b = repmat(Walsh4User1,1,length(User1Data));

SpreadSig = a.*b;
[/code]

Added after 2 minutes:

kron can also be used, yes
 

    Aya2002

    Points: 2
    Helpful Answer Positive Rating
Communications_Engineer said:
1) Over sample your user data by a factor equal to spreading factor using
Code:
a = rectpulse(User1Data,SF)

2) Repeat the spreading sequence for every bit/symbol of user data using
Code:
 b = repmat(WalshCode,1,length(User1Data))

3) finally, multiply both of them to get spread signal

Important: before multiplying make sure you normalize the energy of the spreading sequence to one (unity), do this by dividing WalshCode by sqrt(SF) i.e
Code:
WalshCodeNorm = WalshCode/sqrt(SF)

Thank you very much,

regarding your third step

3) finally, multiply both of them to get spread signal

in fact i did not multiplied them, :) i added them (normal mathematical summation), is this right?

thanks

Added after 1 hours 48 minutes:

right now,

I have tried the two cases (prod and sum).

1. for the prod(A) i got BER as below for SNR(db)=18:

Number of users =16
Number of Bits for each user = 400

number =

1571


ratio =

0.2455
-------------------------------------------------------------------
2. for the sum(A) i got BER as below for SNR(db)=18:

Number of users =16
Number of Bits for each user = 400

number =

0


ratio =

0

what do you see?

Added after 1 hours 11 minutes:

but i think for the sum(A) case there will be a very high Peak to average power ratio
 

with out noise your ber should be zero. any way let me get this straight you are adding walsh sequence with your user data?

or you are adding multiple spread signals?
 

    Aya2002

    Points: 2
    Helpful Answer Positive Rating
check your pm

Added after 1 hours 4 minutes:

Communications_Engineer said:
with out noise your ber should be zero. any way let me get this straight you are adding walsh sequence with your user data?

or you are adding multiple spread signals?

I am spreading the users by walsh code then the spreaded signals will be added together.

I did that, isn't correct?
 

Hi friend,
I am doing my thesis work on CDMA,

i need matlab code for implementation of CDMA.

can u please mail me the code at amarprash@gmail.com.

it will be a great help. please please do send the code.

thanks in advance.













Hello Friends,

I have simulated the CDMA system by matlab. I used Walsh code of length 2^n where this number will be the number of users as well. The message will be a binary numbers randomly generated of same length for each user where the message length will be more than 2 bits (may be 2000 or more bits).

My question is:

after the summation of the coded messages, shall i use a bit mapping, i mean shall i use a baseband digital modulation such as BPSK or others before sending it to the channel?

thanks
 

Hi
Mr. Communication Engineer, i m also trying to do the cdma simulation through matlab

kindly guide me to do the same by sending the tutorial. my id is ********
 
Last edited by a moderator:

Here you are the code. the functions are also giver here after the main code:

Code:
%% DS - CDMA (SNR-Performance)
clear all;close all;clc;
nu=input('Number of Users = ');
u=[];s=[];
ml=input('Number of bits for each user = ');
hl=2^nextpow2(nu);
% 
for k = 1:nu
    
u_binary(k,:)=randi([0 1],1,ml);

end
for k = 1:nu
    
u_BPSK(k,:)=u_binary(k,:)*2-1;

end
for n=1:nu
    s(n,:)=cdmat(u_BPSK(n,:),hl,n);
end
cd1=sum(s);
%% Oversampling
cd =rectpulse(cd1,4);
loo=0;
for SNR=0:2:8
    
    loo=loo+1;
    
    t=awgn(cd,SNR,'measured');
    
    %% Integrate and dump (downsampling)
    or=intdump(t,4);

    sr=[];
    for p=1:nu
        sr(p,:)=cdmar(or,hl,p,ml);
    end
    
    binary_rx=(sr+1)/2;
[n(loo),r(loo)]=symerr(u_BPSK,sr);
end

figure;%plot combined signals
%Tx
subplot(211);stem(cd1(1:20),'filled');
title('Combined signals (only 20 symbols');
xlabel('Index of Combined symbols');
ylabel('Magnitude');
grid;
%Rx
subplot(212);stem(or(1:20),'filled');
title('Combined noisy signals (only 20 symbols');
xlabel('Index of Combined symbols');
ylabel('Magnitude');

grid;

SNR=0:2:8;
figure; % plot the BER vs. SNR
semilogy(SNR,r,'r-x'),grid;

figure;% plot data for a randomly selected user such as user no. 1 before the BPSK mapping Tx and Rx
% Tx
subplot(211);stem(u_binary(1,1:10),'filled');grid 
xlabel('Bits index');
title('Transmitted Bits (showing only 10 bits)');
% Rx
subplot(212);stem((sr(1,1:10)+1)/2,'filled');grid 
xlabel('Bits index');
title('Received Bits (showing only 10 bits)');

figure;% plot data for a randomly selected user such as user no. 1 after the BPSK mapping Tx and Rx
% Tx
subplot(211);stem(u_BPSK(1,1:10),'filled');grid 
xlabel('Symbol index');
title('Transmitted BPSK Symbols (showing only 10 Symbol)');
% Rx
subplot(212);stem(sr(1,1:10),'filled');grid 
xlabel('Symbol index');
title('Received BPSK Symbols (showing only 10 Symbol)');



%% Code Division Multiple Access Reciever
% CDMAr - Function
% 1. (s) Input the data
% 2. (hl) Hadamard matrix length 
% 3. (cn) code number to be used for this user (row - number of H - matrix)
% 4. (ml) original message length for this user
% 4. Despread the data by multiplying s by cn.
% 6. Outpot of the function is a despread data of user cn.
% Montadar Abas Taher
% 11/03/2011
function [outcdmar]=cdmar(s,hl,cn,ml)
if cn>hl
    errordlg('The input code number must be equal or less than the Hadamard length','File Error');
end
%% Generate Hadamard Matrix of length (hl)
h=hadamard(hl);
%% Despread the input sequence
scused=ones(1,ml);


bds=kron(scused,h(cn,:));

ds=bds.*s;

rds=reshape(ds,hl,length(s)/hl);
ou=sum(rds);
t=length(ou);
en=[];
for a=1:t
    if ou(a)>1
        en(a)=1;
    else
        en(a)=-1;
    end
end
outcdmar=en;



%% Code Division Multiple Access Transmitter
% CDMAt - Function
% 1. (s) Input the data 
% Input data must be (+/- 1's) (this is a PSK modulation (BPSK))
% 2. (hl) Hadamard matrix length 
% 3. (cn) code number to be used for this user (row - number of H - matrix)
% 4. Spread the data by multiplying s by cn.
% 6. Outpot of the function is spread symbol of user cn.
% Montadar Abas Taher
% 11/03/2011
function [outcdmat]=cdmat(s,hl,cn)
if cn>hl
    errordlg('The input code number must be equal or less than the Hadamard length','File Error');
end
%% Generate Hadamard Matrix of length (hl)
h=hadamard(hl);
%% Spread the input sequence
outcdmat=kron(s,h(cn,:));


Regards

Montadar Abas Taher
 
Last edited by a moderator:

hello
could you please send me ds_mod function?
tnx
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top