forked from dimme/cost2100model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOST2100_Specification.cpp
1303 lines (1217 loc) · 47.4 KB
/
COST2100_Specification.cpp
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* COST2100_Specification.cpp
*
* Created on: Mar 30, 2010
* Author: K.K.
*/
#include "COST2100_Specification.h"
#include "debug.h"
#define DEBUG
#undef DBG_LVL
#define DBG_LVL (DBG_ERR|DBG_INFO)//DBG_TRACE|DBG_WARN|DBG_INFO|DBG_ENTER|DBG_LEAVE)
#include <string>
#include <vector>
namespace penux {
using namespace itpp;
void MPC::update_MPC_pos(const SIDE_TYPE sd_type, int mpc_idx, const vec pos) {
switch (sd_type) {
case BS:
MPC_BS_pos.set_row(mpc_idx, pos);
break;
case MS:
MPC_MS_pos.set_row(mpc_idx, pos);
break;
case BS_MS:
MPC_BS_pos.set_row(mpc_idx, pos);
MPC_MS_pos.set_row(mpc_idx, pos);
break;
}
}
Cluster::Cluster(const CLUSTER_TYPE c_type, const vec &c_bs_pos, const vec &c_ms_pos, const vec &spread, double c_sf, double c_tau_link, const vec &angle, const MPC mpc) {
C_type = c_type;
C_BS_pos = c_bs_pos;
C_MS_pos = c_ms_pos;
C_delay_BS = spread.get(0);
C_AoD_BS = spread.get(1);
C_EoD_BS = spread.get(2);
C_delay_MS = spread.get(3);
C_AoD_MS = spread.get(4);
C_EoD_MS = spread.get(5);
C_shadow_f = c_sf;
C_tau_link = c_tau_link;
C_Phi_BS = angle.get(0);
C_Theta_BS = angle.get(1);
C_Phi_MS = angle.get(2);
C_Theta_MS = angle.get(3);
C_MPC = mpc;
}
double Cluster::get_cluster_spread(const SPREAD_TYPE s_type) {
double spread;
switch (s_type) {
case DELAY_AT_BS:
spread = C_delay_BS;
break;
case DELAY_AT_MS:
spread = C_delay_MS;
break;
case AOD_AT_BS:
spread = C_AoD_BS;
break;
case AOD_AT_MS:
spread = C_AoD_MS;
case EOD_AT_BS:
spread = C_EoD_BS;
break;
case EOD_AT_MS:
spread = C_EoD_MS;
break;
}
return spread;
}
vec Cluster::get_cluster_spread_vec(const SIDE_TYPE sd_type) {
vec s_vec;
switch (sd_type) {
case BS:
s_vec.ins(0, C_delay_BS);
s_vec.ins(1, C_AoD_BS);
s_vec.ins(2, C_EoD_BS);
break;
case MS:
s_vec.ins(0, C_delay_MS);
s_vec.ins(1, C_AoD_MS);
s_vec.ins(2, C_EoD_MS);
break;
case BS_MS:
s_vec.ins(0, C_delay_BS);
s_vec.ins(1, C_AoD_BS);
s_vec.ins(2, C_EoD_BS);
s_vec.ins(3, C_delay_MS);
s_vec.ins(4, C_AoD_MS);
s_vec.ins(5, C_EoD_MS);
break;
}
return s_vec;
};
double Cluster::get_cluster_angle(const ANGLE_TYPE a_type) {
double angle;
switch (a_type) {
case AZIMUTH_AT_BS:
angle = C_Phi_BS;
break;
case AZIMUTH_AT_MS:
angle = C_Phi_MS;
break;
case ELEVATION_AT_BS:
angle = C_Theta_BS;
break;
case ELEVATION_AT_MS:
angle = C_Theta_MS;
break;
}
return angle;
}
vec Cluster::get_cluster_angle_vec(const SIDE_TYPE sd_type) {
vec a_vec;
switch (sd_type) {
case BS:
a_vec.ins(0, C_Phi_BS);
a_vec.ins(1, C_Theta_BS);
break;
case MS:
a_vec.ins(0, C_Phi_MS);
a_vec.ins(1, C_Theta_MS);
break;
case BS_MS:
a_vec.ins(0, C_Phi_BS);
a_vec.ins(1, C_Theta_BS);
a_vec.ins(2, C_Phi_MS);
a_vec.ins(3, C_Theta_MS);
break;
}
return a_vec;
}
Channel_Specification::Channel_Specification(string fileName) {
// initialize the random seeds
RNG_randomize ();
getParamsFromXML(fileName);
init_BSCC();
init_MSCC();
init_VR();
init_cluster();
init_channel();
}
void Channel_Specification::init_channel() {
// for each snapshot
for (int t = 0; t < snapNum; t ++) {
int bs_num = BS_info.get_BS_num();
int ms_num = MS_info.get_MS_num();
// for each BS
for (int i = 0; i < bs_num; i ++) {
vec bs_pos = BS_info.get_BS_pos().get_row(i);
ivec bs_vr_idx = find_element(BSCC.get_row(i), 1);
mat bs_vr = BS_info.get_VR().get_rows(bs_vr_idx);
vec bs_vr_los = BS_info.get_VR_LOS().get_row(i);
// for each MS
for (int j = 0; j < ms_num; j ++) {
mat channel_matrix;
vec ms_pos = MS_info.get_MS_pos().get_row(j);
double d_ms_bs = calc_dist(bs_pos, ms_pos); // distance between BS and MS
if (d_ms_bs == 0) {
ERROR("init_channel(): BS/MS at the same position");
return;
} else {
// active far clusters
double pathloss = calc_path_loss(d_ms_bs);
ivec active_vr_idx;
vec vr_gain, vr_amp;
int pos = 0;
for (int k = 0; k < bs_vr_idx.length(); k ++) {
double dist_tmp = calc_dist(ms_pos.get(0, 1), bs_vr.get_row(k).get(0, 1));
if (dist_tmp < R_C) { // active VR
double y = dist_tmp + L_C - R_C;
vr_gain.ins(pos, 1 / 2 - atan(2 * sqrt(2) * y / sqrt(lambda * L_C)) / pi);
active_vr_idx.ins(pos, bs_vr_idx.get(k));
pos ++;
}
}
if (active_vr_idx.length() > 0) {
double tau_0 = d_ms_bs / c0;
imat mscc = MSCC;
ivec active_cluster_idx = mscc.get_rows(active_vr_idx).get_col(0);
ivec active_cluster = delete_repeated_elements(active_cluster_idx);
mat vrgain = vr_gain;
for (int l = 0; l < active_cluster.length(); l ++) {
int active_cluster_idx = active_cluster.get(l);
vr_amp.ins(l, max(vrgain.get_rows(find_element(MSCC, active_cluster_idx)).get_col(0)));
Cluster current_active_cluster = channel_cluster(active_cluster_idx);
double d_bs_c_ms = calc_dist(bs_pos, current_active_cluster.get_cluster_pos(BS))
+ calc_dist(ms_pos, current_active_cluster.get_cluster_pos(MS));
double tau = d_bs_c_ms / c0 + current_active_cluster.get_cluster_link_delay();
double cluster_att = std::max(exp(-k_tau * (tau - tau_0) * 1e6), exp(-k_tau * (tau_B - tau_0) * 1e6)); // attenuation of clusters
MPC cluster_MPC = current_active_cluster.get_cluster_MPC();
double cluster_sf = current_active_cluster.get_cluster_shadowing_fading();
for (int m = 0; m < N_MPC; m ++) {
vec mpc_bs_sph = coordinate_transformation(cluster_MPC.get_MPC_pos(BS).get_row(m) - bs_pos, CART2SPH);
vec mpc_ms_sph = coordinate_transformation(cluster_MPC.get_MPC_pos(MS).get_row(m) - ms_pos, CART2SPH);
double tau_mpc = (mpc_bs_sph.get(2) + mpc_ms_sph.get(2)) / c0 + current_active_cluster.get_cluster_link_delay();
complex<double> phase(0, -2 * pi * freq_c * tau_mpc);
complex<double> channel_amp = sqrt(cluster_sf * cluster_att)
* cluster_MPC.get_MPC_amplitude().get(m) * pathloss * exp(phase);
double channel_amp_real = channel_amp.real();
double channel_amp_imag = channel_amp.imag();
// DDIR
vec channel = concat(mpc_bs_sph.get(0, 1), mpc_ms_sph.get(0, 1), to_vec(tau_mpc), to_vec(channel_amp_real), to_vec(channel_amp_imag));
channel_matrix.append_row(channel);
}
}
}
std::cout << "Info: init_channel(): channel initializing...!" << std::endl;
// active BS local cluster
if (BS_local) {
Cluster local_cluster = (BS_info.get_BS_local_cluster())(i);
MPC local_MPC = local_cluster.get_cluster_MPC();
double cluster_sf = local_cluster.get_cluster_shadowing_fading();
for (int m = 0; m < N_MPC; m ++) {
vec mpc_bs_sph = coordinate_transformation(local_MPC.get_MPC_pos(BS).get_row(m) - bs_pos, CART2SPH);
vec mpc_ms_sph = coordinate_transformation(local_MPC.get_MPC_pos(MS).get_row(m) - ms_pos, CART2SPH);
double tau_mpc = (mpc_bs_sph.get(2) + mpc_ms_sph.get(2)) / c0 + local_cluster.get_cluster_link_delay();
complex<double> phase(0, -2 * pi * freq_c * tau_mpc);
complex<double> channel_amp = sqrt(cluster_sf) * local_MPC.get_MPC_amplitude().get(m) * pathloss * exp(phase);
double channel_amp_real = channel_amp.real();
double channel_amp_imag = channel_amp.imag();
// DDIR
vec channel = concat(mpc_bs_sph.get(0, 1), mpc_ms_sph.get(0, 1), to_vec(tau_mpc), to_vec(channel_amp_real), to_vec(channel_amp_imag));
channel_matrix.append_row(channel);
}
}
// active MS local cluster
if (MS_local) {
Cluster local_cluster = (MS_info.get_MS_local_cluster())(j);
MPC local_MPC = local_cluster.get_cluster_MPC();
double cluster_sf = local_cluster.get_cluster_shadowing_fading();
for (int m = 0; m < N_MPC; m ++) {
vec mpc_bs_sph = coordinate_transformation(local_MPC.get_MPC_pos(BS).get_row(m) - bs_pos, CART2SPH);
vec mpc_ms_sph = coordinate_transformation(local_MPC.get_MPC_pos(MS).get_row(m) - ms_pos, CART2SPH);
double tau_mpc = (mpc_bs_sph.get(2) + mpc_ms_sph.get(2)) / c0 + local_cluster.get_cluster_link_delay();
complex<double> phase(0, -2 * pi * freq_c * tau_mpc);
complex<double> channel_amp = sqrt(cluster_sf) * local_MPC.get_MPC_amplitude().get(m) * pathloss * exp(phase);
double channel_amp_real = channel_amp.real();
double channel_amp_imag = channel_amp.imag();
// DDIR
vec channel = concat(mpc_bs_sph.get(0, 1), mpc_ms_sph.get(0, 1), to_vec(tau_mpc), to_vec(channel_amp_real), to_vec(channel_amp_imag));
channel_matrix.append_row(channel);
}
}
// LOS component
double power_los, power_factor_los;
if (d_ms_bs > d_co) {
power_los = 0;
power_factor_los = 0;
} else {
double d_ms_vr_los = calc_dist(ms_pos.get(0, 1), bs_vr_los.get(0, 1));
if (d_ms_vr_los > R_L) {
power_los = 0;
power_factor_los = 0;
} else {
double y = d_ms_vr_los + L_L - R_L;
double vr_los_gain = 1 / 2 - atan(2 * sqrt(2) * y / sqrt(lambda * R_L)) / pi;
double power_other = 0;
power_factor_los = power_factor;
power_other = pow(sum(channel_matrix.get_col(5)), 2) + pow(sum(channel_matrix.get_col(6)), 2);
power_los = abs(power_factor_los) * power_other;
}
}
vec los_bs_sph = coordinate_transformation(ms_pos - bs_pos, CART2SPH);
vec los_ms_sph = coordinate_transformation(bs_pos - ms_pos, CART2SPH);
double d_bs_ms_xy = calc_dist(bs_pos.get(0, 1), ms_pos.get(0, 1));// distance BS to MS, in X-Y plane
double tau_0_xy = d_bs_ms_xy / c0; // delay of the LOS
complex<double> phase_los(0, -2 * pi * freq_c * tau_0_xy);
complex<double> channel_amp_los = sqrt(power_los) * exp(phase_los);
double channel_amp_los_real = channel_amp_los.real();
double channel_amp_los_imag = channel_amp_los.imag();
// DDIR
vec channel_los = concat(los_bs_sph.get(0, 1), los_ms_sph.get(0, 1), to_vec(tau_0_xy), to_vec(channel_amp_los_real), to_vec(channel_amp_los_imag));
channel_matrix.append_row(channel_los);
std::cout << "Info: init_channel(): " << channel_matrix.size() << std::endl;
/********** Creating frequency response with antenna settings: start **********/
// FIXME: change it to be compatible with external antenna settings
// Reserved TX, RX numbers TODO: get from external parameters
int tx_num = 2;
int rx_num = 2;
// Get transfer function with DDIRs
Array<cmat> H_all(N_freq);
vec freqs(N_freq );
for (int f = 0; f < N_freq; f++) {
cmat H(rx_num, tx_num);
double freq = freq_start + f * freq_div;
freqs.set(f, freq);
for (int m = 0; m < channel_matrix.rows(); m++ ) {
int tau_idx = ceil(channel_matrix.get(m, 4) / sampleRate);
if (tau_idx > 0 && tau_idx < tau_idx_max ) {
complex<double> delay_phase(0, -2 * pi * freq * channel_matrix.get(m, 4));
complex<double> delay_response = exp(delay_phase);
double aod = channel_matrix.get(m, 0);
double eod = channel_matrix.get(m, 1);
mat bsv(1, 3);
bsv.set(0, 0, sin(eod) * cos(aod));
bsv.set(0, 1, sin(eod)*sin(aod));
bsv.set(0, 2, cos(eod));
bsv = bsv * rotate_matrix(vec("0, 0"));//txRot(1), txRot(2)
aod = acos(bsv(0, 2));
eod = atan2(bsv(0, 1), bsv(0, 0));
double aoa = channel_matrix.get(m, 2);
double eoa = channel_matrix.get(m, 3);
mat msv(1, 3);
msv.set(0, 0, sin(eoa)*cos(aoa));
msv.set(0, 1, sin(eoa)*sin(aoa));
msv.set(0, 2, cos(eoa));
msv = msv * rotate_matrix(vec("0, 0")); //rxRot(1), rxRot(2)
aod=acos(msv(0, 2));
eod=atan2(msv(0, 1),msv(0, 0));
cmat antenna_response_tx(tx_num, 1);
cmat antenna_response_rx(rx_num, 1);
/*
// Antenna repsonse general version
// load from data
vec txAziRange, txEleRange, rxAziRange, rxEleRange;
Array<cmat> txResponses, rxResponses;
int txAziIdx = min_index(abs(txAziRange - aod * 180 / pi));
int txEleIdx = min_index(abs(txEleRange - eod * 180 / pi));
int rxAziIdx = min_index(abs(rxAziRange - aoa * 180 / pi));
int rxEleIdx = min_index(abs(rxEleRange - eoa * 180 / pi));
for (int tx = 0; tx < tx_num; tx++) {
antenna_response_tx.set(tx, 0, txResponses(tx).get(txAziIdx, txEleIdx));
}
for (int rx = 0; rx < rx_num; rx++) {
antenna_response_rx.set(rx, 0, rxResponses(rx).get(rxAziIdx, rxEleIdx));
}
*/
// 2x2 antenna system test, assume half wavelength distance
complex<double> antenna_shift_tx(0, -pi * cos(aod));
complex<double> antenna_shift_rx(0, -pi * cos(aoa));
antenna_response_tx.set(0, 0, 1);
antenna_response_tx.set(1, 0, exp(antenna_shift_tx));
antenna_response_rx.set(0, 0, 1);
antenna_response_rx.set(1, 0, exp(antenna_shift_rx));
complex<double> channel_amplitude(channel_matrix.get(m, 5), channel_matrix(m, 6));
H += channel_amplitude * delay_response * antenna_response_rx * antenna_response_tx.transpose();
} else {// out of the delay range
continue;
}
}
H_all(f) = H;
//TODO: channel normalization with filters
}
/********** Creating frequency response with antenna settings: end **********/
transfer.push_back(Transfer_Function(i, j, freqs, H_all));
}
}
}
update_MS_info();
transfer_function.push_back(transfer);
}
std::cout << "Info: init_channel(): channel initialized!" << std::endl;
}
void Channel_Specification::getParamsFromXML(string fileName) {
char *fn=new char[fileName.size()+1];
fn[fileName.size()] = 0;
memcpy(fn, fileName.c_str(), fileName.size());
xmlDocPtr doc = xmlReadFile(fn,"UTF-8",XML_PARSE_RECOVER); // parse the file
xmlNodePtr curNode, bsNodes, msNodes, channelNodes, exChannelNodes, stChannelNodes, spreadNodes, clusterNodes;
xmlChar *xmlKey;
if (NULL == doc) {
ERROR("getParamsFromXML(): file cannot be read!");
return;
}
curNode = xmlDocGetRootElement(doc);
if (NULL == curNode) {
xmlFreeDoc(doc);
ERROR("getParamsFromXML(): file is blank!");
return;
}
if (xmlStrcmp(curNode->name, BAD_CAST "ChannelSpecification")) { // check root element name
xmlFreeDoc(doc);
ERROR("getParamsFromXML(): file is invalid!");
return;
}
// get children nodes
curNode = curNode->xmlChildrenNode;
while (curNode != NULL) {
// set the parameters from the given xml
// load BS information
if ((!xmlStrcmp(curNode->name, BAD_CAST "BSInfo"))) {
bsNodes = curNode->xmlChildrenNode;
mat bs_pos;
vec bscc_ratio;
vec antenna_num;
while (bsNodes != NULL) {
if ((!xmlStrcmp(bsNodes->name, BAD_CAST "position"))) {
xmlKey = xmlNodeGetContent(bsNodes);
string pos((char*) xmlKey);
bs_pos = mat(pos);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(bsNodes->name, BAD_CAST "commonRatio"))) {
xmlKey = xmlNodeGetContent(bsNodes);
string ratio((char*) xmlKey);
bscc_ratio = vec(ratio);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(bsNodes->name, BAD_CAST "antennaNum"))) {
xmlKey = xmlNodeGetContent(bsNodes);
string antenna((char*) xmlKey);
antenna_num = vec(antenna);
xmlFree(xmlKey);
}
// TODO: add here for more parameter nodes if necessary
bsNodes = bsNodes->next;
}
xmlFree(bsNodes);
if (bs_pos.rows() != bscc_ratio.length()) {
ERROR("getParamsFromXML(): invalid BS information!");
return;
}
BS_info = BS_Info(bs_pos, bscc_ratio, antenna_num); // initialize the BS_Info object
std::cout << "Info: getParamsFromXML(): BS_Info loaded!" << std::endl;
}
// load MS information
else if ((!xmlStrcmp(curNode->name, BAD_CAST "MSInfo"))) {
msNodes = curNode->xmlChildrenNode;
mat ms_pos, ms_velo;
double mscc;
vec antenna_num;
while (msNodes != NULL) {
if ((!xmlStrcmp(msNodes->name, BAD_CAST "position"))) {
xmlKey = xmlNodeGetContent(msNodes);
string pos((char*) xmlKey);
ms_pos = mat(pos);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(msNodes->name, BAD_CAST "velocity"))) {
xmlKey = xmlNodeGetContent(msNodes);
string velo((char*) xmlKey);
ms_velo = mat(velo);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(msNodes->name, BAD_CAST "commonCluster"))) {
xmlKey = xmlNodeGetContent(msNodes);
mscc = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(msNodes->name, BAD_CAST "antennaNUm"))) {
xmlKey = xmlNodeGetContent(msNodes);
string antenna((char*) xmlKey);
antenna_num = vec(antenna);
xmlFree(xmlKey);
}
// TODO: add here for more parameter nodes if necessary
msNodes = msNodes->next;
}
xmlFree(msNodes);
if (ms_pos.rows() != ms_velo.rows()) {
ERROR("getParamsFromXML(): invalid MS information!");
return;
}
MS_info = MS_Info(ms_pos, ms_velo, mscc, antenna_num);
std::cout << "Info: getParamsFromXML(): MS_Info loaded!" << std::endl;
}
// load channel information
else if ((!xmlStrcmp(curNode->name, BAD_CAST "Channel"))) {
channelNodes = curNode->xmlChildrenNode;
while (channelNodes != NULL) {
if ((!xmlStrcmp(channelNodes->name, BAD_CAST "profile"))) {
xmlKey = xmlNodeGetContent(channelNodes);
string prof((char*) xmlKey);
if (prof == "macro")
profile = COST2100_MACRO;
else if (prof == "micro")
profile = COST2100_MICRO;
else if (prof == "pico")
profile = COST2100_PICO;
else if (prof == "aalto")
profile = COST2100_AALTO;
else
profile = COST2100_TEST;
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): profile loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "frequency"))) {
xmlKey = xmlNodeGetContent(channelNodes);
string freq_str((char*) xmlKey);
vec freq = vec(freq_str);
if (freq.length() != 3 && freq.get(0) > freq.get(1) ) {
ERROR("getParamsFromXML(): incorrect frequency range!");
return;
} else {
freq_start = freq.get(0);
freq_stop = freq.get(1);
freq_div = freq.get(2);
bandwidth = freq_stop - freq_start;
N_freq = bandwidth / freq_div;
freq_c = (freq_start + freq_stop) / 2;
sampleRate = 1 / bandwidth;
c0 = 3e8;
lambda = c0 / freq_c;
}
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): frequency loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "snapRate"))) {
xmlKey = xmlNodeGetContent(channelNodes);
snapRate = atof((char*) xmlKey);
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): snapRate loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "snapNum"))) {
xmlKey = xmlNodeGetContent(channelNodes);
snapNum = atof((char*) xmlKey);
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): snapNum loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "overSampleRate"))) {
xmlKey = xmlNodeGetContent(channelNodes);
overSampleRate = atof((char*) xmlKey);
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): overSampleRate loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "bandType"))) {
xmlKey = xmlNodeGetContent(channelNodes);
string band((char*) xmlKey);
if (band == "wide") {
bandType = WIDEBAND;
} else if (band == "narrow") {
bandType = NARROWBAND;
}
xmlFree(xmlKey);
std::cout << "Info: getParamsFromXML(): bandType loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "external"))) { // external channel parameters
exChannelNodes = channelNodes->xmlChildrenNode;
while (exChannelNodes != NULL) {
if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "bsHeight"))) { // TODO: check the range height expression
xmlKey = xmlNodeGetContent(exChannelNodes);
h_BS = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "msHeight"))) { // TODO: check the range height expression
xmlKey = xmlNodeGetContent(exChannelNodes);
h_MS = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "cellRadius"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
cellRadius = atof((char*) xmlKey);
delay_max = cellRadius * 5; // maximum delay, 5 times of cell_radius [s]
tau_idx_max = ceil(delay_max / sampleRate);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "rooftopHeight"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
h_rooftop = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "roadWidth"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
w_road = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "buildingSeparation"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
w_street = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "roadOrientation"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
phi_road = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "roomSize"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
string room_str((char*) xmlKey);
vec room = vec(room_str);
if (room.length() != 2) {
ERROR("getParamsFromXML(): incorrect room size!");
return;
} else {
l_room = room.get(0);
w_room = room.get(1);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(exChannelNodes->name, BAD_CAST "floorNum"))) {
xmlKey = xmlNodeGetContent(exChannelNodes);
n_floor = atof((char*) xmlKey);
xmlFree(xmlKey);
}
exChannelNodes = exChannelNodes->next;
}
xmlFree(exChannelNodes);
std::cout << "Info: getParamsFromXML(): other external parameters loaded!" << std::endl;
} else if ((!xmlStrcmp(channelNodes->name, BAD_CAST "stochastic"))) { // stochastic channel parameters
stChannelNodes = channelNodes->xmlChildrenNode;
while (stChannelNodes != NULL) {
if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "vrRadius"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
R_C = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "trRadius"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
L_C = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "clusterPower"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
k_tau = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "excessDelay"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
tau_B = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "cutoffDistLOS"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
d_co = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "vrRadiusLOS"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
R_L = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "trRadiusLOS"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
L_L = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "factorLOS"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string factor_str((char*) xmlKey);
vec factor_LOS = vec(factor_str);
if (factor_LOS.length() != 2)
ERROR("getParamsFromXML(): incorrect LOS factors!");
else {
mu_K = factor_LOS.get(0);
sigma_K = factor_LOS.get(1);
power_factor = mu_K * pow(10, (randn() * sigma_K / 10));
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "singleClusterRatio"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
K_sel = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "averageLocalCluster"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
N_C_local = atof((char*) xmlKey);
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "averageFarCluster"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
mu_N_C_add = atof((char*) xmlKey);
N_C_add = get_Poisson_number(mu_N_C_add);
double rho_C = (N_C_add) / (pi * pow(R_C - L_C, 2));
N_C_far = round_i(rho_C * (pi * pow(cellRadius, 2)));
xmlFree(xmlKey);
if (N_C_far == 0) {
ERROR("getParamsFromXML(): incorrect average far cluster number! (unknown exception)");
return;
}
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "activeLocalCluster"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string local_str((char*) xmlKey);
vec local_active = vec(local_str);
if (local_active.length() != 2) {
ERROR("getParamsFromXML(): incorrect local cluster activeness!");
return;
} else {
BS_local = (local_active.get(0) == 1) ? true : false;
MS_local = (local_active.get(1) == 1) ? true : false;
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "mpc"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string mpc_str((char*) xmlKey);
vec mpc_factor = vec(mpc_str);
if (mpc_factor.length() != 2) {
ERROR("getParamsFromXML(): incorrect MPC factors!");
return;
} else {
N_MPC = mpc_factor.get(0);
K_MPC = mpc_factor.get(1);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "diffuseRadiation"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string diffuse_str((char*) xmlKey);
vec diffuse_radiation = vec(diffuse_str);
if (diffuse_radiation.length() != 3) {
ERROR("getParamsFromXML(): incorrect diffuse radiation factor!");
return;
} else {
mu_diff = diffuse_radiation.get(0);
sigma_diff = diffuse_radiation.get(1);
PDP_diff = diffuse_radiation.get(2);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "shadowing"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string shadow_str((char*) xmlKey);
vec shadowing = vec(shadow_str);
if (shadowing.length() != 2) {
ERROR("getParamsFromXML(): incorrect shadowing parameters!");
return;
} else {
sigma_sf = shadowing.get(0);
L_sf = shadowing.get(1);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "spread"))) {
spreadNodes = stChannelNodes->xmlChildrenNode;
while (spreadNodes != NULL) {
if ((!xmlStrcmp(spreadNodes->name, BAD_CAST "delay"))) {
xmlKey = xmlNodeGetContent(spreadNodes);
string delay_str((char*) xmlKey);
vec delay = vec(delay_str);
if (delay.length() != 3) {
ERROR("getParamsFromXML(): incorrect delay spread!");
return;
} else {
mu_tau = delay.get(0);
sigma_tau = delay.get(1);
L_tau = delay.get(2);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(spreadNodes->name, BAD_CAST "AoD"))) {
xmlKey = xmlNodeGetContent(spreadNodes);
string aod_str((char*) xmlKey);
vec aod = vec(aod_str);
if (aod.length() != 3) {
ERROR("getParamsFromXML(): incorrect AoD spread!");
return;
} else {
mu_phi_BS = aod.get(0);
sigma_phi_BS = aod.get(1);
L_phi_BS = aod.get(2);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(spreadNodes->name, BAD_CAST "EoD"))) {
xmlKey = xmlNodeGetContent(spreadNodes);
string eod_str((char*) xmlKey);
vec eod = vec(eod_str);
if (eod.length() != 3) {
ERROR("getParamsFromXML(): incorrect EoD spread!");
return;
} else {
mu_theta_BS = eod.get(0);
sigma_theta_BS = eod.get(1);
L_theta_BS = eod.get(2);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(spreadNodes->name, BAD_CAST "AoA"))) {
xmlKey = xmlNodeGetContent(spreadNodes);
string aoa_str((char*) xmlKey);
vec aoa = vec(aoa_str);
if (aoa.length() != 3) {
ERROR("getParamsFromXML(): incorrect AoA spread!");
return;
} else {
mu_phi_MS = aoa.get(0);
sigma_phi_MS = aoa.get(1);
L_phi_MS = aoa.get(2);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(spreadNodes->name, BAD_CAST "EoA"))) {
xmlKey = xmlNodeGetContent(spreadNodes);
string eoa_str((char*) xmlKey);
vec eoa = vec(eoa_str);
if (eoa.length() != 3) {
ERROR("getParamsFromXML(): incorrect EoA spread!");
return;
} else {
mu_theta_MS = eoa.get(0);
sigma_theta_MS = eoa.get(1);
L_theta_MS = eoa.get(2);
}
xmlFree(xmlKey);
}
spreadNodes = spreadNodes->next;
}
xmlFree(spreadNodes);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "crossCorrelation"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string x_corr_str((char*) xmlKey);
x_corr_matrix = chol(mat(x_corr_str));
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "cluster"))) {
clusterNodes = stChannelNodes->xmlChildrenNode;
while (clusterNodes != NULL) {
if ((!xmlStrcmp(clusterNodes->name, BAD_CAST "azimuth"))) {
xmlKey = xmlNodeGetContent(clusterNodes);
string azimuth_str((char*) xmlKey);
vec azimuth = vec(azimuth_str);
if (azimuth.length() != 3) {
ERROR("getParamsFromXML(): incorrect azimuth parameters of cluster to visibility region!");
return;
} else {
phi_C = azimuth.get(0, 1);
pdf_phi_C = (azimuth.get(2)==0) ? NORMAL : UNIFORM;
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(clusterNodes->name, BAD_CAST "elevation"))) {
xmlKey = xmlNodeGetContent(clusterNodes);
string elevation_str((char*) xmlKey);
vec elevation = vec(elevation_str);
if (elevation.length() != 3) {
ERROR("getParamsFromXML(): incorrect elevation parameters of cluster to visibility region!");
return;
} else {
theta_C = elevation.get(0, 1);
pdf_theta_C = (elevation.get(2)==0) ? NORMAL : UNIFORM;
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(clusterNodes->name, BAD_CAST "distance"))) {
xmlKey = xmlNodeGetContent(clusterNodes);
string distance_str((char*) xmlKey);
vec distance = vec(distance_str);
if (distance.length() != 3) {
ERROR("getParamsFromXML(): incorrect distance parameters of cluster to visibility region!");
return;
} else {
r_C = distance.get(0, 1);
pdf_r_C = (distance.get(2)==0) ? NORMAL : UNIFORM;
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(clusterNodes->name, BAD_CAST "linkDelay"))) {
xmlKey = xmlNodeGetContent(clusterNodes);
string link_str((char*) xmlKey);
vec link = vec(link_str);
if (link.length() != 2) {
ERROR("getParamsFromXML(): incorrect link delay parameters of cluster to visibility region!");
return;
} else {
mu_tau_C = link.get(0);
sigma_tau_C = link.get(1);
}
xmlFree(xmlKey);
}
clusterNodes = clusterNodes->next;
}
xmlFree(clusterNodes);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "polarization"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string xpd_str((char*) xmlKey);
vec xpd = vec(xpd_str);
if (xpd.length() != 6) {
ERROR("getParamsFromXML(): incorrect XPD parameters!");
return;
} else {
mu_xpdv = xpd.get(0);
sigma_xpdv = xpd.get(1);
mu_xpdh = xpd.get(2);
sigma_xpdh = xpd.get(3);
mu_cpr = xpd.get(4);
sigma_cpr = xpd.get(5);
}
xmlFree(xmlKey);
} else if ((!xmlStrcmp(stChannelNodes->name, BAD_CAST "dmc"))) {
xmlKey = xmlNodeGetContent(stChannelNodes);
string dmc_str((char*) xmlKey);
vec dmc = vec(dmc_str);
if (dmc.length() != 3) {
ERROR("getParamsFromXML(): incorrect DMC parameters!");
return;
} else {
mu_spread_dmc = dmc.get(0);
sigma_spread_dmc = dmc.get(1);
beta_dmc = dmc.get(2);
}
xmlFree(xmlKey);
}
stChannelNodes = stChannelNodes->next;
}
xmlFree(stChannelNodes);
std::cout << "Info: getParamsFromXML(): stochastic parameters loaded!" << std::endl;
}// TODO: add here for more parameter nodes
channelNodes = channelNodes->next;
}
xmlFree(channelNodes);
std::cout << "Info: getParamsFromXML(): Channel parameters loaded!" << std::endl;
}
curNode = curNode->next;
}
xmlFree(curNode);
xmlFreeDoc(doc);
std::cout << "Info: getParamsFromXML(): all file loaded!" << std::endl;
}
void Channel_Specification::update_MS_info() {
// calculate new MS positions
mat ms_pos_new = MS_info.get_MS_pos() + MS_info.get_MS_velo() * snapRate;
for (int i = 0; i < MS_info.get_MS_num(); i ++) {
Cluster local_cluster = (MS_info.get_MS_local_cluster())(i);
MPC local_mpc = local_cluster.get_cluster_MPC();
vec d_local_mpc_ms_new = calc_dist(ms_pos_new.get_row(i).get(0, 1), local_mpc.get_MPC_pos(MS).get_cols(0, 1));
// check for MPC re-calculation
for (int j = 0; j < d_local_mpc_ms_new.length(); j ++) {
vec new_mpc_tmp(3);
double d_mpc_tmp = d_local_mpc_ms_new.get(j);
if (d_mpc_tmp > local_cluster.get_cluster_spread(DELAY_AT_MS)) {
new_mpc_tmp = (randn(1, 3) * diag(local_cluster.get_cluster_spread_vec(MS) / 3)).get_row(0) + ms_pos_new.get_row(i);
d_mpc_tmp= calc_dist(new_mpc_tmp, ms_pos_new.get_row(i));
while (d_mpc_tmp > local_cluster.get_cluster_spread(DELAY_AT_MS)) {
new_mpc_tmp = (randn(1, 3) * diag(local_cluster.get_cluster_spread_vec(MS) / 3)).get_row(0) + ms_pos_new.get_row(i);
d_mpc_tmp= calc_dist(new_mpc_tmp, ms_pos_new.get_row(i));
}
local_mpc.update_MPC_pos(BS_MS, j, new_mpc_tmp);
}
}
local_cluster.update_cluster_MPC(local_mpc);
MS_info.update_MS_local_cluster(i, local_cluster);
}
MS_info.update_MS_pos(ms_pos_new);
std::cout << "Info: update_MS_info(): MS updated!" << std::endl;
}
Array<Cluster> Channel_Specification::init_local_clusters(SIDE_TYPE sd_type) {
int cluster_num;
CLUSTER_TYPE c_type;
mat pos;
switch (sd_type) {
case BS:
c_type = LOCAL_AT_BS;
cluster_num = BS_info.get_BS_num();
pos = BS_info.get_BS_pos();
break;
case MS:
c_type = LOCAL_AT_MS;
cluster_num = MS_info.get_MS_num();
pos = MS_info.get_MS_pos();
break;
default:
ERROR ("Error local cluster side type!");
break;
}
Array<Cluster> clusters(cluster_num);
mat corr_randn;
vec shadow_factor, tau_C, theta_C_BS, phi_C_BS, theta_C_MS, phi_C_MS, d_tau; // spatial delay spread
init_cluster_params(cluster_num, corr_randn, shadow_factor, tau_C, theta_C_BS, phi_C_BS, theta_C_MS, phi_C_MS, d_tau);
// calculate parameters of each cluster
for (int i = 0; i < cluster_num; i ++) {
vec current_pos = pos.get_row(i);
double current_d_tau = d_tau.get(i);
vec local_spread;
local_spread.ins(0, current_d_tau);
local_spread.ins(1, current_d_tau);
local_spread.ins(2, current_d_tau / 20);
MPC local_mpc = get_MPC(c_type, current_pos, current_pos, local_spread, zeros(2), zeros(2));
clusters(i) = Cluster(c_type, current_pos, current_pos, repmat(local_spread, 2), shadow_factor.get(i), 0, zeros(4), local_mpc);
}
return clusters;
}
Array<Cluster> Channel_Specification::init_far_clusters() {
int cluster_num = max(MSCC);
Array<Cluster> clusters(cluster_num);
mat corr_randn;
vec shadow_factor, tau_C, theta_C_BS, phi_C_BS, theta_C_MS, phi_C_MS, d_tau; // spatial delay spread
init_cluster_params(cluster_num, corr_randn, shadow_factor, tau_C, theta_C_BS, phi_C_BS, theta_C_MS, phi_C_MS, d_tau);
// calculate parameters of each cluster
for (int i = 0; i < cluster_num; i ++) {
CLUSTER_TYPE c_type;
vec pos_C_BS, pos_C_MS, spread, vr_pos, bs_pos;// activity
get_ref_BS_VR(i, bs_pos, vr_pos);
vec VR_direct = vr_pos - bs_pos;
VR_direct.set(2, 0);
vec VR_sph1 = coordinate_transformation(VR_direct, CART2SPH);
vec VR_sph2;
VR_sph2.ins(0, VR_sph1.get(0) + get_random_number(pdf_phi_C , phi_C));