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

📄 qrandml.m

📁 mimo-mc-cdma系统上行链路中分别针对单用户和多用户的不同检测算法的比较
💻 M
字号:
clear all
Nc=64;                          % the total carriers
K=4;                            % the number of users 
M=4;                            % the number of transmit antennas
N=4;                            % the number of receive antennas 
G=16;                            % the processing gain
S=Nc/G;                         % the number of signals of each group
Tc=1/1.2288e6;                  % chip duration 
Ts=Tc;                          % symbol duration
circle_times=500;
SNR_dB=0:4:36;
%KK=4:2:16;
SGMA=1;
e=zeros(1,21);

%SNR_dB=20;
%SNR=10^(SNR_dB/10);
%Pow=2*SGMA^2*SNR;
%for x=1:length(KK)
%    K=4+2*(x-1);
  
H=zeros(N,M,Nc,K);
for k=1:K
  for p=1:Nc
    for m=1:M
      for n=1:N
        H(n,m,p,k)=raylrnd(0.5)*exp(j*2*pi*rand);  
      end
    end
  end
end

for x=1:length(SNR_dB)
  SNR(x)=10^(SNR_dB(x)/10);
  Pow(x)=2*SGMA^2*SNR(x)/M;
  
  for t=1:circle_times
    TransmitSignal=rand(M,S,K);
    TransmitSignal=(TransmitSignal>=0.5)-(TransmitSignal<0.5);

    % spreading
    SpreadCode=hadamard(G);
    TS=[];
    for k=1:K
      SD=[];
      for s=1:S
        TS=TransmitSignal(:,[s*ones(1,G)],:);
        for g=1:G
          SpreadData(:,g,k)=TS(:,g,k)*SpreadCode(k,g);
        end
        SD=[SD SpreadData(:,:,k)];
      end
      SP(:,:,k)=SD;
    end

  % multicarrier modulation
    for p=1:Nc
      for k=1:K
         TX(:,p,k)=H(:,:,p,k)*SP(:,p,k);
      end
    end
    TX=sqrt(Pow(x))*ifft(TX,[],2); 

  % transmit
    AWGN=SGMA*randn(N,Nc);
    TX=sum(TX,3);
    for p=1:Nc
       RX(:,p)=TX(:,p)+AWGN(:,p);
    end

  % demodulation
    DM=fft(RX,[],2);

  % multiuser detection and V-blast detection
    for p=1:Nc
       g=mod(p,G);
       if (g==0)
         g=G;
       end
       for k=1:K
          Despread(:,p,k)=DM(:,p)*SpreadCode(k,g);
       end
       for k=1:K
          H1(:,:,1)=H(:,:,p,k);
          [Q,R]=qr(H1(:,:,1));
          DecisionVector(:,p,k)=Q'*Despread(:,p,k);
          DecisionVector1(:,p,k)=DecisionVector(:,p,k);
          Out(M,1)=DecisionVector1(M,p,k)/R(M,M);
          Output(M,1)=(Out(M,1)>=0)-(Out(M,1)<0);
          for mm=1:(M-1)
              for mmm=0:(mm-1)
                  DecisionVector1((M-mm),p,k)=DecisionVector1((M-mm),p,k)-R((M-mm),(M-mmm))*sqrt(Pow(x))*Output((M-mmm),1);
              end
              Out((M-mm),1)=DecisionVector1((M-mm),p,k)/R((M-mm),(M-mm));
              Output((M-mm),1)=(Output((M-mm),1)>=0)-(Output((M-mm),1)<0);
          end
          for m=2:M+1
              H1(:,M,m)=H1(:,1,(m-1));
              for mm=1:(M-1)
                  H1(:,mm,m)=H1(:,(mm+1),(m-1));
              end
              [Q,R]=qr(H1(:,:,m));
              DecisionVector1(:,p,k)=Q'*Despread(:,p,k);
              Out(M,m)=Out(1,(m-1));
              Output(M,m)=(Out(M,m)>=0)-(Out(M,m)<0);
              for mm=1:(M-1)
                  for mmm=0:(mm-1)
                      DecisionVector1((M-mm),p,k)=DecisionVector1((M-mm),p,k)-R((M-mm),(M-mmm))*sqrt(Pow(x))*Output((M-mmm),m);
                  end
                  Out((M-mm),m)=DecisionVector1((M-mm),p,k)/R((M-mm),(M-mm));
                  Output((M-mm),m)=(Output((M-mm),m)>=0)-(Output((M-mm),m)<0);
              end
          end
          for m=1:(M+1)
              er=DecisionVector(:,p,k)-H1(:,:,m)*sqrt(Pow(x))*Output(:,m);
              stre(m,p,k)=er'*er;
          end
          [A,J]=min(stre(:,p,k));
          Out1(:,p,k)=Out(:,m);
          Output1(:,p,k)=Output(:,m);
          for c=1:K
             if c~=k
                Despread(:,p,c)=Despread(:,p,c)-SpreadCode(c,g)*SpreadCode(k,g)*H(:,:,p,k)*sqrt(Pow(x))*Output1(:,p,k);
             end
          end
       end
    end

  % subcarrier combination
    C=[];
    FinalData=[];
    for s=1:S
       C(:,:,:)=Out1(:,(s-1)*G+1:s*G,:);
       %for m=1:M
       %   for g=1:G
       %      for k=1:K
       %         E(m,g,k)=C(m,g,k)*abs(real(C(m,g,k)));
       %      end
       %   end
       %end
       FinalData(:,s,:)=sum(C,2);
    end
    FinalData=(FinalData>=0)-(FinalData<0);

  % compute the BER
    e(x)=e(x)+0.5*sum(sum(sum(abs(TransmitSignal-FinalData))));
  end
  per(x)=e(x)/(S*M*K*circle_times);
end
hold on
semilogy(SNR_dB,per(:),'x')
xlabel('Eb/No(dB)');
%semilogy(KK,per(:),'x')
%xlabel('K');
ylabel('BER');

⌨️ 快捷键说明

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