-
Notifications
You must be signed in to change notification settings - Fork 5
/
pair_rho.m
64 lines (56 loc) · 1.52 KB
/
pair_rho.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [ strong_users, users_noma, users_oma ] = pair_rho( rho )
global P;
global Users;
global Pairs;
% 计算信道相似度矩阵和信道增益差矩阵
Diff = zeros(P.nums, P.nums);
Corr = zeros(P.nums, P.nums);
for i = 1:P.nums
hi = Users(i).h.';
pli = Users(i).pathloss;
for j = 1:P.nums
hj = Users(j).h.';
plj = Users(j).pathloss;
Diff(i,j) = pli - plj;
Corr(i,j) = norm(hi*hj') / norm(hi) / norm(hj);
end
end
% 筛选相似度满足要求(rho)的可能配对组合
potential = zeros(P.nums,P.nums);
[Users(1:P.nums).candidates] = deal([]);
[Users(1:P.nums).partner] = deal([]);
for i = 1:P.nums
for j = 1:P.nums
if Corr(i,j) > rho && Diff(i,j) > 0
Users(i).candidates = [Users(i).candidates,j];
potential(i,j) = Diff(i,j);
end
end
end
% 将信道增益差最大的组合依此提取
tmp = potential;
p = 1; % index for pairs_noma
while any(tmp(:))
index = find(tmp == max(tmp(:)));
[strong,weak] = ind2sub([P.nums,P.nums], index);
Pairs(p).pair = [strong, weak];
Pairs(p).strong_user = strong;
Users(strong).partner = weak;
Users(weak).partner = strong;
p = p + 1;
tmp(strong,:) = 0;
tmp(weak,:) = 0;
tmp(:,strong) = 0;
tmp(:,weak) = 0;
end
% 将剩下没有配对的用户单独一组
users_all = 1:P.nums;
users_noma = [Pairs(1:p-1).pair];
users_oma = setdiff(users_all, users_noma);
for i = 1:length(users_oma)
Pairs(p).pair = [users_oma(i), 0];
Pairs(p).strong_user = users_oma(i);
p = p + 1;
end
strong_users = [Pairs(1:p-1).strong_user];
end