📄 lmmse.m
字号:
clear all
Nc=64; % the total carriers
K=2; % the number of users
M=2; % the number of transmit antennas
N=2; % the number of receive antennas
G=64; % 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=200;
SNR_dB=4:4:12;
%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);
%TX=sqrt(Pow)*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
Perm=zeros(N,M,Nc,K);
for p=1:Nc
g=mod(p,G);
if (g==0)
g=G;
end
Gg(:,:,p)=eye(N);
for k=1:K
DecisionVector(:,p,k)=DM(:,p)*SpreadCode(k,g);
Gg(:,:,p)=Gg(:,:,p)+Pow(x)*H(:,:,p,k)*H(:,:,p,k)';
%Gg(:,:,p)=Gg(:,:,p)+Pow*H(:,:,p,k)*H(:,:,p,k)';
end
for k=1:K
for m=1:M
Power(m,p,k)=(H(:,m,p,k))'*H(:,m,p,k);
end
Permution=[];
for m=1:M
[A,L]=max(Power(:,p,k));
Permution=[Permution H(:,L,p,k)];
AntennaOrder(m,p,k)=L;
Power(L,p,k)=0;
end
Perm(:,:,p,k)=Permution;
R(:,:,p,k)=Gg(:,:,p);
for m=1:M
MMSE(m,p,k)=Pow(x)*Perm(:,m,p,k)'*inv(R(:,:,p,k))*DecisionVector(:,p,k);
Output(m,p,k)=(real(MMSE(m,p,k))>=0)-(real(MMSE(m,p,k))<0);
DecisionVector(:,p,k)=DecisionVector(:,p,k)-sqrt(Pow(x))*Perm(:,m,p,k)*Output(m,p,k);
R(:,:,p,k)=R(:,:,p,k)-Pow(x)*Perm(:,m,p,k)*Perm(:,m,p,k)';
end
% reset
for m=1:M
ResetAntenna(AntennaOrder(m,p,k),p,k)=MMSE(m,p,k);
end
end
end
% subcarrier combination
C=[];
FinalData=[];
for s=1:S
C(:,:,:)=ResetAntenna(:,(s-1)*G+1:s*G,:);
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')
%semilogy(KK,per(:),'x')
xlabel('Eb/No(dB)');
%xlabel('K');
ylabel('BER');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -