📄 qr_decompose.m
字号:
clear all
Nc=32; % the total carriers
K=4; % the number of users
M=4; % the number of transmit antennas
N=4; % the number of receive antennas
G=8; % 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=1000;
SNR_dB=0:20;
% SNR_dB=20;
SGMA=1;
e=zeros(1,21);
%SNR=10^(SNR_dB/10);
%Pow=2*SGMA^2*SNR;
%for x=1:5
% K=K+6;
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);
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=8;
end
for k=1:K
Despread(:,p,k)=DM(:,p)*SpreadCode(k,g);
[Q,R]=qr(H(:,:,p,k));
DecisionVector(:,p,k)=Q'*Despread(:,p,k);
Out(M,p,k)=DecisionVector(M,p,k)/R(M,M);
Output(M,p,k)=(Out(M,p,k)>=0)-(Out(M,p,k)<0);
for m=1:(M-1)
for mm=0:(m-1)
DecisionVector((M-m),p,k)=DecisionVector((M-m),p,k)-R((M-m),(M-mm))*sqrt(Pow(x))*Output((M-mm),p,k);
end
Out((M-m),p,k)=DecisionVector((M-m),p,k)/R((M-m),(M-m));
Output((M-m),p,k)=(Output((M-m),p,k)>=0)-(Output((M-m),p,k)<0);
end
end
end
% subcarrier combination
for s=1:S
C(:,:,:)=Out(:,(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)');
ylabel('BER');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -