Skip to content

Commit

Permalink
Fix many bugs - synchronize with this commit for main/main_runnable
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosbg1991 committed May 15, 2019
1 parent 154a481 commit af408b0
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 121 deletions.
22 changes: 22 additions & 0 deletions TESTING/test_SINR_comparison.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
clear all; close all; clc;

addpath('UTILITIES','-end'); % Add utilities folder at the end of search path
addpath('../data','-end'); % Add data folder at the end of search path

% load('TABLE-SNR-loc4.mat','SINRLCMV','SINRCBF','SINRHEU','nAntennasList','nUsersList');
load('TABLE-SNR-loc4-v2.mat','SINRLCMV','SINRCBF','SINRHEU','nAntennasList','nUsersList');

improve = SINRHEU - SINRLCMV;

figure; hold on;
leg = cell(10,1);
for i = 1:10
plot(1:length(nAntennasList),improve(i,:),'linewidth',1.5);
leg(i) = strcat(num2str(i),{' '},'users');
end
nAntennasList = {'12^2','14^2','16^2','18^2','20^2','22^2'};
legend(leg);
xticklabels(nAntennasList);
ylabel('improvement (dB)');
xlabel('Array size');
grid minor;
20 changes: 10 additions & 10 deletions TESTING/test_conventionalBF2.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
clear; close all; clc;
clear; close all; clc;
addpath('../UTILITIES','-end'); % Add utilities folder at the end of search path
addpath('../code-systems','-end'); % Add system's folder at the end of search path
addpath('../code-beamforming','-end'); % Add beamforming folder at the end of search path
Expand All @@ -8,15 +8,15 @@
problem = o_read_input_problem('metaproblem_test.dat');
conf = o_read_config('config_test.dat');
%% Input parameters
maxIter = 1; % Maximum number of iterations
configList = -1; % antenna configuration (distribution across users) (-1 for random asignation)
problem.N_Antennas = 8.^2; % Number of antennas
nUserList = [1 2 4 8]; % Number of users to iterate over
candSet = (1:1:problem.nUsers); % Subset to be allocated antennas
conf.detLocation = false;
conf.useCaseLocation = false;
conf.useCaseLocation = 1; % Use-case location ID
conf.verbosity = 1; % Use-case location ID
maxIter = 1; % Maximum number of iterations
configList = -1; % antenna configuration (distribution across users) (-1 for random asignation)
problem.N_Antennas = 8.^2; % Number of antennas
nUserList = [1 2 4 8]; % Number of users to iterate over
candSet = (1:1:problem.nUsers); % Subset to be allocated antennas
conf.detLocation = true;
conf.useCasesLocation = true;
conf.useCaseLocation = 3; % Use-case location ID
conf.verbosity = 0; % Use-case location ID
%% Output parameters
Cap_LCMV_tot = zeros(length(configList),1);
Cap_CBF_tot = zeros(length(configList),1);
Expand Down
2 changes: 1 addition & 1 deletion TESTING/test_myFirstScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%% Input parameters
problem.N_Antennas = 8.^2; % Number of antennas
problem.nUsers = 4; % Number of users
candSet = (1:1:problem.nUsers); % Users to be considered for antenna alloc.
candSet = (1:1:problem.nUsers); % Users to be considered for antenna alloc.
conf.detLocation = false; % true to use preconfigured locations, false for random
conf.useCaseLocation = false; % if detLocation is true, retrieve locations
conf.useCaseLocation = 1; % Use-case location ID
Expand Down
8 changes: 5 additions & 3 deletions code-beamforming/CBG_CA_Position_Objective_optim_ga.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
% not be assigned because parent 1 already assigned them)
[~,idx] = find(child==0);
if ~isempty(idx)
% Shuffle list
% Shuffle listpossible_locations
newTotUsers = totUsers(randperm(length(totUsers)));
child(idx) = newTotUsers;
end
Expand All @@ -139,11 +139,13 @@
mutationChildren = zeros(nMutateKids,nvars);

nAntennas = sum(problem.NmaxArray);
nParents = length(parents);

% Antenna swapping array
swap = ceil(nAntennas * rand(nAntennas,2));
% swap = ceil(nAntennas * rand(nAntennas,2)); % potential bug -erase
swap = ceil(nAntennas * rand(nParents,2));

for i=1:length(parents)
for i=1:nParents
% Initialize before making changes
parent = thisPopulation(parents(i),:);
child = parent;
Expand Down
49 changes: 24 additions & 25 deletions code-beamforming/CBG_creationArrayGA.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,32 @@
% See also: CBG_solveit

%------------- BEGIN CODE --------------
antPerUser = problem.NmaxArray;
availableAnt = (1:1:problem.N_Antennas);
availableAnt1 = availableAnt;
assignation = zeros(1,problem.N_Antennas);
if isfield(problem,'initialW')
% Initial gene configuration
for id = 1:problem.nUsers
% Select relevant indices
antennaSelected = (problem.initialW(id,:)~=0);
% Allocate those to designated user
assignation(antennaSelected) = id;
end
else
% Initial gene configuration
for id = 1:problem.nUsers
% Select antenna indices to be allocated to selected user
antennaSelected = randsample(availableAnt1,antPerUser(id));
% Update gene with those indices
assignation(antennaSelected) = id;
% Remove selected antennas from active set
availableAnt1 = setdiff(availableAnt1,antennaSelected);
end
antPerUser = problem.NmaxArray;
availableAnt = (1:1:problem.N_Antennas);
availableAnt1 = availableAnt;
assignation = zeros(1,problem.N_Antennas);
if isfield(problem,'initialW')
% Initial gene configuration
for id = 1:problem.nUsers
% Select relevant indices
antennaSelected = (problem.initialW(id,:)~=0);
% Allocate those to designated user
assignation(antennaSelected) = id;
end
else
% Initial gene configuration
for id = 1:problem.nUsers
% Select antenna indices to be allocated to selected user
antennaSelected = randsample(availableAnt1,antPerUser(id));
% Update gene with those indices
assignation(antennaSelected) = id;
% Remove selected antennas from active set
availableAnt1 = setdiff(availableAnt1,antennaSelected);
end
myGene = [availableAnt , assignation];
InitialPopulation = repmat(myGene,conf.PopulationSize_Data,1);
end
myGene = [availableAnt , assignation];
InitialPopulation = repmat(myGene,conf.PopulationSize_Data,1);




% EOF
14 changes: 7 additions & 7 deletions code-beamforming/CBG_solveit.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function [sol_found,W,handle_ConformalArray,PRx,I,bestScores] = CBG_solveit(problem,conf,usersToBeAssigned)
function [sol_found,W,handle_ConformalArray,PRx,I,bestScores] = CBG_solveit(problem,conf,candSet)
% CBG_solveit - Main PHY script that finds the optimal solution for HELB
% (see submited paper for further description), given the mmWave sub-array
% restrictions, the number of users, their channels and the demanded SNR
% per application.
%
% Syntax: [sol_found,W,handle_ConformalArray,PRx,I,bestScores] = ...
% CBG_solveit(problem,conf,usersToBeAssigned)
% CBG_solveit(problem,conf,candSet)
%
% Inputs:
% problem - struct containint configuration in data/metaproblem_test.dat
% conf - struct containint configuration in data/config_test.dat
% usersToBeAssigned - Vector containing the users IDs
% candSet - Vector containing the users IDs
%
% Outputs:
% sol_found - flag indicating whether the solution was found
Expand All @@ -34,8 +34,8 @@
sol_found = true;

% Localize variables
problem.nUsers = length(usersToBeAssigned);
problem.candSet = usersToBeAssigned;
problem.nUsers = length(candSet);
problem.candSet = candSet;

% Create subarray partition
problem = o_create_subarray_partition(problem);
Expand All @@ -45,14 +45,14 @@
% Create the antenna handler and the data structure with all possible pos.
problem.handle_Ant = phased.CosineAntennaElement('FrequencyRange',...
[problem.freq-(problem.Bw/2) problem.freq+(problem.Bw/2)],...
'CosinePower',[1.5 2.5]); % [1.5 2.5] values set porque s�
'CosinePower',[1.5 2.5]); % [1.5 2.5] values set porque si
handle_ConformalArray = phased.URA([problem.NyPatch,problem.NzPatch],...
'Lattice','Rectangular','Element',problem.handle_Ant,...
'ElementSpacing',[problem.dy,problem.dz]);
problem.possible_locations = handle_ConformalArray.getElementPosition;

% Allocate number of antennas to users (QoS)
problem = o_compute_antennas_per_user(problem,usersToBeAssigned);
problem = o_compute_antennas_per_user(problem,candSet);

if conf.verbosity >= 1
fprintf('We distribute %d antennas amongst users\n',problem.N_Antennas)
Expand Down
7 changes: 5 additions & 2 deletions code-beamforming/o_generate_5Gchannels.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
thetaChannels = ones(nUsers,maxnChannelPaths)*NaN;
phiChannels = ones(nUsers,maxnChannelPaths)*NaN;
alphaChannels = ones(nUsers,maxnChannelPaths)*NaN;
MatlabRelease = version('-release');
for u=1:nUsers
ZOD_LOS = thetaUsers(u);
AOD_LOS = phiUsers(u);
% cdlChan = nr5gCDLChannel;
cdlChan = nrCDLChannel;
if strcmp(MatlabRelease,'2018a'); cdlChan = nr5gCDLChannel;
elseif strcmp(MatlabRelease,'2018b'); cdlChan = nrCDLChannel;
else; error('Need either Matlab R2018a or R2018b');
end
cdlChan.SampleRate = 1760e6 / 1; %% SC-1760e6 sa/s, OFDM 2640e6 sa/s
cdlChan.TransmitAntennaArray.Size = [NxPatch, NyPatch, 1, 1, 1];
cdlChan.ReceiveAntennaArray.Size = [1, 1, 1, 1, 1];
Expand Down
1 change: 1 addition & 0 deletions code-beamforming/o_read_input_problem.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
struct('name','Tsym','type','float');
struct('name','targetPER','type','float');
struct('name','BFalgorithm','type','char');
struct('name','refine','type','char');
struct('name','loadTraffic','type','bool');
struct('name','deadline','type','int');
};
Expand Down
2 changes: 1 addition & 1 deletion code-systems/f_BF_results.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
% Output parameters
DirOK = -Inf(nUsers,1); % Directivity target (heuristics)
DirNOK = -Inf(nUsers,nUsers); % Directivity others (heuristics)

% Antenna location in the array
possible_locations = handle_ConformalArray.getElementPosition;

Expand Down
2 changes: 1 addition & 1 deletion code-systems/f_arrivalToFlow.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
valor.success(pkt) = 0;
end
flows(id) = valor;
maxSlot = max(maxSlot,max(flows(id).deadlines)+1);
maxSlot = max(maxSlot,max(flows(id).deadlines)+5);
end


Expand Down
8 changes: 7 additions & 1 deletion code-systems/f_configuration.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
% traffic - todo
% flows - Array of structs of length equal to the number of
% users. For each user, each flow (belonging to each packet) is
% characterized by the amount of bits that needs to be delivered. The
% characterized by the amount of bits that needs to be delivered. The
% amount of bits are distributed uniformly across the slots until
% reaching the deadline. Thus, the variable flows contains four features:
% - slots: For each flow, the slots across it.
Expand Down Expand Up @@ -70,8 +70,14 @@
problem.MCSPER = mcsTable;
% Load the SNR table for faster execution
load('TABLE-SNR-loc4.mat','SINRLCMV','SINRCBF','SINRHEU','nAntennasList','nUsersList');
% load('TABLE-SNR-loc4-v2.mat','SINRLCMV','SINRCBF','SINRHEU','nAntennasList','nUsersList');
[~,idxUsr] = min(abs(problem.nUsers - nUsersList));
[~,idxAnt] = min(abs(problem.N_Antennas - nAntennasList));
% Temporal - cause longer distances, higher attenuation
correction = 25;
SINRCBF = SINRCBF - correction;
SINRLCMV = SINRLCMV - correction;
SINRHEU = SINRHEU - correction;
problem.SINR_CBF = db2pow(SINRCBF(idxUsr,idxAnt)); % in linear scale
problem.SINR_LCMV = db2pow(SINRLCMV(idxUsr,idxAnt)); % in linear scale
problem.SINR_HEU = db2pow(SINRHEU(idxUsr,idxAnt)); % in linear scale
Expand Down
69 changes: 60 additions & 9 deletions code-systems/f_conventionalBF.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [W_LCMV,W_CBF,handle_ConformalArray,estObj_LCMV,estObj_CBF,candSet] = f_conventionalBF(problem,conf,candSet)
function [W_LCMV,W_CBF,handle_ConformalArray,estObj_LCMV,estObj_CBF,candSet] = f_conventionalBF(problem,conf,candSet,refine)
%
% Syntax: [W_LCMV,W_CBF,handle_ConformalArray,estObj_LCMV,estObj_CBF] = ...
% f_conventionalBF(problem,conf,candSet)
Expand All @@ -8,6 +8,8 @@
% conf - Struct containing configuration in data/config_test.dat
% candSet - Vector containing the users ID being considered in the
% current slot
% refine - RBoolean, Refine to find solution, select users with highest
% priority
%
% Outputs:
% W_LCMV - Matrix [nUser x nAntennas] containg the weights for LCMV
Expand Down Expand Up @@ -45,20 +47,62 @@

%------------- BEGIN CODE --------------

% Initial number of users
nUsers = length(candSet);

