⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dscdma.m

📁 此程序为DS-CDMA链路中加入基于子空间的PASTd多用户检测方法。系统中采用m序列阔频
💻 M
字号:
% Program 5-6
%
% Simulation program to realize DS-CDMA system
%
% dscdma.m
%
% Programmed by yixiongshu,2006.8.9



%----------------------preparation part -----------------------------
sr=256000.0;                            % symboll rate
ml=2;                                       % number of modulation levels
br=sr*ml;  % bit rate
nd=1000;    % number of symbol
ebno=3.5;    % Ebno
PASTdber=zeros(1,13);
PASTber=zeros(1,13);
OPASTber=zeros(1,13);
OPASTdber=zeros(1,13);
%OtherE=[0.2512 0.3162 0.3981 0.5012 0.6310 0.7943 1 1.2589 1.5849 1.9953 2.5119 3.1623 3.9811];
for Berloop=1:13
ebno=ebno+0.5
%  
%-----------------------------------------------Filter initialization-----------------
irfn=21;
IPOINT=8;
alfs=0.5;
[xh]=hrollfcoef(irfn,IPOINT,sr,alfs,1);       % Transmitting Filter
[xh2]=hrollfcoef(irfn,IPOINT,sr,alfs,0);      % Received Filter

%------------------------------ Spreading code initialization--------------------
user=4;   % number of users
%a = [1 OtherE(Berloop) OtherE(Berloop) OtherE(Berloop)];
a =[1 1 1 1];
A = diag(a);
seq=2;  % 1:m-sequence     2:Gold    3:orthogonal Gold
stage=3;
ptap1=[1 3];
ptap2=[2 3];
regi1=[1 1 1];
regi2=[1 1 1];

% ----------------------------- Generation of the spreading code --------
switch seq
    case 1
        code=mseq(stage,ptap1,regi1,user);
    case 2
        m1=mseq(stage,ptap1,regi1);
        m2=mseq(stage,ptap2,regi2);
        code=goldseq(m1,m2,user);
    case 3
        m1=mseq(stage,ptap1,regi1);
        m2=mseq(stage,ptap2,regi2);
        code=[goldseq(m1,m2,user),zeros(user,1)];
end
code=code*2-1;
clen=length(code);


% ---------------------------------- Fading initialization ---------------
rfade=1;   % Rayleigh fading  0:nothing  1:consider
itau=[0,8];   % delay time
dlvl1=[0.0,40.0];  % attenuation level
n0=[6,7];
th1=[0.0,0.0];
itnd1=[3001,4004];
now1=2;
tstp=1/sr/IPOINT/clen;  % time resolution
fd=160;
flat=1;
itnde1=nd*IPOINT*clen*30;

% ----------------------------- Start calculation -------------
nloop=1;
%for modes=4:7
ERRORsSUM=zeros(1,nd);
PASTdsERR=zeros(1,nd);
PASTsERR=zeros(1,nd);
OPASTsERR=zeros(1,nd);
OPASTdsERR=zeros(1,nd);
ERRORoSUM=zeros(1,nd);
PASTosERR=zeros(1,nd);
PASToERR=zeros(1,nd);
OPASToERR=zeros(1,nd);
OPASTdoERR=zeros(1,nd);

modes=7;
noe=0;
nod=0;


for ii=1:nloop
    
    % -------------------------- Transmitter ---------------------
    data=rand(user,nd*ml)>0.5;
    [ich,qch]=qpskmod(data,user,nd,ml);
    
    [ich1,qch1]=spread(ich,qch,code);
    
    [ich2,qch2]=compoversamp2(ich1,qch1,IPOINT);
    [ich3,qch3]=compconv2(ich2,qch2,xh);
    
    if user==1
        ich4=ich3;
        qch4=qch3;
    else
        ich4=sum((ich3'*A)');
        qch4=sum((qch3'*A)');
    end

 % -------------------------- Fading channel ------------------------
 if rfade==0
     ich5=ich4;
     qch5=qch4;
 else
     [ich5,qch5]=sefade(ich4,qch4,itau,dlvl1,th1,n0,itnd1,...
         now1,length(ich4),tstp,fd,flat);
     itnd1=itnd1+itnde1;
 end
 
 % ---------------------------------- Receiver  -----------------------------
 spow=sum(rot90(ich3.^2+qch3.^2))/nd;
 attn=sqrt(0.5*spow*sr/br*10^(-ebno/10));
% attn=sqrt(spow*10^(-ebno/10));
 
 [ich6,qch6]=comb2(ich5,qch5,attn);
 
 [ich7,qch7]=compconv2(ich6,qch6,xh2); % filter
 
 samp1=irfn*IPOINT+1;
 ich8=ich7(:,samp1:IPOINT:IPOINT*nd*clen+samp1-1);
 qch8=qch7(:,samp1:IPOINT:IPOINT*nd*clen+samp1-1);
 
 MUDmode =modes;   %1:no 2:decor 3:mmse 4:PASTd 5:PAST 6:OPAST 7:OPASTd
 
 if MUDmode>3
    [ich10 qch10 ERRORo ERRORs]=Subspacemud(ich8,qch8,MUDmode,code);
 else
 [ich9 qch9]=despread(ich8,qch8,code);
 [ich10 qch10]=mud(ich9,qch9,MUDmode,attn,A,code); 
end
 
demodata=qpskdemod(ich10,qch10,nd,ml);   % QPSK demodulation
 
 %--------------------- BER and ERRor-----------------------------
 noe2=sum(sum(abs(data(1,:)-demodata(1,:))));
 nod2=nd*ml;
 noe=noe+noe2;
 nod=nod+nod2;
 
%  fprintf('%d\t%e\n',ii,noe2/nod2);

ERRORsSUM=ERRORsSUM+ERRORs;
ERRORoSUM=ERRORoSUM+ERRORo;
end

%---------------------------ERROR--------------------------------
if MUDmode>3
switch MUDmode
    case 4
        PASTdoErr=ERRORoSUM/nloop;
        PASTdsErr=ERRORsSUM/nloop;
        PASTdber(Berloop)=noe/nod;
    case 5
        PASToErr=ERRORoSUM/nloop;
        PASTsErr=ERRORsSUM/nloop;
        PASTber(Berloop)=noe/nod;
    case 6
        OPASToErr=ERRORoSUM/nloop;
        OPASTsErr=ERRORsSUM/nloop;
        OPASTber(Berloop)=noe/nod;
    case 7
        OPASTdoErr=ERRORoSUM/nloop;
        OPASTdsErr=ERRORsSUM/nloop; 
        OPASTdber(Berloop)=noe/nod;
end
end
% ------------------------------Data file --------------------------

ber=noe/nod;
fprintf('%d/t%d\t%d\t%d\t%e\n',modes,ebno,noe,nod,ber);

fid=fopen('BER.mat','a');
fprintf(fid,'%d\t%d\t%d\t%d\t%e\n',modes,ebno,noe,nod,ber);
fclose(fid);
end

% figure;
% x=1:1:nd;
% plot(x,PASTdoErr,'-b',x,PASToErr,'-k',x,OPASToErr,'-g',x,OPASTdoErr,'-r');
% ylabel('Orthonormality Error','FontSize',11);
% figure;
% plot(x,PASTdsErr,'-b',x,PASTsErr,'-k',x,OPASTsErr,'-g',x,OPASTdsErr,'-r');
% ylabel('Subspace Error','FontSize',11);
%end
figure;
xx=4:0.5:10; %%%%%%%%%%误码率
%xx=-12:2:12;%%%%%%%%%%%%远近效应
semilogy(xx,PASTdber,'-ob',xx,PASTber,'-xk',xx,OPASTber,'-sg',xx,OPASTdber,'-*r');
ylabel('BER','FontSize',11);
xlabel('BER','FontSize',11);
grid on;

fid=fopen('BER.mat','a');
fprintf(fid,'\n');
fclose(fid);
a=0;

% --------------------------- end of file ----------------------

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -