📄 simulation_capacity_users.m
字号:
function [SNR] = simulation_capacity_users
% Shows the BER as a function of the number of users in the system
% AWGN channel
% single path
SNR = 8;
N = 16; % the length of spread code
T = 50000;
alpha = 1;
SNR_dec = 10.^(SNR / 10);
Matcodes = no_orth_spreadcode(N);%非正交的
% C1=C1(:,1:K);
ku = 1;
% Matched filter
k=1;
for K=1:2:15 %K is the number of users
%A=floor((0:(K-1))*5/K)+1;% what
A=ones(K,1)*alpha;
A=A*ones(1,T);%vector(1,5000)
Aavg = sum(A.^2,2)/T;%
C = Matcodes(:,1:K);
Eb = C(:,ku)' * C(:,ku)*Aavg(ku);
mf = C(:,ku);
disp('loop');
sigma = Eb/SNR_dec(k)/2;
Sentbit = sign(randn(K,T));
Y=C*(A.*Sentbit) + sqrt(sigma)*randn(N,T);
% matched
Receivedbit1 = sign(mf'*Y);
Perr1(K) = sum(abs(Receivedbit1-Sentbit(ku,:)))/2/T;
% decorrelator
Receivedbit2 = sign(inv(C'*C)*C'*Y);
Perr2(K) = sum(abs(Receivedbit2(ku,:)-Sentbit(ku,:)))/2/T;
% MMSE
Receivedbit3 = sign(inv(C'*C+sigma*diag(1./Aavg))*C'*Y);
Perr3(K) = sum(abs(Receivedbit3(ku,:)-Sentbit(ku,:)))/2/T;
% SIC 逐级干扰对消(串行)
Z=C'*Y;
for j=K:-1:1
Z2=Z(j,:);
sent_bit=sign(Z2);
R=C'*C;
Z = Z - R(:,j)*(A(j,:).*sent_bit);%abs(Z2)
Receivedbit4(j,:)=sent_bit;
end
Perr4(K) = sum(abs(Receivedbit4(ku,:)-Sentbit(ku,:)))/2/T;
% DFD 决策反馈
F=chol(C'*C);
Finv=inv(F');
Yfb = Finv*C'*Y;
for j=K:-1:1
sent_bit=sign(Yfb(j,:));
Yfb=Yfb-F(:,j)*(A(j,:).*sent_bit);%abs(Yfb(j,:))
Receivedbit5(j,:)=sent_bit;
end
Perr5(K) = sum(abs(Receivedbit5(ku,:)-Sentbit(ku,:)))/2/T;
% PIC(并行)
Z3=inv(C'*C)*C'*Y;
Receivedbit6 = sign(Z3);% decorrelator
B=C'*C-triu(tril(C'*C));%去除对角上的元素,留下的是可认为是相互干扰的成分
Z3=C'*Y-B*(A.*Receivedbit6);
%vector ones(1,5000)
%triu(tril(Z3))
Receivedbit6 = sign(Z3);
Perr6(K) = sum(abs(Receivedbit6(ku,:)-Sentbit(ku,:)))/2/T;
end
if (nargout==0)
semilogy(1:2:15, Perr1(1:2:15), 'bx-');hold on;
xlabel('number of users');
ylabel('BER');
semilogy(1:2:15, Perr2(1:2:15), 'ro-');hold on;
semilogy(1:2:15, Perr3(1:2:15), 'm+-');hold on;
semilogy(1:2:15, Perr4(1:2:15), 'k*-');hold on;
semilogy(1:2:15, Perr5(1:2:15), 'cs-');hold on;
semilogy(1:2:15, Perr6(1:2:15), 'bv-');hold on;
hold on;
legend('Matched filter', 'Decorrelator','MMSE','SIC','DFD','PIC')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [codeMatrix] = no_orth_spreadcode(SF)
% This function returns a matrix whose lignes are code vectors. These codes are
% not orthonormal
C1=hadamard(SF); % Generates a matrix with orthogonal vectors
C2=sign(randn(SF,1)); % Generates a cell code to ensure spreading
C3=diag(C2)*C1/sqrt(SF); % Matrix normalized
C4=(rand(SF,SF)-.5)/3; % Generates a noise matrix
codeMatrix = C4+C3; % Sums the code and the noise to have non-orthogonal codes
%end function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -