📄 iterative_qr.m
字号:
clear all
Nc=64; % the total carriers
%K=1; % the number of users
M=3; % 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=1000;
%SNR_dB=0:4:28;
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);
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
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);
H1(:,:,1)=H(:,:,p,k);
[Q,R]=qr(H1(:,:,1));
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)*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
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));
DecisionVector(:,p,k)=Q'*Despread(:,p,k);
Out(M,p,k)=Out(1,p,k);
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)*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
end
% subcarrier combination
C=[];
FinalData=[];
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)');
semilogy(KK,per(:),'x')
xlabel('K');
ylabel('BER');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -