-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprecoded_MIMO_communication_ML_ver2.m
551 lines (460 loc) · 17.2 KB
/
precoded_MIMO_communication_ML_ver2.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
%filename:precoded_MIMO_communication_ML_ver2.m
j=sqrt(-1);
%LTE-A codebook
u=[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1;
-1, -j, 1, j, (-1-j)/sqrt(2), (1-j)/sqrt(2), (1+j)/sqrt(2), (-1+j)/sqrt(2), -1, -j, 1, j, -1, -1, 1, 1;
-1, 1, -1, 1, -j, j, -j, j, 1, -1, 1, -1, -1, 1, -1, 1;
-1, j, 1, -j, (1-j)/sqrt(2), (-1-j)/sqrt(2),(-1+j)/sqrt(2),(1+j)/sqrt(2), 1, -j, -1, j, 1, -1, -1, 1];
W=zeros(4,4,16);
for i=1:length(W)
a = u(:, i) * u(:, i)';
b = u(:, i)' * u(:, i);
W(:, :, i) = eye(4) - (2 * a) / b;
end
F4_matrix_order = ...
[[1 2 3 4];[1 2 3 4];[3 2 1 4];[3 2 1 4];
[1 2 3 4];[1 2 3 4];[1 3 2 4];[1 3 2 4];
[1 2 3 4];[1 2 3 4];[1 3 2 4];[1 3 2 4];
[1 2 3 4];[1 3 2 4];[3 2 1 4];[1 2 3 4]];
F4=zeros(4,4,16);
for i=1:length(W)
F4(:, :, i) = W(:, F4_matrix_order(i,:), i) / 2;
end
F2_matrix_order = ...
[[1 4];[1 2];[1 2];[1 2];
[1 4];[1 4];[1 3];[1 3];
[1 2];[1 4];[1 3];[1 3];
[1 2];[1 3];[1 3];[1 2]];
F2=zeros(4,2,16);
for i=1:length(W)
F2(:, :, i) = W(:, F2_matrix_order(i,:), i) /sqrt(2);
end
nS=2; %number of streams
nT=4; %number of transmit antenna
nR=2; %number of receive antenna
k=4; %2,4,6
frame_size=nS*k; %bits
% frame_size = 8;
MAX_frame_NUM=50000000;
EbNo_Start=1;%[dB]
EbNo_End=30;
EbNo_Step=1;
EbNo=[EbNo_Start:EbNo_Step:EbNo_End]; %[dB]
BER_target=5 * 10^(-6);
bit_error_target=1000;
threshold = bit_error_target / (frame_size * BER_target) ; disp(threshold);
seed = randi(10000);
% Single (No) precoder (with Sphere Decoding)
tic
Random_precoder_SD_BER=zeros(1,length(EbNo));
for EbNo_idx=1:0
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randi([0 1],1,frame_size);
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Use selected Random Precoder
% n : Gaussian noise
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if mod(bit_error, 100) == 0
fprintf('[%d %%] EbNo_idx %d ) %g \n', bit_error/bit_target * 100,EbNo(EbNo_idx) ,bit_error/(frame_idx*frame_size));
end
if bit_error > bit_error_target
Random_precoder_SD_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('EbNo_idx %d is over ) %g\n',EbNo(EbNo_idx), bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
Random_precoder_SD_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('EbNo_idx %d is over ) %g\n',EbNo(EbNo_idx), bit_error/(frame_idx*frame_size));
break;
end
end
if Random_precoder_SD_BER(EbNo_idx) < BER_target
break;
end
end
% ML Precoder
disp('--------------- Single (No) Precoder Selection performance measurement is over ---------------');
toc
SMLPS_BER=zeros(1,length(EbNo));
for EbNo_idx=1:0
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
if mod(frame_idx/MAX_frame_NUM * 100, 10.0) == 0.0
fprintf('[Message] SMLPS Detection, EbNo_idx : %d, %g \%, Bit Error : %d\n' ...
, EbNo_idx, frame_idx/MAX_frame_NUM * 100, bit_error);
end
%random frame generation
bits=randn(1,frame_size);
neg_idx=find(bits<0);
bits=ones(1,frame_size);
bits(neg_idx)=0;
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select Precoder
[F, ~] = Simplified_ML_Precoder_Selection(H, nS);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
SMLPS_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[SMLPS_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
SMLPS_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[SMLPS_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if SMLPS_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- Simplified ML Selection performance measurement is over ---------------');
toc
tic
ML_BER=zeros(1,length(EbNo));
for EbNo_idx=1:length(EbNo)
bit_error=0;
rng('default');
rng(6807);
% sprintf('EbNo_idx : %d \n', EbNo_idx);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randi([0 1],1,frame_size);
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select Precoder
F = precoder_select_ML_ver6_complex_ver1(H,nS);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
ML_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[ML_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
ML_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[ML_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if ML_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- ML Selection performance measurement is over ---------------');
toc
tic
QRD_BER=zeros(1,length(EbNo));
for EbNo_idx=1:length(EbNo)
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randn(1,frame_size);
neg_idx=find(bits<0);
bits=ones(1,frame_size);
bits(neg_idx)=0;
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select Precoder
[F, ~] = QRD_based_Method(H,nS);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
QRD_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
QRD_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if QRD_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- QRD based Selection performance measurement is over ---------------');
toc
perms_array = perms(1:1:K).';
[perms_size_case, perm_size_total] = size(perms_array);
perms_idx_refer = zeros(1, 10^(perms_size_case-1) * (perms_size_case+1));
for i = 1:perm_size_total
if perms_size_case == 2
perms_idx = perms_array(1,i) * 10 +perms_array(2,i);
elseif perms_size_case == 3
perms_idx = perms_array(1,i) * 100 + perms_array(2,i) * 10 +perms_array(3,i);
else
% Considered only perms_size_case == 4
perms_idx = perms_array(1,i) * 1000 + perms_array(2,i) * 100 +perms_array(3,i) * 10 + perms_array(4,i);
end
perms_idx_refer(perms_idx) = i;
end
% Generate Permutation Tree
perms_tree = zeros(2, perm_size_total);
perms_queue = zeros(size(perms_array));
tree_idx = 1; queue_curr_idx = 1;
perms_queue(:, queue_curr_idx) = perms_array(:, 1);
tree_checker = zeros(1, perm_size_total);
while queue_curr_idx ~= 0
perms_pattern = perms_queue(: , queue_curr_idx);
queue_curr_idx = queue_curr_idx - 1;
perms_idx = perms_pattern(1) * 1000 + perms_pattern(2) * 100 +perms_pattern(3) * 10 + perms_pattern(4);
parent_checker_idx = perms_idx_refer(perms_idx);
if parent_checker_idx == 1
tree_checker(1) = true;
perms_tree(1, tree_idx) = 1; % child
perms_tree(2, tree_idx) = 0; % parent
tree_idx = tree_idx + 1;
end
for w=1:perms_size_case-1
swapped_pattern = perms_pattern;
% Swap
temp_element = swapped_pattern(w+1);
swapped_pattern(w+1) = swapped_pattern(w);
swapped_pattern(w) = temp_element;
swapped_perms_idx = swapped_pattern(1) * 1000 + swapped_pattern(2) * 100 +swapped_pattern(3) * 10 + swapped_pattern(4);
child_checker_idx = perms_idx_refer(swapped_perms_idx);
if ~tree_checker(child_checker_idx)
tree_checker(child_checker_idx) = true;
perms_tree(1, tree_idx) = child_checker_idx; % child
perms_tree(2, tree_idx) = parent_checker_idx; % parent
tree_idx = tree_idx + 1;
queue_curr_idx = queue_curr_idx + 1;
perms_queue(:, queue_curr_idx) = perms_array(:, child_checker_idx);
end
end
end
tic
QRD_BTP_BER=zeros(1,length(EbNo));
for EbNo_idx=1:length(EbNo)
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randn(1,frame_size);
neg_idx=find(bits<0);
bits=ones(1,frame_size);
bits(neg_idx)=0;
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select Precoder
[F, ~] = QRD_based_BT_P_Method(H,nS);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
QRD_BTP_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTP_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
QRD_BTP_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTP_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if QRD_BTP_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- QRD_BT-P based Selection performance measurement is over ---------------');
toc
tic
QRD_BTC_BER=zeros(1,length(EbNo));
for EbNo_idx=1:length(EbNo)
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randn(1,frame_size);
neg_idx=find(bits<0);
bits=ones(1,frame_size);
bits(neg_idx)=0;
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select Precoder
[F, ~] = QRD_based_BT_C_Method(H, nS, 0.99);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
%receiver
%Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
QRD_BTC_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTC_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
QRD_BTC_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTC_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if QRD_BTC_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- QRD_BT-C based Selection performance measurement is over ---------------');
toc
tic
QRD_BTE_BER=zeros(1,length(EbNo));
for EbNo_idx=1:length(EbNo)
bit_error=0;
rng('default');
rng(seed);
for frame_idx=1:MAX_frame_NUM
%random frame generation
bits=randn(1,frame_size);
neg_idx=find(bits<0);
bits=ones(1,frame_size);
bits(neg_idx)=0;
%QAM mapping
x=QAM_mapper(bits,k);
x=transpose(x);%row->column
%noise variance calculation
n_var=10^(-EbNo(EbNo_idx)/10)/k;
%wireless transmission
%Rayleigh fading channel
H=1/sqrt(nS)*sqrt(1/2)*(randn(nR,nT)+j*randn(nR,nT));
% Select the proper Precoder
[F, ~] = QRD_based_BT_E_Method(H, nS, 2, 0.99);
n=sqrt(n_var/2)*(randn(nR,1)+j*randn(nR,1));
y=H*F*x+n;
% Receiver / Rayleigh fading channel
%If F is selected by ML algorithm, then use sphere decoder to get
% original stream(signal).
HF = H*F;
s_hat=Sphere_Decoder(y,HF,nS,k,n_var);
bits_hat=QAM_demapper(s_hat,k);
%BER calculation
bit_error=bit_error+sum(xor(bits,bits_hat));
if bit_error > bit_error_target
QRD_BTE_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTE_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
if bit_error_target /(frame_idx*frame_size) < BER_target
QRD_BTE_BER(EbNo_idx)=bit_error/(frame_idx*frame_size);
fprintf('[QRD_BTE_BER] EbNo_idx %d is over ) %g\n',EbNo_idx, bit_error/(frame_idx*frame_size));
break;
end
end
if QRD_BTE_BER(EbNo_idx) < BER_target
break;
end
end
disp('--------------- QRD_BT-E based Selection performance measurement is over ---------------');
toc
disp('All over');
figure;
semilogy(EbNo,Random_precoder_SD_BER, 'rx-'); hold on;
semilogy(EbNo, ML_BER, 'bo-'); hold on;
semilogy(EbNo, SMLPS_BER, 'm*--'); hold on;
semilogy(EbNo, QRD_BER, 'k+-'); hold on;
semilogy(EbNo, QRD_BTP_BER, 'k^-'); hold on;
semilogy(EbNo, QRD_BTC_BER, 'ks-'); hold on;
semilogy(EbNo, QRD_BTE_BER, 'kd-.'); hold on;
title('Precoder Selection Processing Time');
xlabel('SNR[dB]');
ylabel('BER');
legend('No precoder','ML precoder', 'SML precoder', 'QRD precoder', ...
'QRD BT-P precoder', 'QRD BT-C precoder', 'QRD BT-E precoder');
saveas(gcf,'MIMO_4x4_QAM16_nS4');