-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathrandom_channel.c
More file actions
2352 lines (2027 loc) · 88 KB
/
random_channel.c
File metadata and controls
2352 lines (2027 loc) · 88 KB
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
/*
* SPDX-License-Identifier: LicenseRef-CSSL-1.0
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <complex.h>
#include "PHY/TOOLS/tools_defs.h"
#include "sim.h"
#include "scm_corrmat.h"
#include "common/config/config_userapi.h"
#include "common/utils/telnetsrv/telnetsrv.h"
#include "common/utils/load_module_shlib.h"
//#define DEBUG_CH
//#define DEBUG_CH_POWER
//#define DOPPLER_DEBUG
#include "assertions.h"
extern void print_shorts(char *s,simde__m128i *x);
static mapping channelmod_names[] = {
CHANNELMOD_MAP_INIT
};
static char *module_id_str[] = MODULEID_STR_INIT;
static int channelmod_show_cmd(char *buff, int debug, telnet_printfunc_t prnt);
static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt);
static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt);
int get_modchannel_index(char *buf, int debug, void *vdata, telnet_printfunc_t prnt);
int get_channel_params(const char *buf, int debug, void *tdata, telnet_printfunc_t prnt);
int get_currentchannels_type(const char *buf, int debug, void *vdata, telnet_printfunc_t prnt);
#define HELP_WEBIF_MODIFCHAN_STRING "<channel index>"
static telnetshell_cmddef_t channelmod_cmdarray[] = {
{"help", "", channelmod_print_help, {NULL}, 0, NULL},
{"show", "<predef,current>", channelmod_show_cmd, {NULL}, TELNETSRV_CMDFLAG_TELNETONLY, NULL},
{"show predef", "", channelmod_show_cmd, {NULL}, TELNETSRV_CMDFLAG_WEBSRVONLY, NULL},
{"show current", "", channelmod_show_cmd, {NULL}, TELNETSRV_CMDFLAG_WEBSRVONLY, NULL},
{"modify", "<channelid> <param> <value>", channelmod_modify_cmd, {NULL}, TELNETSRV_CMDFLAG_TELNETONLY, NULL},
{"show params", "<channelid> <param> <value>", channelmod_modify_cmd, {.webfunc_getdata = get_currentchannels_type}, TELNETSRV_CMDFLAG_GETWEBTBLDATA | TELNETSRV_CMDFLAG_WEBSRV_SETRETURNTBL, NULL},
{"show channelid",
HELP_WEBIF_MODIFCHAN_STRING,
channelmod_modify_cmd,
{.webfunc_getdata = get_channel_params},
TELNETSRV_CMDFLAG_NEEDPARAM | TELNETSRV_CMDFLAG_WEBSRVONLY | TELNETSRV_CMDFLAG_GETWEBTBLDATA,
NULL},
{"", "", NULL, {NULL}, 0, NULL},
};
static telnetshell_vardef_t channelmod_vardef[] = {{"", 0, 0, NULL}};
static unsigned int max_chan;
static channel_desc_t **defined_channels;
static char *modellist_name;
static int noise_power_dBFS = INVALID_DBFS_VALUE;
void fill_channel_desc(channel_desc_t *chan_desc,
uint8_t nb_tx,
uint8_t nb_rx,
uint8_t nb_taps,
uint8_t channel_length,
double *amps,
double *delays,
struct complexd *R_sqrt,
double Td,
double sampling_rate,
double channel_bandwidth,
double ricean_factor,
double aoa,
double forgetting_factor,
double max_Doppler,
uint64_t channel_offset,
double path_loss_dB,
uint8_t random_aoa)
{
uint16_t i,j;
double delta_tau;
LOG_I(OCM,"[CHANNEL] Getting new channel descriptor, nb_tx %d, nb_rx %d, nb_taps %d, channel_length %d\n",
nb_tx,nb_rx,nb_taps,channel_length);
chan_desc->nb_tx = nb_tx;
chan_desc->nb_rx = nb_rx;
chan_desc->nb_taps = nb_taps;
chan_desc->channel_length = channel_length;
chan_desc->amps = amps;
LOG_D(OCM,"[CHANNEL] Doing delays ...\n");
if (delays==NULL) {
chan_desc->delays = calloc(nb_taps, sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_DELAY ;
delta_tau = Td/nb_taps;
for (i=0; i<nb_taps; i++)
chan_desc->delays[i] = ((double)i)*delta_tau;
} else
chan_desc->delays = delays;
chan_desc->Td = Td;
chan_desc->sampling_rate = sampling_rate;
chan_desc->channel_bandwidth = channel_bandwidth;
chan_desc->ricean_factor = ricean_factor;
chan_desc->aoa = aoa;
chan_desc->random_aoa = random_aoa;
chan_desc->forgetting_factor = forgetting_factor;
chan_desc->channel_offset = channel_offset;
chan_desc->path_loss_dB = path_loss_dB;
chan_desc->first_run = 1;
chan_desc->ip = 0.0;
chan_desc->max_Doppler = max_Doppler;
chan_desc->Doppler_phase_cur = calloc(nb_rx, sizeof(double));
chan_desc->ch = calloc(nb_tx*nb_rx, sizeof(struct complexd *));
chan_desc->chF = calloc(nb_tx*nb_rx, sizeof(struct complexd *));
chan_desc->a = calloc(nb_taps, sizeof(struct complexd *));
LOG_D(OCM,"[CHANNEL] Filling ch \n");
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = calloc(channel_length, sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = calloc(275 * 12, sizeof(struct complexd)); // allocate for up to 275 RBs, 12 symbols per RB
LOG_D(OCM,"[CHANNEL] Filling a (nb_taps %d)\n",nb_taps);
for (i = 0; i<nb_taps; i++) {
LOG_D(OCM,"tap %d (%p,%zu)\n",i,&chan_desc->a[i],nb_tx*nb_rx * sizeof(struct complexd));
chan_desc->a[i] = calloc(nb_tx*nb_rx, sizeof(struct complexd));
}
LOG_D(OCM,"[CHANNEL] Doing R_sqrt ...\n");
if (R_sqrt == NULL) {
chan_desc->R_sqrt = (struct complexd **) calloc(nb_taps,sizeof(struct complexd *));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_RSQRT_NTAPS ;
for (i = 0; i<nb_taps; i++) {
chan_desc->R_sqrt[i] = (struct complexd *) calloc(nb_tx*nb_rx*nb_tx*nb_rx,sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].r = 1.0;
chan_desc->R_sqrt[i][j].i = 0.0;
}
}
} else {
chan_desc->R_sqrt = (struct complexd **) calloc(nb_taps,sizeof(struct complexd *));
for (i = 0; i<nb_taps; i++) {
//chan_desc->R_sqrt[i] = (struct complexd*) calloc(nb_tx*nb_rx*nb_tx*nb_rx,sizeof(struct complexd));
//chan_desc->R_sqrt = (struct complexd*)&R_sqrt[i][0];
/* all chan_desc share the same R_sqrt, coming from caller */
chan_desc->R_sqrt[i] = R_sqrt;
}
}
for (i = 0; i<nb_taps; i++) {
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
LOG_D(OCM,"Rsqrt[%d][%d] %f %f\n",i,j,chan_desc->R_sqrt[i][j].r,chan_desc->R_sqrt[i][j].i);
}
}
LOG_D(OCM,"[CHANNEL] RF %f\n",chan_desc->ricean_factor);
for (i=0; i<chan_desc->nb_taps; i++)
LOG_D(OCM,"[CHANNEL] tap %d: amp %f, delay %f\n",i,chan_desc->amps[i],chan_desc->delays[i]);
chan_desc->nb_paths=10;
reset_meas(&chan_desc->random_channel);
reset_meas(&chan_desc->interp_time);
reset_meas(&chan_desc->interp_freq);
reset_meas(&chan_desc->convolution);
}
static double mbsfn_delays[] = {0,.03,.15,.31,.37,1.09,12.490,12.52,12.64,12.80,12.86,13.58,27.49,27.52,27.64,27.80,27.86,28.58};
static double mbsfn_amps_dB[] = {0,-1.5,-1.4,-3.6,-0.6,-7.0,-10,-11.5,-11.4,-13.6,-10.6,-17.0,-20,-21.5,-21.4,-23.6,-20.6,-27};
static double scm_c_delays[] = {0, 0.0125, 0.0250, 0.3625, 0.3750, 0.3875, 0.2500, 0.2625, 0.2750, 1.0375, 1.0500, 1.0625, 2.7250, 2.7375, 2.7500, 4.6000, 4.6125, 4.6250};
static double scm_c_amps_dB[] = {0.00, -2.22, -3.98, -1.86, -4.08, -5.84, -1.08, -3.30, -5.06, -9.08, -11.30, -13.06, -15.14, -17.36, -19.12, -20.64, -22.85, -24.62};
// TS 38.104 - Table G.2.1.1-2, delays normalized based on TR 38.901 - eq. 7.7-1
static double tdl_a_delays[] = {0, 0.3333, 0.5000, 0.6667, 0.8333, 1.6667, 2.1667, 2.5000, 3.5000, 4.5000, 5.0000, 9.6667};
static double tdl_a_amps_dB[] = {-15.5, 0.0, -5.1, -5.1, -9.6, -8.2, -13.1, -11.5, -11.0, -16.2, -16.6, -26.2};
// TS 38.104 - Table G.2.1.1-3, delays normalized based on TR 38.901 - eq. 7.7-1
static double tdl_b_delays[] = {0.0000, 0.1000, 0.2000, 0.3000, 0.3500, 0.4500, 0.5500, 1.2000, 1.7000, 2.4500, 3.3000, 4.8000};
static double tdl_b_amps_dB[] = {0.0, -2.2, -0.6, -0.6, -0.3, -1.2, -5.9, -2.2, -0.8, -6.3, -7.5, -7.1};
// TS 38.104 - Table G.2.1.1-4, delays normalized based on TR 38.901 - eq. 7.7-1
static double tdl_c_delays[] = {0.0000, 0.2167, 0.2333, 0.6333, 0.6500, 0.6667, 0.8000, 1.0833, 1.7333, 3.4833, 5.0333, 8.6500};
static double tdl_c_amps_dB[] = {-6.9, 0.0, -7.7, -2.5, -2.4, -9.9, -8.0, -6.6, -7.1, -13.0, -14.2, -16.0};
static double tdl_d_delays[] = {//0,
0,
0.035,
0.612,
1.363,
1.405,
1.804,
2.596,
1.775,
4.042,
7.937,
9.424,
9.708,
12.525
};
static double tdl_d_amps_dB[] = {//-0.2,
//-13.5,
-.00147,
-18.8,
-21,
-22.8,
-17.9,
-20.1,
-21.9,
-22.9,
-27.8,
-23.6,
-24.8,
-30.0,
-27.7
};
#define TDL_D_RICEAN_FACTOR .046774
static double tdl_e_delays[] = {0,
0.5133,
0.5440,
0.5630,
0.5440,
0.7112,
1.9092,
1.9293,
1.9589,
2.6426,
3.7136,
5.4524,
12.0034,
20.6519
};
static double tdl_e_amps_dB[] = {//-0.03,
//-22.03,
-.00433,
-15.8,
-18.1,
-19.8,
-22.9,
-22.4,
-18.6,
-20.8,
-22.6,
-22.3,
-25.6,
-20.2,
-29.8,
-29.2
};
#define TDL_E_RICEAN_FACTOR 0.0063096
static double epa_delays[] = { 0,.03,.07,.09,.11,.19,.41};
static double epa_amps_dB[] = {0.0,-1.0,-2.0,-3.0,-8.0,-17.2,-20.8};
static double eva_delays[] = { 0,.03,.15,.31,.37,.71,1.09,1.73,2.51};
static double eva_amps_dB[] = {0.0,-1.5,-1.4,-3.6,-0.6,-9.1,-7.0,-12.0,-16.9};
static double etu_delays[] = { 0,.05,.12,.2,.23,.5,1.6,2.3,5.0};
static double etu_amps_dB[] = {-1.0,-1.0,-1.0,0.0,0.0,0.0,-3.0,-5.0,-7.0};
static double default_amps_lin[] = {0.3868472, 0.3094778, 0.1547389, 0.0773694, 0.0386847, 0.0193424, 0.0096712, 0.0038685};
static double default_amp_lin[] = {1};
//correlation matrix for a 2x2 channel with full Tx correlation
static struct complexd R_sqrt_22_corr[16] = {{0.70711,0}, {0.0, 0.0}, {0.70711,0}, {0.0, 0.0},
{0.0, 0.0}, {0.70711,0}, {0.0, 0.0}, {0.70711,0},
{0.70711,0}, {0.0, 0.0}, {0.70711,0}, {0.0, 0.0},
{0.0, 0.0}, {0.70711,0}, {0.0, 0.0}, {0.70711,0}
};
//correlation matrix for a fully correlated 2x1 channel (h1==h2)
static struct complexd R_sqrt_21_corr[] = {{0.70711,0}, {0.70711,0}, {0.70711,0}, {0.70711,0}};
//correlation matrix for a 2x2 channel with full Tx anti-correlation
static struct complexd R_sqrt_22_anticorr[16] = {{0.70711,0}, {0.0, 0.0}, {-0.70711,0}, {0.0, 0.0},
{0.0, 0.0}, {0.70711,0}, {0.0, 0.0}, {-0.70711,0},
{-0.70711,0}, {0.0, 0.0}, {0.70711,0}, {0.0, 0.0},
{0.0, 0.0}, {-0.70711,0}, {0.0, 0.0}, {0.70711,0}
};
//correlation matrix for a fully anti-correlated 2x1 channel (h1==-h2)
static struct complexd R_sqrt_21_anticorr[4] = {{0.70711,0}, {-0.70711,0}, {-0.70711,0}, {0.70711,0}};
// full correlation matrix in vectorized form for 2x2 channel, where h1 is perfectly orthogonal to h2
static struct complexd R_sqrt_22_orthogonal[16] = {{0.70711,0.0}, {0.0, 0.0}, {0.0,0.0}, {0.0, 0.0},
{0.0, 0.0}, {0.0,0.0}, {0.0, 0.0}, {0.0,0.0},
{0.0,0.0}, {0.0, 0.0}, {0.0,0.0}, {0.0, 0.0},
{0.0, 0.0}, {0.0,0.0}, {0.0, 0.0}, {0.70711,0.0}
};
// full correlation matrix for TM4 to make orthogonal effective channel
static struct complexd R_sqrt_22_orth_eff_ch_TM4_prec_real[16] = {{0.70711,0.0}, {0.0, 0.0}, {0.70711,0.0}, {0.0, 0.0},
{0.0, 0.0}, {0.70711,0.0}, {0.0, 0.0}, {-0.70711,0.0},
{0.70711,0.0}, {0.0, 0.0}, {0.70711,0.0}, {0.0, 0.0},
{0.0, 0.0}, {-0.70711,0.0}, {0.0, 0.0}, {0.70711,0.0}
};
static struct complexd R_sqrt_22_orth_eff_ch_TM4_prec_imag[16] = {{0.70711,0.0}, {0.0,0.0}, {0.0, -0.70711}, {0.0,0.0},
{0.0, 0.0}, {0.70711,0.0}, {0.0, 0.0}, {0.0,0.70711},
{0.0,-0.70711}, {0.0, 0.0}, {-0.70711,0.0}, {0.0, 0.0},
{0.0, 0.0}, {0.0,0.70711}, {0.0, 0.0}, {-0.70711,0.0}
};
//Correlation matrix for EPA channel
static struct complexd R_sqrt_22_EPA_low[16] = {{1.0,0.0}, {0.0,0.0}, {0.0,0.0}, {0.0,0.0},
{0.0,0.0}, {1.0,0.0}, {0.0,0.0}, {0.0,0.0},
{0.0,0.0}, {0.0,0.0}, {1.0,0.0}, {0.0,0.0},
{0.0,0.0}, {0.0,0.0}, {0.0,0.0}, {1.0,0.0}
};
static struct complexd R_sqrt_22_EPA_high[16] = {
{0.7179,0.0}, {0.4500,0.0}, {0.4500,0.0}, {0.2821,0.0},
{0.4500,0.0}, {0.7179,0.0}, {0.2821,0.0}, {0.4500,0.0},
{0.4500,0.0}, {0.2821,0.0}, {0.7179,0.0}, {0.4500,0.0},
{0.2821,0.0}, {0.4500,0.0}, {0.4500,0.0}, {0.7179,0.0}
};
static struct complexd R_sqrt_22_EPA_medium[16] = {{0.8375,0.0}, {0.5249,0.0}, {0.1286,0.0}, {0.0806,0.0},
{0.5249,0.0}, {0.8375,0.0}, {0.0806,0.0}, {0.1286,0.0},
{0.1286,0.0}, {0.0806,0.0}, {0.8375,0.0}, {0.5249,0.0},
{0.0806,0.0}, {0.1286,0.0}, {0.5249,0.0}, {0.8375,0.0}
};
//Rayleigh1_orth_eff_ch_TM4
void tdlModel(int tdl_paths, double *tdl_delays, double *tdl_amps_dB, double DS_TDL, channel_desc_t *chan_desc ) {
int nb_rx=chan_desc-> nb_rx;
int nb_tx=chan_desc-> nb_tx;
chan_desc->nb_taps = tdl_paths;
chan_desc->Td = tdl_delays[tdl_paths-1]*DS_TDL;
printf("last path (%d) at %f * %e = %e\n",tdl_paths-1,tdl_delays[tdl_paths-1],DS_TDL,chan_desc->Td);
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td +
1 +
2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
printf("TDL : %f Ms/s, nb_taps %d, Td %e, channel_length %d\n",chan_desc->sampling_rate,tdl_paths,chan_desc->Td,chan_desc->channel_length);
double sum_amps = 0;
chan_desc->amps = calloc(chan_desc->nb_taps, sizeof(double));
for (int i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*tdl_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (int i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] /= sum_amps;
tdl_delays[i] *= DS_TDL;
}
chan_desc->delays = tdl_delays;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = calloc(nb_tx*nb_rx, sizeof(struct complexd *));
chan_desc->chF = calloc(nb_tx*nb_rx, sizeof(struct complexd *));
chan_desc->a = calloc(chan_desc->nb_taps, sizeof(struct complexd *));
chan_desc->ricean_factor = 1.0;
for (int i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = calloc(chan_desc->channel_length, sizeof(struct complexd));
for (int i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = calloc(2+(275*12), sizeof(struct complexd));
for (int i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = calloc(nb_tx*nb_rx, sizeof(struct complexd));
int matrix_size = nb_tx*nb_rx;
double *correlation_matrix[matrix_size];
if (chan_desc->corr_level!=CORR_LEVEL_LOW) {
if (nb_rx==1 && nb_tx==2) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R12_medium_high[row];
}
} else if (nb_rx==1 && nb_tx==4) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R14_medium_high[row];
}
} else if (nb_rx==1 && nb_tx==8) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R18_medium_high[row];
}
} else if (nb_rx==2 && nb_tx==2 && chan_desc->corr_level==CORR_LEVEL_MEDIUM) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R22_medium[row];
}
} else if (nb_rx==2 && nb_tx==4 && chan_desc->corr_level==CORR_LEVEL_MEDIUM) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R24_medium[row];
}
} else if (nb_rx==4 && nb_tx==4 && chan_desc->corr_level==CORR_LEVEL_MEDIUM) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R44_medium[row];
}
} else if (nb_rx==2 && nb_tx==2 && chan_desc->corr_level==CORR_LEVEL_HIGH) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R22_high[row];
}
} else if (nb_rx==2 && nb_tx==4 && chan_desc->corr_level==CORR_LEVEL_HIGH) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R24_high[row];
}
} else if (nb_rx==4 && nb_tx==4 && chan_desc->corr_level==CORR_LEVEL_HIGH) {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = R44_high[row];
}
} else {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = NULL;
}
}
} else {
for (int row = 0; row < matrix_size; row++) {
correlation_matrix[row] = NULL;
}
}
chan_desc->R_sqrt = calloc(matrix_size, sizeof(*chan_desc->R_sqrt));
for (int row = 0; row < matrix_size; row++) {
chan_desc->R_sqrt[row] = calloc(matrix_size, sizeof(**chan_desc->R_sqrt));
if (correlation_matrix[row] == NULL) {
// TS 38.104 - Table G.2.3.1.2-4: MIMO correlation matrices for low correlation
chan_desc->R_sqrt[row][row].r = 1.0;
} else {
for (int col = 0; col < matrix_size; col++) {
chan_desc->R_sqrt[row][col].r = correlation_matrix[row][col];
}
}
}
}
void get_cexp_doppler(struct complexd *cexp_doppler, channel_desc_t *chan_desc, const uint32_t length)
{
// TS 38.104 - Table G.3-1
uint16_t Dmin = 2;
uint16_t Ds = 300;
double v = chan_desc->max_Doppler * ((double) SPEED_OF_LIGHT / (double)chan_desc->center_freq);
#ifdef DOPPLER_DEBUG
printf("v = %f\n", v);
#endif
double phase0 = 2 * M_PI * uniformrandom();
double cos_theta[length];
double fs[length];
for (uint32_t t_idx = 0; t_idx < length; t_idx++) {
double t = t_idx / (chan_desc->sampling_rate * 1e6);
if (t >= 0 && t <= Ds / v) {
cos_theta[t_idx] = (Ds / 2 - v * t) / sqrt(Dmin * Dmin + (Ds / 2 - v * t) * (Ds / 2 - v * t));
} else if (t > Ds / v && t <= 2 * Ds / v) {
cos_theta[t_idx] = (-1.5 * Ds + v * t) / sqrt(Dmin * Dmin + (-1.5 * Ds + v * t) * (-1.5 * Ds + v * t));
} else {
cos_theta[t_idx] = cos(fmod(t, 2 * Ds / v));
}
fs[t_idx] = chan_desc->max_Doppler * cos_theta[t_idx];
double complex tmp_cexp_doppler = cexp(I * (2 * M_PI * fs[t_idx] * t + phase0));
cexp_doppler[t_idx].r = creal(tmp_cexp_doppler);
cexp_doppler[t_idx].i = cimag(tmp_cexp_doppler);
#ifdef DOPPLER_DEBUG
printf("(%2u) t_us = %f, cos_theta = %f, fs = %f, cexp_doppler = (%f, %f)\n", t_idx, t * 1e6, cos_theta[t_idx], fs[t_idx], cexp_doppler[t_idx].r, cexp_doppler[t_idx].i);
#endif
}
}
double get_normalization_ch_factor(channel_desc_t *desc)
{
if (!(desc->channel_length > 1 && desc->modelid >= TDL_A && desc->modelid <= TDL_E)) {
return 1.0;
}
uint16_t N_average = 1000;
double accumulated_ch_power = 0;
struct complexd a[desc->nb_taps][desc->nb_tx * desc->nb_rx];
struct complexd anew[desc->nb_tx * desc->nb_rx];
struct complexd acorr[desc->nb_tx * desc->nb_rx];
for (int n = 1; n <= N_average; n++) {
for (int l = 0; l < (int)desc->nb_taps; l++) {
for (int aarx = 0; aarx < desc->nb_rx; aarx++) {
for (int aatx = 0; aatx < desc->nb_tx; aatx++) {
struct complexd *anewp = &anew[aarx + (aatx * desc->nb_rx)];
anewp->r = sqrt(desc->ricean_factor * desc->amps[l] / 2) * gaussZiggurat(0.0, 1.0);
anewp->i = sqrt(desc->ricean_factor * desc->amps[l] / 2) * gaussZiggurat(0.0, 1.0);
if ((l == 0) && (desc->ricean_factor != 1.0)) {
anew[aarx + (aatx * desc->nb_rx)].r += sqrt((1.0 - desc->ricean_factor) / 2);
anew[aarx + (aatx * desc->nb_rx)].i += sqrt((1.0 - desc->ricean_factor) / 2);
}
} // for (int aatx = 0; aatx < desc->nb_tx; aatx++)
} // for (int aarx = 0; aarx < desc->nb_rx; aarx++)
// Apply correlation matrix
bzero(acorr, desc->nb_tx * desc->nb_rx * sizeof(struct complexd));
for (int aatx = 0; aatx < desc->nb_tx; aatx++) {
for (int aarx = 0; aarx < desc->nb_rx; aarx++) {
for (int inside = 0; inside < desc->nb_tx * desc->nb_rx; inside++) {
const cd_t tmp = cdMul(anew[aarx + aatx * desc->nb_rx], desc->R_sqrt[aarx + aatx * desc->nb_rx][inside]);
csum(acorr[inside], tmp, acorr[inside]);
}
} // for (int aarx = 0; aarx < desc->nb_rx; aarx++)
} // for (int aatx = 0; aatx < desc->nb_tx; aatx++)
memcpy(a[l], acorr, desc->nb_tx * desc->nb_rx * sizeof(*acorr));
} // for (int l = 0; l < (int)desc->nb_taps; l++)
for (int aarx = 0; aarx < desc->nb_rx; aarx++) {
for (int aatx = 0; aatx < desc->nb_tx; aatx++) {
for (int k = 0; k < (int)desc->channel_length; k++) {
double ch_r = 0.0;
double ch_i = 0.0;
double s = 0.0;
for (int l = 0; l < desc->nb_taps; l++) {
if ((k - (desc->delays[l] * desc->sampling_rate) - desc->channel_offset) == 0) {
s = 1.0;
} else {
s = sin(M_PI * (k - (desc->delays[l] * desc->sampling_rate) - desc->channel_offset)) /
(M_PI * (k - (desc->delays[l] * desc->sampling_rate) - desc->channel_offset));
}
ch_r += s * a[l][aarx + (aatx * desc->nb_rx)].r;
ch_i += s * a[l][aarx + (aatx * desc->nb_rx)].i;
} // for (int l = 0; l < desc->nb_taps; l++)
accumulated_ch_power += (ch_r * ch_r + ch_i * ch_i);
} // for (int k = 0; k < (int)desc->channel_length; k++)
} // for (int aatx = 0; aatx < desc->nb_tx; aatx++)
} // for (int aarx = 0; aarx < desc->nb_rx; aarx++)
}
return sqrt((N_average * desc->nb_tx * desc->nb_rx) / accumulated_ch_power);
}
channel_desc_t *new_channel_desc_scm(uint8_t nb_tx,
uint8_t nb_rx,
SCM_t channel_model,
double sampling_rate,
uint64_t center_freq,
double channel_bandwidth,
double DS_TDL,
double maxDoppler,
const corr_level_t corr_level,
double forgetting_factor,
uint64_t channel_offset,
double path_loss_dB,
float noise_power_dB)
{
channel_desc_t *chan_desc = (channel_desc_t *)calloc(1,sizeof(channel_desc_t));
for(int i=0; i<max_chan; i++) {
if (defined_channels[i] == NULL) {
defined_channels[i]=chan_desc;
chan_desc->chan_idx=i;
break;
} else {
AssertFatal(i<(max_chan-1),
"No more channel descriptors available, increase channelmod.max_chan parameter above %u\n",max_chan);
}
}
uint16_t i,j;
double sum_amps;
double aoa, ricean_factor, Td;
int channel_length,nb_taps;
struct complexd *R_sqrt_ptr2;
chan_desc->modelid = channel_model;
chan_desc->nb_tx = nb_tx;
chan_desc->nb_rx = nb_rx;
chan_desc->sampling_rate = sampling_rate;
chan_desc->center_freq = center_freq;
chan_desc->channel_bandwidth = channel_bandwidth;
chan_desc->max_Doppler = maxDoppler;
chan_desc->corr_level = corr_level;
chan_desc->forgetting_factor = forgetting_factor;
chan_desc->channel_offset = channel_offset;
chan_desc->path_loss_dB = path_loss_dB;
chan_desc->first_run = 1;
chan_desc->ip = 0.0;
chan_desc->noise_power_dB = noise_power_dB;
chan_desc->normalization_ch_factor = 1.0;
LOG_I(OCM,"Channel Model (inside of new_channel_desc_scm)=%d\n\n", channel_model);
int tdl_paths=0;
double *tdl_amps_dB;
double *tdl_delays;
/* Spatial Channel Models (SCM) channel model from TR 38.901 Section 7.7.2 */
switch (channel_model) {
case SCM_A:
LOG_W(OCM,"channel model not yet supported\n");
free(chan_desc);
return(NULL);
case SCM_B:
LOG_W(OCM,"channel model not yet supported\n");
free(chan_desc);
return(NULL);
case SCM_C:
chan_desc->nb_taps = 18;
chan_desc->Td = 4.625;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = calloc(chan_desc->nb_taps, sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*scm_c_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = scm_c_delays;
chan_desc->ricean_factor = 1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = calloc(chan_desc->channel_length, sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = calloc(1200, sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = calloc(nb_tx*nb_rx, sizeof(struct complexd));
chan_desc->R_sqrt = calloc(6, sizeof(struct complexd **));
if (nb_tx==2 && nb_rx==2) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R22_sqrt[i][0];
} else if (nb_tx==2 && nb_rx==1) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R21_sqrt[i][0];
} else if (nb_tx==1 && nb_rx==2) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R12_sqrt[i][0];
} else {
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_RSQRT_6 ;
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = calloc(nb_tx*nb_rx*nb_tx*nb_rx, sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].r = 1.0;
chan_desc->R_sqrt[i][j].i = 0.0;
}
LOG_W(OCM,"correlation matrix not implemented for nb_tx==%d and nb_rx==%d, using identity\n", nb_tx, nb_rx);
}
}
break;
case SCM_D:
LOG_W(OCM,"This is not the real SCM-D model! It is just SCM-C with an additional Rice factor!\n");
chan_desc->nb_taps = 18;
chan_desc->Td = 4.625;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*scm_c_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = scm_c_delays;
chan_desc->ricean_factor = 0.1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd));
chan_desc->R_sqrt = (struct complexd **) malloc(6*sizeof(struct complexd **));
if (nb_tx==2 && nb_rx==2) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R22_sqrt[i][0];
} else if (nb_tx==2 && nb_rx==1) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R21_sqrt[i][0];
} else if (nb_tx==1 && nb_rx==2) {
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R12_sqrt[i][0];
} else {
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_RSQRT_6 ;
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = (struct complexd *) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].r = 1.0;
chan_desc->R_sqrt[i][j].i = 0.0;
}
LOG_W(OCM,"correlation matrix not implemented for nb_tx==%d and nb_rx==%d, using identity\n", nb_tx, nb_rx);
}
}
break;
/* tapped delay line (TDL) channel model from TR 38.901 Section 7.7.2 */
#define tdl_m(MoDel)\
DevAssert(sizeof(tdl_ ## MoDel ## _amps_dB) == sizeof(tdl_ ## MoDel ## _delays)); \
tdl_paths=sizeof(tdl_ ## MoDel ## _amps_dB)/sizeof(*tdl_ ## MoDel ## _amps_dB);\
tdl_delays=tdl_ ## MoDel ## _delays;\
tdl_amps_dB=tdl_ ## MoDel ## _amps_dB
case TDL_A:
chan_desc->ricean_factor = 1;
tdl_m(a);
tdlModel(tdl_paths, tdl_delays, tdl_amps_dB, DS_TDL, chan_desc);
break;
case TDL_B:
chan_desc->ricean_factor = 1;
tdl_m(b);
tdlModel(tdl_paths, tdl_delays, tdl_amps_dB, DS_TDL, chan_desc);
break;
case TDL_C:
chan_desc->ricean_factor = 1;
tdl_m(c);
tdlModel(tdl_paths, tdl_delays, tdl_amps_dB, DS_TDL, chan_desc);
break;
case TDL_D:
chan_desc->ricean_factor = TDL_D_RICEAN_FACTOR;
tdl_m(d);
tdlModel(tdl_paths, tdl_delays, tdl_amps_dB, DS_TDL, chan_desc);
break;
case TDL_E:
chan_desc->ricean_factor = TDL_E_RICEAN_FACTOR;
tdl_m(e);
tdlModel(tdl_paths, tdl_delays, tdl_amps_dB, DS_TDL, chan_desc);
break;
case EPA:
chan_desc->nb_taps = 7;
chan_desc->Td = .410;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*epa_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = epa_delays;
chan_desc->ricean_factor = 1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd));
if (nb_tx==2 && nb_rx==2) {
chan_desc->R_sqrt = (struct complexd **) malloc(6*sizeof(struct complexd **));
for (i = 0; i<6; i++)
chan_desc->R_sqrt[i] = (struct complexd *) &R22_sqrt[i][0];
} else {
chan_desc->R_sqrt = (struct complexd **) malloc(6*sizeof(struct complexd **));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_RSQRT_6 ;
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = (struct complexd *) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].r = 1.0;
chan_desc->R_sqrt[i][j].i = 0.0;
}
LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
}
}
break;
case EPA_low:
chan_desc->nb_taps = 7;
chan_desc->Td = .410;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*epa_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = epa_delays;
chan_desc->ricean_factor = 1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd));
if (nb_tx==2 && nb_rx==2) {
chan_desc->R_sqrt = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd **));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->R_sqrt[i] = R_sqrt_22_EPA_low;
} else {
printf("Correlation matrices are implemented for 2 x 2 only");
}
/*else {
chan_desc->R_sqrt = (struct complexd**) malloc(6*sizeof(struct complexd**));
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = (struct complexd*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].x = 1.0;
chan_desc->R_sqrt[i][j].y = 0.0;
}
LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
}
}*/
break;
case EPA_high:
chan_desc->nb_taps = 7;
chan_desc->Td = .410;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*epa_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = epa_delays;
chan_desc->ricean_factor = 1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd));
if (nb_tx==2 && nb_rx==2) {
chan_desc->R_sqrt = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd **));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->R_sqrt[i] = R_sqrt_22_EPA_high;
} else {
printf("Correlation matrices are implemented for 2 x 2 only");
}
/*else {
chan_desc->R_sqrt = (struct complexd**) malloc(6*sizeof(struct complexd**));
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = (struct complexd*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].x = 1.0;
chan_desc->R_sqrt[i][j].y = 0.0;
}
LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
}
}*/
break;
case EPA_medium:
chan_desc->nb_taps = 7;
chan_desc->Td = .410;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*epa_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->amps[i] /= sum_amps;
chan_desc->delays = epa_delays;
chan_desc->ricean_factor = 1;
chan_desc->aoa = 0;
chan_desc->random_aoa = 0;
chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *));
chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->ch[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd));
for (i = 0; i<nb_tx*nb_rx; i++)
chan_desc->chF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd));
if (nb_tx==2 && nb_rx==2) {
chan_desc->R_sqrt = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd **));
for (i = 0; i<chan_desc->nb_taps; i++)
chan_desc->R_sqrt[i] = R_sqrt_22_EPA_medium;
} else {
printf("Correlation matrices are implemented for 2 x 2 only");
}
/*else {
chan_desc->R_sqrt = (struct complexd**) malloc(6*sizeof(struct complexd**));
for (i = 0; i<6; i++) {
chan_desc->R_sqrt[i] = (struct complexd*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd));
for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
chan_desc->R_sqrt[i][j].x = 1.0;
chan_desc->R_sqrt[i][j].y = 0.0;
}
LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
}
}*/
break;
case EVA:
chan_desc->nb_taps = 9;
chan_desc->Td = 2.51;
chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td));
sum_amps = 0;
chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double));
chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ;
for (i = 0; i<chan_desc->nb_taps; i++) {
chan_desc->amps[i] = pow(10,.1*eva_amps_dB[i]);
sum_amps += chan_desc->amps[i];
}
for (i = 0; i<chan_desc->nb_taps; i++)