%cdma.m
%Generating orthonormal codes
C=[1 1;-1 1];
for i=1:1:5
C=[C C;-C C];
end
C=C/8;
%Generating qpsk baseband signal
%64 samples of the code forms 1 bit duration
for i=1:1:64
R{i}=round(rand(1,10))*2-1;
I{i}=round(rand(1,10))*2-1;
end
%CDMA base band signal (Spreading)
for i=1:1:64
UD{i}=[];
end
for k=1:1:64
for i=1:1:10
UD{k}=[UD{k} (R{k}(i)+j*I{k}(i))*C(k,:)];
end
end
%Bandpass signal
BPSIGNAL=0;
fc=1;
t=0:0.01:1;
t=t(1:1:100);
for k=1:1:64
temp=[];
for l=1:1:640
temp=[temp real(UD{k}(l))*cos(2*pi*fc*t)-imag(UD{k}(l))*sin(2*pi*fc*t)];
end
BPSIGNAL=BPSIGNAL+temp;
end
%Detecting complex base pass representation from the received signal using
%coherent detection
DRE=[];
DI=[];
for i=1:1:640
temp=BPSIGNAL((i-1)*100+1:(i-1)*100+100);
DRE=[DRE sum(temp.*cos(2*pi*fc*t))];
DI=[DI sum(temp.*sin(2*pi*fc*t))];
end
figure
scatter(DRE,DI)
title('scatter diagram of the cdma signal of 64 users without additive gaussian noise' )
%Adding gaussian noise
RBANDPASS=BPSIGNAL+sqrt(0.1)*randn(1,64000);
figure
subplot(2,1,1)
plot(BPSIGNAL)
title('Band pass signal before adding noise')
subplot(2,1,2)
plot(RBANDPASS)
title('Band pass signal after addding noise')
%Detecting complex base pass representation from the received signal using
%coherent detection
NDRE=[];
NDI=[];
for i=1:1:640
temp=RBANDPASS((i-1)*100+1:(i-1)*100+100);
NDRE=[NDRE sum(temp.*cos(2*pi*fc*t))];
NDI=[NDI sum(temp.*sin(2*pi*fc*t))];
end
figure
scatter(NDRE,NDI)
title('scatter diagram of the cdma signal of 64 users with additive gaussian noise ')
RX=NDRE+j*NDI;
figure
%Despreading
for i=1:1:64
UDD{i}=[];
end
for k=1:1:64
for i=1:1:10
UDD{k}=[UDD{k} sum(RX((i-1)*64+1:1:(i-1)*64+64).*C(k,:))];
end
subplot(8,8,k)
scatter(real(UDD{k}),imag(UDD{k}))
end
figure
for i=1:1:64
subplot(8,8,i)
plot(C(i,:))
end
