📄 fig_ml_nearfar_gold.m
字号:
% Fig_ml_nearfar_gold
clear
N=31; % the spreading gain
SourceNum=10000; % the number of source signal
RunningTime=10; % the iteration number
userNum=10; % the total number of users
M = 1; % the number of desired user
% power=[20 30 30 30 30 40 40 40 50 50]-20; % the emitting power of all the usersr
power = zeros(1,10);
A = diag(10.^(power/20));
spreadingCode=goldcode(log2(N+1))/sqrt(N); % generate spreading code using the function goldcode
spreadingCode=spreadingCode(:,2:userNum+1);
BITS = makebinary(userNum); % here, we should list all the possible combination of the users' data
for kk = 1:5
SNR = (kk-1)*3;
for j=1:RunningTime % begin to circulation
spreadingCode = sign(randn(N,userNum))/sqrt(N);
R = spreadingCode'*spreadingCode;
noise=randn(SourceNum*N,1)/(10^(SNR/20)); % generate noise
symbol=sign(rand(userNum,SourceNum)-0.5); % generate bipolar signal
source=diag(10.^(power/20))*symbol;
SpreadedSignal=spreadingCode*source;
for i=1:SourceNum
for k = 1:userNum
temp(:,k) = source(k,i)*spreadingCode(:,k);
end
ReceivedSignal=sum(temp,2)+noise(1+(i-1)*N:i*N); % calculate the received signal, that passs the channel
r = spreadingCode'*ReceivedSignal;
b1(:,i) = jml(r,R,A,1,BITS); % run the ML detector for each iteration
end
errorratio1(j,kk) = length(find(b1(1:M,:)~=symbol(1:M,:)))/SourceNum/M; % the BER
end
end
FONTSIZE=0.315; % 单位为厘米;
LINEWIDTH_AXES=1.2;%140/42; % corresponding to 0.140mm
LINEWIDTH_WAVE=0.5;%180/42; % corresponding to 0.180mm
figNumber=figure('Name','ML no nearfar and nearfar gold code', 'Visible','on');
set(gcf,'Color','white');
semilogy(0:3:12,mean(errorratio1),'r-+','LineWidth',LINEWIDTH_WAVE)
hold on
grid on
xlabel('SNR (dB)','FontUnits','centimeters','FontName','Times New Roman','FontSize',FONTSIZE);
ylabel('BER','FontUnits','centimeters','FontName','Times New Roman','FontSize',FONTSIZE);
title('\bf ML Multiuser Detector in a Nearfar Environment (Gold Code)','Color','blue','FontUnits','centimeters','FontName','Times New Roman','FontSize',FONTSIZE*1.2);
set(gca,'XColor','blue','YColor','blue','FontUnits','centimeters','FontName','Times New Roman','FontSize',FONTSIZE,'LineWidth',LINEWIDTH_AXES);
set(figNumber,'PaperPosition',[0.634518 6.34518 20.3046*0.8 15.2284*0.8]); %Shrink the figure size
clear
N=31; % the spreading gain
SourceNum=10000; % the number of source signal
RunningTime=10; % the iteration number
userNum=10; % the total number of users
M = 1; % the number of desired user
power=[20 30 30 30 30 40 40 40 50 50]-20; % the emitting power of all the usersr
% power = zeros(1,10);
A = diag(10.^(power/20));
spreadingCode=goldcode(log2(N+1))/sqrt(N); % generate spreading code using the function goldcode
spreadingCode=spreadingCode(:,2:userNum+1);
BITS = makebinary(userNum); % here, we should list all the possible combination of the users' data
for kk = 1:5
SNR = (kk-1)*3;
for j=1:RunningTime % begin to circulation
spreadingCode = sign(randn(N,userNum))/sqrt(N);
R = spreadingCode'*spreadingCode;
noise=randn(SourceNum*N,1)/(10^(SNR/20)); % generate noise
symbol=sign(rand(userNum,SourceNum)-0.5); % generate bipolar signal
source=diag(10.^(power/20))*symbol;
SpreadedSignal=spreadingCode*source;
for i=1:SourceNum
for k = 1:userNum
temp(:,k) = source(k,i)*spreadingCode(:,k);
end
ReceivedSignal=sum(temp,2)+noise(1+(i-1)*N:i*N); % calculate the received signal, that passs the channel
r = spreadingCode'*ReceivedSignal;
b1(:,i) = jml(r,R,A,1,BITS); % run the ML detector for each iteration
end
errorratio1(j,kk) = length(find(b1(1:M,:)~=symbol(1:M,:)))/SourceNum/M; % the BER
end
end
FONTSIZE=0.315; % 单位为厘米;
LINEWIDTH_AXES=1.2;%140/42; % corresponding to 0.140mm
LINEWIDTH_WAVE=0.5;%180/42; % corresponding to 0.180mm
semilogy(0:3:12,mean(errorratio1),'b-+','LineWidth',LINEWIDTH_WAVE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -