clc;
clear all;
close all;
MonteCarlo = 1;
iteration = 100;
N = 4; % user number
P_dB = 10; % initialize power matrix: p_i(0) = p_i/N;
% p = power(10, 0.1 * P_dB)/N; %% linear power;
p_peak = power(10, 0.1 * P_dB);
e = 1.0e-3; % a very small positive value;
th = 0.5; % total interference constraint
radium = 100;
d = 10; % the maximum distance between a pair of D2D users
path_loss = -2;
dis = zeros(N, N);
dis_source_to_bs = zeros(1, N);
for cyc = 1 : MonteCarlo
% R1 = radium * sqrt(rand(1, N));
% seta1 = 2 * pi * rand(1,N);
% x_source = R1 .* cos(seta1);
% y_source = R1 .* sin(seta1);
% position_source = x_source + 1i * y_source;
%
% % R2 = radium * sqrt(rand(1, N));
% R2 = rand(1, N) * (1 - d) + d; % generate N random values between (1, d)
% seta2 = 2 * pi * rand(1,N);
% x_destination = x_source + R2 .* cos(seta2);
% y_destination = y_source + R2 .* sin(seta2);
% position_destination = x_destination + 1i * y_destination;
%
% for i = 1:N
% for j = 1:N
% dis(i, j) = abs(position_source(i) - position_destination(j));
% end
% end
%
% dis_source_to_bs = abs(position_source);
%
% h = abs(randn(N, N) + 1i * randn(N, N)) / 2 .* power(dis, path_loss);
% g = abs(randn(1, N) + 1i * randn(1, N)) / 2 .* power(dis_source_to_bs, path_loss);
%
% % h = abs(randn(N, N) + 1i * randn(N, N)) / 2;
% % g = abs(randn(1, N) + 1i * randn(1, N)) / 2;
load four_channel.mat
q1 = zeros(1, N);
for i = 1:N
q1(i) = h(i, i) / g(i);
end
q_max = max(q1); % price upper bound;
s = q_max / iteration; % price step-size for price upper bound;
interf_max = zeros(1, N);
delta_max = zeros(1, N);
q2 = zeros(1, N);
for i = 1:N
for j = 1:N
if j ~= i
interf_max(i) = interf_max(i) + p_peak * h(j, i);
end
end
delta_max(i) = interf_max(i) + 1;
end
for i = 1:N
q2(i) = h(i, i) / g(i) / (p_peak * h(i, i) + delta_max(i));
end
q_min = min(q2); % price lower bound;
ite = 1;
q_unif = zeros(1, iteration - 1);
% q_unif(1) = q_max; % initialize price
total_interf = zeros(1, iteration - 1);
revenue_unif = zeros(1, iteration - 1);
p_unif = zeros(N, iteration - 1);
tic
while(ite < iteration)
ite
tic
[p, r] = best_response(h, g, p_peak, q_unif(ite));
toc
p
p_unif(:, ite) = p;
for i = 1:N
total_interf(ite) = total_interf(ite) + p(i) * g(i);
end
revenue_unif(ite) = q_unif(ite) * total_interf(ite);
q_unif(ite + 1) = max(q_unif(ite) + s, 0);
% if ite == 1
% q_unif(ite + 1) = q_unif(ite) - s;
% elseif ite > 1 && total_interf(ite) <= th && revenue_unif(ite) > revenue_unif(ite - 1) % abs(revenue_unif(ite) - revenue_unif(ite - 1)) <= e
% q_unif(ite + 1) = q_unif(ite) - s;
% else
% q_unif(ite + 1) = q_unif(ite);
% end
ite = ite + 1;
end
toc
end
figure
% x=1:iteration-1;
plot(q_unif,[revenue_unif,0],'-o','Linewidth', 2)
xlabel('price'); ylabel('revenue');
% text('Interpreter','latex','String','$$\pi^c$$','FontSize',16);
% text('Interpreter','latex','String','$$\pi^l$$','FontSize',16);
% text('Interpreter','latex','String','$$\pi^u$$','FontSize',16);
grid on;
figure
% x=1:iteration-1;
plot(q_unif,[p_unif(1,:),0],'-o',q_unif,[p_unif(2,:),0],':^',q_unif,[p_unif(3,:),0],'-.+',q_unif,[p_unif(4,:),0],'--s','Linewidth', 2)
legend('user 1','user 2','user 3','user 4');
xlabel('price'); ylabel('power (dB)');
grid on;
figure
% x=1:iteration-1;
plot(q_unif,[total_interf,0],'-v','Linewidth', 2)
xlabel('price'); ylabel('interference temperature');
grid on;
% figure
% subplot(3,1,1);
% plot(q_unif,[revenue_unif,0],'-o','Linewidth', 2)
% xlabel('price'); ylabel('revenue');
% subplot(3,1,2);
% plot(q_unif,[p_unif(1,:),0],'-o',q_unif,[p_unif(2,:),0],':^',q_unif,[p_unif(3,:),0],'-.+',q_unif,[p_unif(4,:),0],'--s','Linewidth', 2)
% legend('user 1','user 2','user 3','user 4');
% xlabel('price'); ylabel('power (dB)');
% subplot(3,1,3);
% plot(q_unif,[total_interf,0],'-v','Linewidth', 2)
% xlabel('price'); ylabel('interference temperature');
matlab_基于蜂窝网络的D2D通信的资源分配算法,主要是实现功率控制
版权申诉
5星 · 超过95%的资源 181 浏览量
2022-06-22
21:07:53
上传
评论 8
收藏 3KB ZIP 举报
wouderw
- 粉丝: 268
- 资源: 2960
最新资源
- hadoop-基于hive的聊天数据分析报表可视化案例数据源
- Advanced Multicore Systems-On-Chip
- kb-2026-0504cbr-3.zip
- 基于Python卷积神经网络人脸识别驾驶员疲劳检测与预警系统设计+源码+文档(毕业设计&课程设计&项目开发)
- 在链表的任意位置插入一个节点.c
- 基于python实现使用谷歌mediapipe的手关键点检测模型+源码(毕业设计&课程设计&项目开发)
- 西门子电梯PLC比赛代码
- 66eb59b9321b30b62a979f86d7d100f2.pptx
- 异或加密解密的CC++源代码示例
- 基于QT+C++实现的会逃跑的按钮+源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页