0% found this document useful (0 votes)
106 views

Code

This MATLAB function simulates multi-code multi-carrier CDMA in an AWGN channel. It takes in parameters like the number of users, modulation scheme, number of subcarriers, SNR, and number of iterations. It generates random bits for each user, maps them to symbols using the modulation scheme, spreads the symbols using orthogonal codes, transmits them over subcarriers, adds AWGN noise, performs despreading and decoding at the receiver, and returns the bit error rate and symbol error rate.

Uploaded by

minhtaiet1711
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

Code

This MATLAB function simulates multi-code multi-carrier CDMA in an AWGN channel. It takes in parameters like the number of users, modulation scheme, number of subcarriers, SNR, and number of iterations. It generates random bits for each user, maps them to symbols using the modulation scheme, spreads the symbols using orthogonal codes, transmits them over subcarriers, adds AWGN noise, performs despreading and decoding at the receiver, and returns the bit error rate and symbol error rate.

Uploaded by

minhtaiet1711
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

function F=mcawgn(code,K,M,Sub,SNR,iteration)

% Multi-code Multi-Carrier CDMA Simulator in AWGN channel

% Description

% Parameter

% K : No of Users

% M : No of sequence which we use in the G(n) sequence set = M-


ary

% N : Length of the sequence G(n) ---> We fixed this length =


255 or 256

% Sub : Number of Subcarrier frequency (Sub SHOULD BE 8 or 16)

% Using m-files : bit_gen.m, m_seq_gen.m

% ***USAGE : mccdma(code,K,M,Sub,SNR,iteration), (e.g.


mccdma(1,5,32,16,10,10000))

% X=mccdma(code,K,M,Sub,SNR,iteration) returns a
vector which is [Bit error rate, Symbol error rate].

% FYI #1 : "00000" all zero bit is mapped to 1st symbol. That


means if the

% binary value of information bits is n, then the symbol is


(n+1)th

% sequence.

% FYI #2 : In every vector [1,.....,N], 1 is the first bit and


N is the

% last bit in time domain and frequency domain

% Define the value for parameters


N = 256;

% Generate sequence set G_set, G(user,time)

G_set=[];

switch code

case {1}

G_set = hadamard(256); % Length of G = 256

case {2}

G_set_temp = gold(1); % Length of G = 255, NOT 256

G_set = [G_set_temp ones(length(G_set_temp(:,1)),1)];


% Add "1" for the last bit(256th) to the code whose length is 255

case {3}

G_set_temp = kasami(1); % Length of G = 255, NOT


256

G_set = [G_set_temp ones(length(G_set_temp(:,1)),1)];


% Add "1" for the last bit(256th) to the code whose length is 255

case {4}

p = [1 0 0 1 0 1 0 1 1]; %(1)

G_one = m_seq_gen(g,1);

for I=1:255

G_set_temp(I,:) = circshift(G_one,[0,I-1]);

end

G_set(I,:) = [G_set_temp(I,:) 1]; % Add "1" for the


last bit(256th) to the code whose length is 255

end

%Generate user specific sequence U, U(user,time)

switch Sub

case {8}
p2 = [1 1 0 1];

otherwise

p2 = [1 1 0 0 1];

Sub = 16;

end

g2 = m_seq_gen(p2,1);

for I=1:K

U_temp(I,:) = circshift(g2,[0,I-1]);

U(I,:) = [U_temp(I,:) 1];

end

%U = sign(rand(K,Sub)-.5);

U_t=[];

for i=1:K

U_t=cat(1,U_t,repmat(U(i,:),N,1));

end

E_stot = zeros(1,K);

E_btot = 0;

N = 256;

Z = zeros(K,N*Sub);

symbol_T = N*Sub;
E_btot = 0;

for itr = 1:iteration


%*********************************** iteration = symbol number
**********************************

% Generate the Tx bits & Make M-ary Symbol

No_bit=log2(M);

% Calculation the sigma for AWGN

EbNo_temp = SNR/10.;

N_temp = (N*Sub)/(10^EbNo_temp); %%%%%%%%%

sigma = sqrt(N_temp/2);

symbol = bit_gen(1,No_bit,K); % symbol(1,time,user)

symbol_temp = zeros(No_bit,K);

symbol_temp(:,:) = symbol(1,:,:);

symbol_index = bi2de(sign(symbol_temp+1)')+1;

% Select G(n) for each user depending on the information


bit(M-ary symbol),

% G(user,time)

G = G_set(symbol_index,:);

% Transmitter
% Spread in Frequency domain, X:Spreaded Signal in Freq
domain,

X = repmat(reshape(G',prod(size(G)),1),1,Sub).*U_t;

% Do IFFT operation across the rows (dimension = 2) to code


into time,

S = sqrt(Sub).*ifft(X,Sub,2);

S_t = reshape(S',symbol_T,K)';

SF_SUM = sum(S_t,1);

% AWGN, R(1,N*Sub)

R_t = SF_SUM + sigma*randn(1,symbol_T) +


j*sigma*randn(1,symbol_T);

R = reshape(R_t',Sub,N)';

% Receiver, R(sequence time index, sub-carrier index)

R_fft = 1/sqrt(Sub)*fft(R,Sub,2);

% Despread, R_desp(user,sequence time index)

for i=1:K
R_desp_temp(i,:) = (R_fft*U(i,:)'/Sub)';

end

R_desp = real(R_desp_temp);

% Detection using Matched filter for G(n),


out_mat(user,output value of matched filter for

% each G(n) sequence)

% Decode : each index = user No. , each elements = Decimal


value of maximum output sequence of

% matched value

out_mat = R_desp*G_set(1:M,:)';

[maximum,Decode] = max(out_mat');

%Decoded_bits = G_set(Decode,:);

result = Decode - symbol_index';

% Calculate the symbol error

E_symbol = sign(abs(result));

E_stot = E_stot + E_symbol;

% Calculate the bit error

Decode_t = (Decode - 1)';

E_bit_temp = sign(de2bi(Decode_t,No_bit)-0.5) -
symbol_temp';

E_bit = sign(abs(E_bit_temp));

E_btot = E_btot + sum(sum(E_bit,1),2);


end

E_avg = sum(E_stot,2);

SER = E_avg/K/iteration;

BER = E_btot/K/iteration/No_bit;

F = [BER, SER];

You might also like