% Restrict sub-arrays to Localized for LCMV
problem.arrayRestriction = 'Localized';
% Restrict the number of users to the candidate Set for current slot
refine = true;

% Compute number of sub-arrays to assign per user. We ensure each user
% receives one array and locate them horizontaly
if ceil(sqrt(problem.N_Antennas)) > nUsers
problem.NySubarrays = nUsers;
problem.NxSubarrays = 1;
else
if mod(nUsers,2)~=0; t = factor(nUsers + 1); % odd
else; t = factor(nUsers); % even
end
t = [t(1) prod(t(2:end))];
problem.NxSubarrays = t(1);
problem.NySubarrays = t(2);
end
problem.N_Subarrays = problem.NxSubarrays*problem.NySubarrays;
problem = o_compute_antennas_per_user(problem,candSet);

% Create initial assignation to users
problem = o_create_subarray_partition(problem);

% Distribute partitions amongst users
totSubArrays_1 = floor((problem.NxSubarrays * problem.NySubarrays) / nUsers);
remainder = rem((problem.NxSubarrays * problem.NySubarrays),nUsers);
totSubArrays = totSubArrays_1 .* ones(1,nUsers);
totSubArrays(1:remainder) = totSubArrays(1:remainder) + 1;

% Antennas assigned to each user (initial, prior refinement in case needed)
mySubArray = (1:1:(problem.NxSubarrays * problem.NySubarrays));
relevant_positions = cell(nUsers,1);
for valID = 1:nUsers
partAssignation = mySubArray(1:totSubArrays(valID));
temp = [];
for ass = partAssignation
temp = [temp problem.Partition{ass}]; %#ok<AGROW>
end
relevant_positions{valID} = temp;
for k = partAssignation
mySubArray(mySubArray==k) = []; % delete assigned antennas
end
end

% Initialize refinement parameters for user selection in case of shortage
% of antenna resources. Some users will be left out.
Delta1 = 2e-1; % 20% tolerance = 5x max difference on number of antennas
Delta2 = 1; % Number of devices to cut out for next iteration
Delta3 = 1.5; % Tolerance of number of antennas
Delta3 = 1.3; % Tolerance of number of antennas
% Iterate until finding a candSet that allows for good cancellation amongst
% users. The less number of users scheduled to transmit, the more antennas
% for each, the more antennas per constraint, the least interference
% generated, the higher performance.
while refine
nUsers = length(candSet);
% Compute number of sub-arrays to assign per user. We ensure each user
% receives one array and locate them horizontaly
if ceil(sqrt(problem.N_Antennas)) > nUsers
Expand All @@ -73,14 +117,17 @@
problem.NySubarrays = t(2);
end
problem.N_Subarrays = problem.NxSubarrays*problem.NySubarrays;
problem = o_compute_antennas_per_user(problem,candSet);
problem = o_compute_antennas_per_user(problem,candSet);

% Create subarray partition
problem = o_create_subarray_partition(problem);

% Distribute partitions amongst users
totSubArrays_1 = floor((problem.NxSubarrays * problem.NySubarrays) / nUsers);
remainder = rem((problem.NxSubarrays * problem.NySubarrays),nUsers);
totSubArrays = totSubArrays_1 .* ones(1,nUsers);
totSubArrays(1:remainder) = totSubArrays(1:remainder) + 1;

% Antennas assigned to each user (fixed)
mySubArray = (1:1:(problem.NxSubarrays * problem.NySubarrays));
relevant_positions = cell(nUsers,1);
Expand All @@ -95,6 +142,7 @@
mySubArray(mySubArray==k) = []; % delete assigned antennas
end
end

% Check if the configuration is valid
cellsz = cellfun(@length,relevant_positions,'uni',false);
n_ant_users = cell2mat(cellsz);
Expand All @@ -118,9 +166,12 @@
else
% We've found a good solution
refine = false; % Stop the loop
nUsers = length(candSet); % update
end

% Update number of users
nUsers = length(candSet);
end

% Recreate the conformal array
problem.NzPatch = problem.NxPatch;
problem.dz = problem.dx;
Expand Down Expand Up @@ -196,5 +247,5 @@
end


% EOF
% EOF

2 changes: 1 addition & 1 deletion code-wirelessEmulation/s_phased_channel_SRM.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef s_phased_channel_SRM < matlab.System
classdef s_phased_channel_SRM < matlab.System
% phased_channel Add summary here
%
% NOTE: When renaming the class name phased_channel, the file name
Expand Down
Binary file added data/TABLE-SNR-loc4-v2.mat
Binary file not shown.
Loading

0 comments on commit af408b0

Please sign in to comment.