You are on page 1of 2

P=64; K=6; Nd=500;

Lh=6;
L1=3*Lh; fd=round(L1/2);
dB=20; Pow=[1 ones(1,K-1)*10^(0/20)];
tao=[0 floor(rand(1,K-1)*P)];
%chargerment longcode.mat;
lcode=longcode(50000);
b=(round(rand(K,Nd))*2-1)+sqrt(-1)*(round(rand(K,Nd))*2-1); % symboles
sf=(0:1:K-1)*100; %meme code utilise par tous les utilisateurs
h=randn(K,Lh)+sqrt(-1)*randn(K,Lh); % cannaux pour les Kutilisateurs
for i=1:K, h(i,:)=h(i,:)/norm(h(i,:)); end % normalisation
Mh=zeros(L1,Lh+L1-1);
for i=1:L1,
Mh(i,i:i+Lh-1)=h(1,:);
end
% Construction du signal recu CDMA
x=lcode(1:Nd*P); x1=zeros(size(x));
for i=1:Nd, % signal utilisateur 1
x((i-1)*P+1:i*P)=b(1,i)*x((i-1)*P+1:i*P);
end
x=filter(h(1,:),1,x); % filtrage
for j=2:K % les autres utilisateur
for i=1:Nd,
x1((i-1)*P+1:i*P)=... %
Pow(j)*b(j,i)*lcode(sf(j)+(i-1)*P+1:sf(j)+i*P);
end
x1=filter(h(j,:),1,x1); % channel filtering
x(tao(j)+1:Nd*P)=x(tao(j)+1:Nd*P)+x1(1:Nd*P-tao(j)); % delai asynchrone
end
vn=randn(size(x))+sqrt(-1)*randn(size(x)); % AWGN
vn=vn/norm(vn)*10^(-dB/20)*norm(x);
SNR=20*log10(norm(x)/norm(vn))
x=x+vn;
Y=zeros(L1,Nd-3); X=zeros(L1,P);
for i=1:Nd-3
for j=1:P,
if i*P+j+fd-L1>0
X(:,P-j+1)=x(i*P+j-1+fd:-1:i*P+j+fd-L1).';
else X(1:i*P+j-1+fd,P-j+1)=x(i*P+j-1+fd:-1:1).';
end
end
u=X*lcode((i+1)*P:-1:i*P+1).'/P;
Y(:,i)=u;
% if i/100==round(i/100), i/10000, end
end

R=Y*Y'/(Nd-3);
[Ur,Sr,Vr]=svd(R);
hb1=Ur(:,1); hb1=hb1/(hb1'*Mh(:,fd)/abs(hb1'*Mh(:,fd)));
Channel_MSE=norm(hb1-Mh(:,fd)) ;% MSE
sy=hb1'*Y; % ssymboles après estimation
% performance
fh=hb1'*Mh; i=find(abs(fh)==max(abs(fh)));
sy1=sy/fh(i);
sy2=sign(real(sy1))+sqrt(-1)*sign(imag(sy1));
temp=sy2-b(1,2:Nd-2);
SER=length(find(temp~=0))/length(temp)

You might also like