-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.m
185 lines (167 loc) · 5.56 KB
/
Main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%% Author: Rujing Xiong, Tiebin Mi
% CreatTime: 2022.10.07
% Complete:2022.10.07
% Modified:
% Modified:
% E-mail: Rujing@hust.edu.cn
% Description: DiscreteOptimization for 2-bit RIS, compare with Manopt, for multi-bit
% Based on traditional channel model, Mi's code
% SNR with N(t) 2bit and multi bit
clc
clear
tic
sigma2 = 1; %noise
T = 1; %number of Tx
B = 2; % number of bits
N = 100:100:1000;
y_square = zeros(1,length(N));
loop = 1000;
y_my = zeros(loop,length(N)); % my method (proposed DaS)
y_man = zeros(loop,length(N)); % Manopt-discrete
y_Man = zeros(loop,length(N)); % Manopt
y_apk = zeros(loop,length(N)); % apk
y_sdr = zeros(loop,length(N)); % SDR-SDP-discrete
for h = 1:loop
for t = 1:length(N)
U = zeros(N(t),2^B*N(t));
H = (randn(N(t),T)+1i*randn(N(t),1)).*0.5; %AP-RIS
Hr = (randn(N(t),1)+1i*randn(N(t),1));%RIS-USER
Phi = diag(Hr)*H;
R = Phi*Phi';
[Z,eigs_R] = eig(R,'vector');
[eigs_R,index_z] = sort(eigs_R,'descend');
Z = Z(:,index_z); %The corresponding eigenvectors are sorted in descending order too.
Z_S = Z(:,1); %Taking the igenvector corresponding to the largest eigenvalue
% proposed DaS
[w_opt,opt_my] = Opt_absWZ(Z_S,B);
y_my(h,t) = w_opt'*R*w_opt;
% Manopt
manifold = complexcirclefactory(N(t));
problem.M = manifold;
problem.cost = @(w) -w'*R*w; %
problem.grad = @(w) manifold.egrad2rgrad(w,-2*R*w);
[w,wcost,info,options] = steepestdescent(problem); % at a random point on the manifold
%[w,wcost,info,options] = conjugategradient(problem);%
%[w,wcost,info,options] = barzilaiborwein(problem); %Barzilai Borwein
%y_Man(h,t) = w'*R*w; % under continue phase shift
%w = Discretization2Bit(w);
w = discretization1Bit(w);
y_man(h,t) =w'*R*w; % under discrete phase shift
% APX
[w_apk,opt_apk] = APK_K_Ary(Z_S,B);
y_apk(h,t) = w_apk'*R*w_apk;
% CVX
f_tmp = 0;
r_tmp = zeros(N,1); %
w_tmp = zeros(N,1);
count = 10;
for k=1:count
r = (randn(N,1)+1i*randn(N,1)).*sqrt(1/2); % (N,1)
cvx_begin
variable V(N,N) symmetric semidefinite %
maximize( real(trace(R*V)))
subject to
diag(V) == 1;
cvx_end
[U,Sigma] = eig(V);
w = U*Sigma^(1/2)*r; % (N*1)
f = w'*R*w; %
if f>f_tmp
f_tmp = max(f,f_tmp);
r_tmp = r;
w_tmp = w; %
end
end
% [m,index]=max(f);
% r_opt = r(:,index);
% w_opt = w(:,index);
% theta_opt = angle(w_opt);
% w_opt = exp(1i*theta_opt); %
% W = diag(w_opt);
theta_opt = angle(w_tmp);
w_sdr = exp(1i*theta_opt);
w_sdr = discretization1Bit(w_sdr);
y_sdr(h,t) = w_sdr'*R*w_sdr;
end
X = sprintf('The loop have completed %d times.',h);
disp(X);
end % end loop
y_meanMy = mean(y_my,1);
SNR_my = 10*log10(1+y_meanMy./sigma2);
y_meanMan = mean(y_Man,1);
SNR_Man = 10*log10(1+y_meanMan./sigma2);
y_meanman = mean(y_man,1);
SNR_man = 10*log10(1+y_meanman./sigma2);
y_meanapk = mean(y_apk,1);
SNR_apk = 10*log10(1+y_meanapk./sigma2);
y_meansdr = mean(y_sdr,1);
SNR_sdr = 10*log10(1+y_meansdr./sigma2);
figure
hold on
plot(N,SNR_Man,'-rs','LineWidth',1);
hold on
plot(N,SNR_man,'-gs','LineWidth',1);
hold on
plot(N,SNR_my,'--cd','LineWidth',1);
hold on
plot(N,SNR_apk,'--bx','LineWidth',1);
hold on
plot(N,SNR_sdr,'--gd','LineWidth',1);
xlabel('N','Interpreter','latex','Fontsize',15);
ylabel('SNR(dB)','Interpreter','latex','Fontsize',15);
legend('Manopt','Discrete Manopt','Proposed method','APK','SDR-SDP','Interpreter','latex','Fontsize',15);
hold on ;
grid on;
hold on;
box on;
% title('Gains on Signal power');
toc
% figure
% hold on
% plot(N,SNR1,'-gs','LineWidth',1);
% hold on
% plot(N,SNR2,'--cd','LineWidth',1);
% hold on
% plot(N,SNR3,'-bx','LineWidth',1);
% hold on
% plot(N,SNR4,'-bs','LineWidth',1);
% hold on
% plot(N,SNR5,'--gd','LineWidth',1);
% hold on
% plot(N,SNR6,'-cx','LineWidth',1);
% hold on
% plot(N,SNR7,'-g+','LineWidth',1);
% hold on
% plot(N,SNR8,'--b+','LineWidth',1);
% hold on
% plot(N,SNR0,'-rs','LineWidth',1);
% xlabel('N','Interpreter','latex','Fontsize',15);
% ylabel('SNR(dB)','Interpreter','latex','Fontsize',15);
% legend('1-bit','2-bit','3-bit','4-bit','5-bit','6-bit','7-bit','8-bit','Manopt','Interpreter','latex','Fontsize',15);
% hold on ;
% grid on;
% hold on;
% box on;
% toc
% figure
% hold on
% plot(N,SNR1,'-gs','LineWidth',1);
% hold on
% plot(N,SNR2,'--cd','LineWidth',1);
% hold on
% plot(N,SNR3,'-bx','LineWidth',1);
% hold on
% plot(N,SNR4,'-bs','LineWidth',1);
% hold on
% plot(N,SNR5,'--gd','LineWidth',1);
% hold on
% plot(N,SNR0,'-rs','LineWidth',1);
% xlabel('N','Interpreter','latex','Fontsize',15);
% ylabel('SNR(dB)','Interpreter','latex','Fontsize',15);
% legend('1-bit','2-bit','3-bit','4-bit','5-bit','Manopt','Interpreter','latex','Fontsize',15);
% hold on ;
% grid on;
% hold on;
% box on;
% toc
%set(gca,'yticklabel',{'5%','6%','7%','8%','9%','10%'})%set ylabel in 100%