random_channel.c 56.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
20
 */
21

22
23
24
25
26
27
28
29
30
31
32
33
34
#include <math.h>
#include <cblas.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "PHY/TOOLS/defs.h"
#include "defs.h"
#include "scm_corrmat.h"
#include "UTIL/LOG/log.h"
//#define DEBUG_CH

35
36
extern void print_shorts(char *s,__m128i *x);

37
void fill_channel_desc(channel_desc_t *chan_desc,
38
39
40
41
42
43
44
45
                       uint8_t nb_tx,
                       uint8_t nb_rx,
                       uint8_t nb_taps,
                       uint8_t channel_length,
                       double *amps,
                       double *delays,
                       struct complex** R_sqrt,
                       double Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
46
                       double sampling_rate,
47
                       double channel_bandwidth,
48
49
50
51
52
53
54
55
56
                       double ricean_factor,
                       double aoa,
                       double forgetting_factor,
                       double max_Doppler,
                       int32_t channel_offset,
                       double path_loss_dB,
                       uint8_t random_aoa)
{

57

gauthier's avatar
gauthier committed
58
  uint16_t i,j;
59
60
61
  double delta_tau;

  LOG_I(OCM,"[CHANNEL] Getting new channel descriptor, nb_tx %d, nb_rx %d, nb_taps %d, channel_length %d\n",
Elena Lukashova's avatar
Elena Lukashova committed
62
      nb_tx,nb_rx,nb_taps,channel_length);
63
64
65
66
67
68
69
70
71
72
73
74

  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 = (double*) malloc(nb_taps*sizeof(double));
    delta_tau = Td/nb_taps;
    for (i=0; i<nb_taps; i++)
      chan_desc->delays[i] = ((double)i)*delta_tau;
Elena Lukashova's avatar
Elena Lukashova committed
75
76
  }
  else
77
  chan_desc->delays              = delays;
78
  chan_desc->Td                         = Td;
Elena Lukashova's avatar
Elena Lukashova committed
79
80
  chan_desc->sampling_rate              = sampling_rate;
  chan_desc->channel_bandwidth          = channel_bandwidth;
81
82
83
84
85
86
87
88
89
90
91
92
  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->ch                         = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
  chan_desc->chF                        = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
  chan_desc->a                          = (struct complex**) malloc(nb_taps*sizeof(struct complex*));
93
94
95

  LOG_D(OCM,"[CHANNEL] Filling ch \n");

96
97
  for (i = 0; i<nb_tx*nb_rx; i++)
    chan_desc->ch[i] = (struct complex*) malloc(channel_length * sizeof(struct complex));
98

99
  for (i = 0; i<nb_tx*nb_rx; i++)
100
101
102
103
    chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));  // allocate for up to 100 RBs, 12 samples per RB

  LOG_D(OCM,"[CHANNEL] Filling a (nb_taps %d)\n",nb_taps);
  for (i = 0; i<nb_taps; i++) {
104
    LOG_D(OCM,"tap %d (%p,%zu)\n",i,&chan_desc->a[i],nb_tx*nb_rx * sizeof(struct complex));
105
106
107
108
109
    chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
  }

  LOG_D(OCM,"[CHANNEL] Doing R_sqrt ...\n");
  if (R_sqrt == NULL) {
Elena Lukashova's avatar
Elena Lukashova committed
110
      chan_desc->R_sqrt         = (struct complex**) calloc(nb_taps,sizeof(struct complex*));
111
    for (i = 0; i<nb_taps; i++) {
Elena Lukashova's avatar
Elena Lukashova committed
112
        chan_desc->R_sqrt[i]    = (struct complex*) calloc(nb_tx*nb_rx*nb_tx*nb_rx,sizeof(struct complex));
113
      for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
114
115
        chan_desc->R_sqrt[i][j].x = 1.0;
        chan_desc->R_sqrt[i][j].y = 0.0;
116
117
118
119
      }
    }
  }
  else {
120
121
    chan_desc->R_sqrt = (struct complex**) calloc(nb_taps,sizeof(struct complex*));
    for (i = 0; i<nb_taps; i++) {
Cedric Roux's avatar
Cedric Roux committed
122
        //chan_desc->R_sqrt[i]    = (struct complex*) calloc(nb_tx*nb_rx*nb_tx*nb_rx,sizeof(struct complex));
123
        //chan_desc->R_sqrt = (struct complex*)&R_sqrt[i][0];
Cedric Roux's avatar
Cedric Roux committed
124
        /* all chan_desc share the same R_sqrt, coming from caller */
125
126
        chan_desc->R_sqrt[i] = R_sqrt[0];
        }
127
128
129
130
131
132
133
134
135
  }

  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].x,chan_desc->R_sqrt[i][j].y);
    }
  }

  LOG_D(OCM,"[CHANNEL] RF %f\n",chan_desc->ricean_factor);
Elena Lukashova's avatar
Elena Lukashova committed
136
  for (i=0;i<chan_desc->nb_taps;i++)
137
138
139
140
    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;

141
142
143
144
145
  reset_meas(&chan_desc->random_channel);
  reset_meas(&chan_desc->interp_time);
  reset_meas(&chan_desc->interp_freq);
  reset_meas(&chan_desc->convolution);

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
}

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};
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};

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};
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};

double epa_delays[] = { 0,.03,.07,.09,.11,.19,.41};
double epa_amps_dB[] = {0.0,-1.0,-2.0,-3.0,-8.0,-17.2,-20.8};

double eva_delays[] = { 0,.03,.15,.31,.37,.71,1.09,1.73,2.51};
double eva_amps_dB[] = {0.0,-1.5,-1.4,-3.6,-0.6,-9.1,-7.0,-12.0,-16.9};

double etu_delays[] = { 0,.05,.12,.2,.23,.5,1.6,2.3,5.0};
double etu_amps_dB[] = {-1.0,-1.0,-1.0,0.0,0.0,0.0,-3.0,-5.0,-7.0};

double default_amps_lin[] = {0.3868472 , 0.3094778 , 0.1547389 , 0.0773694 , 0.0386847 , 0.0193424 , 0.0096712 , 0.0038685};
double default_amp_lin[] = {1};

166
167
168
double ts_shift_delays[] = {0, 1/7.68};
double ts_shift_amps[] = {0, 1};

169
170
171
172
173
//correlation matrix for a 2x2 channel with full Tx correlation
struct complex R_sqrt_22_corr_tap[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}};
174
175
176
struct complex *R_sqrt_22_corr[1]     = {R_sqrt_22_corr_tap};

//correlation matrix for a fully correlated 2x1 channel (h1==h2)
177
struct complex R_sqrt_21_corr_tap[4]  = {{0.70711,0}, {0.70711,0}, {0.70711,0}, {0.70711,0}};
178
179
struct complex *R_sqrt_21_corr[1]      = {R_sqrt_21_corr_tap};

180
181
182
183
184
//correlation matrix for a 2x2 channel with full Tx anti-correlation
struct complex R_sqrt_22_anticorr_tap[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}};
185
186
187
struct complex *R_sqrt_22_anticorr[1]     = {R_sqrt_22_anticorr_tap};

//correlation matrix for a fully anti-correlated 2x1 channel (h1==-h2)
188
struct complex R_sqrt_21_anticorr_tap[4]  = {{0.70711,0}, {-0.70711,0}, {-0.70711,0}, {0.70711,0}};
189
190
191
192
struct complex *R_sqrt_21_anticorr[1]     = {R_sqrt_21_anticorr_tap};

struct complex **R_sqrt_ptr2;

193
194
// full correlation matrix in vectorized form for 2x2 channel, where h1 is  perfectly orthogonal to h2

195
196
197
198
struct complex R_sqrt_22_orthogonal_tap[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}};
199
200
201
202
203
204
205
struct complex *R_sqrt_22_orthogonal[1]     = {R_sqrt_22_orthogonal_tap};

// full correlation matrix for TM4 to make orthogonal effective channel




206
207
208
209
struct complex R_sqrt_22_orth_eff_ch_TM4_prec_real_tap[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}};
210
211
212
213
struct complex *R_sqrt_22_orth_eff_ch_TM4_prec_real[1]     = {R_sqrt_22_orth_eff_ch_TM4_prec_real_tap};



214

215
216
217
218
struct complex R_sqrt_22_orth_eff_ch_TM4_prec_imag_tap[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}};
219
220
struct complex *R_sqrt_22_orth_eff_ch_TM4_prec_imag[1]     = {R_sqrt_22_orth_eff_ch_TM4_prec_imag_tap};

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//Correlation matrix for EPA channel
struct complex R_sqrt_22_EPA_low_tap[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}};
struct complex *R_sqrt_22_EPA_low[1]     = {R_sqrt_22_EPA_low_tap};

struct complex R_sqrt_22_EPA_high_tap[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}};
struct complex *R_sqrt_22_EPA_high[1]     = {R_sqrt_22_EPA_high_tap};

struct complex R_sqrt_22_EPA_medium_tap[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}};
struct complex *R_sqrt_22_EPA_medium[1]     = {R_sqrt_22_EPA_medium_tap};

240
241
242


//Rayleigh1_orth_eff_ch_TM4
243

244
245
246
channel_desc_t *new_channel_desc_scm(uint8_t nb_tx,
                                     uint8_t nb_rx,
                                     SCM_t channel_model,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
247
                                     double sampling_rate,
248
                                     double channel_bandwidth,
249
250
251
252
                                     double forgetting_factor,
                                     int32_t channel_offset,
                                     double path_loss_dB)
{
253
254

  channel_desc_t *chan_desc = (channel_desc_t *)malloc(sizeof(channel_desc_t));
gauthier's avatar
gauthier committed
255
  uint16_t i,j;
256
257
258
259
  double sum_amps;
  double aoa,ricean_factor,Td,maxDoppler;
  int channel_length,nb_taps;

260
261
  chan_desc->nb_tx                      = nb_tx;
  chan_desc->nb_rx                      = nb_rx;
262
263
  chan_desc->sampling_rate              = sampling_rate;
  chan_desc->channel_bandwidth          = channel_bandwidth;
264
265
266
267
268
  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;
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

  LOG_I(OCM,"Channel Model (inside of new_channel_desc_scm)=%d\n\n", channel_model);

  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;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
284
    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));
285
286
287
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
288
      chan_desc->amps[i]      = pow(10,.1*scm_c_amps_dB[i]);
289
290
291
292
293
294
295
296
297
298
299
      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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
300
301
302
303
304
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
305
306
307
308
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));

    chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
    if (nb_tx==2 && nb_rx==2) {
309
310
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
311
312
    }
    else if (nb_tx==2 && nb_rx==1) {
313
314
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R21_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
315
316
    }
    else if (nb_tx==1 && nb_rx==2) {
317
318
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R12_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
319
320
    }
    else {
321
      for (i = 0; i<6; i++) {
322
323
324
325
326
327
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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 not implemented for nb_tx==%d and nb_rx==%d, using identity\n", nb_tx, nb_rx);
328
329
330
331
      }
    }
    break;
  case SCM_D:
332
333
334
    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;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
335
    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));
336
337
338
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
339
      chan_desc->amps[i]      = pow(10,.1*scm_c_amps_dB[i]);
340
341
342
343
344
345
346
347
348
349
350
      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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
351
352
353
354
355
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
356
357
358
359
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));

    chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
    if (nb_tx==2 && nb_rx==2) {
360
361
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
362
363
    }
    else if (nb_tx==2 && nb_rx==1) {
364
365
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R21_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
366
367
    }
    else if (nb_tx==1 && nb_rx==2) {
368
369
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R12_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
370
371
    }
    else {
372
      for (i = 0; i<6; i++) {
373
374
375
376
377
378
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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 not implemented for nb_tx==%d and nb_rx==%d, using identity\n", nb_tx, nb_rx);
379
380
381
      }
    }
    break;
382
383
384
  case EPA:
    chan_desc->nb_taps        = 7;
    chan_desc->Td             = .410;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
385
    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));
386
387
388
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
389
      chan_desc->amps[i]      = pow(10,.1*epa_amps_dB[i]);
390
391
392
393
394
395
396
397
398
399
400
      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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
401
402
403
404
405
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
406
407
408
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
409
410
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
411
412
    }
    else {
413
414
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
415
416
417
418
419
420
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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");
421
422
423
      }
    }
    break;
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
  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));
    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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex**));
      for (i = 0; i<chan_desc->nb_taps; i++)
        chan_desc->R_sqrt[i] = R_sqrt_22_EPA_low[0];
    }
      else {
      printf("Correlation matrices are implemented for 2 x 2 only");
    }
    /*else {
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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));
    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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex**));
      for (i = 0; i<chan_desc->nb_taps; i++)
        chan_desc->R_sqrt[i] = R_sqrt_22_EPA_high[0];
    }
    else {
      printf("Correlation matrices are implemented for 2 x 2 only");
    }
    /*else {
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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));
    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 complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex**));
      for (i = 0; i<chan_desc->nb_taps; i++)
        chan_desc->R_sqrt[i] = R_sqrt_22_EPA_medium[0];
    } else {
      printf("Correlation matrices are implemented for 2 x 2 only");
    }
    /*else {
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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;
558
559
560
  case EVA:
    chan_desc->nb_taps        = 9;
    chan_desc->Td             = 2.51;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
561
    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));
562
563
564
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
565
      chan_desc->amps[i]      = pow(10,.1*eva_amps_dB[i]);
566
567
568
569
570
571
572
573
574
575
576
      sum_amps += chan_desc->amps[i];
    }
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
    chan_desc->delays         = eva_delays;
    chan_desc->ricean_factor  = 1;
    chan_desc->aoa            = 0;
    chan_desc->random_aoa     = 0;
    chan_desc->ch             = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
577
578
579
580
581
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
582
583
584
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
585
586
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
587
588
    }
    else {
589
590
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
591
592
593
594
595
596
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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");
597
598
599
600
601
602
      }
    }
    break;
  case ETU:
    chan_desc->nb_taps        = 9;
    chan_desc->Td             = 5.0;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
603
    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));
604
605
606
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
607
      chan_desc->amps[i]      = pow(10,.1*etu_amps_dB[i]);
608
609
610
611
612
613
614
615
616
617
618
      sum_amps += chan_desc->amps[i];
    }
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
    chan_desc->delays         = etu_delays;
    chan_desc->ricean_factor  = 1;
    chan_desc->aoa            = 0;
    chan_desc->random_aoa     = 0;
    chan_desc->ch             = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
619
620
621
622
623
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
624
625
626
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
627
628
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
Elena Lukashova's avatar
Elena Lukashova committed
629
630
    }
    else {
631
632
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
      for (i = 0; i<6; i++) {
633
634
635
636
637
638
        chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
        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");
639
640
641
642
643
644
      }
    }
    break;
  case MBSFN:
    chan_desc->nb_taps        = 18;
    chan_desc->Td             = 28.58;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
645
    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));
646
647
648
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
    for (i = 0; i<chan_desc->nb_taps; i++) {
649
      chan_desc->amps[i]      = pow(10,.1*mbsfn_amps_dB[i]);
650
651
652
653
654
655
656
657
658
659
660
      sum_amps += chan_desc->amps[i];
    }
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
    chan_desc->delays         = mbsfn_delays;
    chan_desc->ricean_factor  = 1;
    chan_desc->aoa            = 0;
    chan_desc->random_aoa     = 0;
    chan_desc->ch             = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->chF            = (struct complex**) malloc(nb_tx*nb_rx*sizeof(struct complex*));
    chan_desc->a              = (struct complex**) malloc(chan_desc->nb_taps*sizeof(struct complex*));
661
662
663
664
665
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->ch[i] = (struct complex*) malloc(chan_desc->channel_length * sizeof(struct complex));
    for (i = 0; i<nb_tx*nb_rx; i++)
      chan_desc->chF[i] = (struct complex*) malloc(1200 * sizeof(struct complex));
    for (i = 0; i<chan_desc->nb_taps; i++)
666
667
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));

nikaeinn's avatar
nikaeinn committed
668
    chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex*));
669
670
671
    for (i = 0; i<6; i++) {
      chan_desc->R_sqrt[i]    = (struct complex*) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complex));
      for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
672
673
        chan_desc->R_sqrt[i][j].x = 1.0;
        chan_desc->R_sqrt[i][j].y = 0.0;
674
675
676
677
678
      }
      LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
    }
    break;
  case Rayleigh8:
679

Elena Lukashova's avatar
Elena Lukashova committed
680
681
      nb_taps = 8;
      Td = 0.8;
682
      channel_length = (int)11+2*sampling_rate*Td;
Elena Lukashova's avatar
Elena Lukashova committed
683
684
685
686
687
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;

      fill_channel_desc(chan_desc,
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
                        nb_tx,
                        nb_rx,
                        nb_taps,
                        channel_length,
                        default_amps_lin,
                        NULL,
                        NULL,
                        Td,
                        sampling_rate,
                        channel_bandwidth,
                        ricean_factor,
                        aoa,
                        forgetting_factor,
                        maxDoppler,
                        channel_offset,
                        path_loss_dB,
                        0);
Elena Lukashova's avatar
Elena Lukashova committed
705
      break;
706
707

  case Rice8:
Elena Lukashova's avatar
Elena Lukashova committed
708
709
      nb_taps = 8;
      Td = 0.8;
710
      channel_length = (int)11+2*sampling_rate*Td;
Elena Lukashova's avatar
Elena Lukashova committed
711
      ricean_factor = 0.1;
712
      aoa = 0.7854;
Elena Lukashova's avatar
Elena Lukashova committed
713
714
715
      maxDoppler = 0;

      fill_channel_desc(chan_desc,nb_tx,
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amps_lin,
                                   NULL,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   1);
Elena Lukashova's avatar
Elena Lukashova committed
732
      break;
733
734

  case Rayleigh1:
Elena Lukashova's avatar
Elena Lukashova committed
735
736
737
738
739
740
741
742
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;

      fill_channel_desc(chan_desc,nb_tx,
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
Elena Lukashova's avatar
Elena Lukashova committed
759
      break;
760
761

  case Rayleigh1_800:
Elena Lukashova's avatar
Elena Lukashova committed
762
763
764
765
766
767
768
769
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 800;

      fill_channel_desc(chan_desc,nb_tx,
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
Elena Lukashova's avatar
Elena Lukashova committed
786
      break;
787
788

  case Rayleigh1_corr:
Elena Lukashova's avatar
Elena Lukashova committed
789
790
791
792
793
794
795
796
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;

      if ((nb_tx==2) && (nb_rx==1)) {
797
        R_sqrt_ptr2 = R_sqrt_21_corr;
Elena Lukashova's avatar
Elena Lukashova committed
798
799
      }
      else if ((nb_tx==2) && (nb_rx==2)) {
800
        R_sqrt_ptr2 = R_sqrt_22_corr;
Elena Lukashova's avatar
Elena Lukashova committed
801
802
      }
      else
803
        R_sqrt_ptr2 = NULL;
Elena Lukashova's avatar
Elena Lukashova committed
804
805

      fill_channel_desc(chan_desc,nb_tx,
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
Elena Lukashova's avatar
Elena Lukashova committed
822
      break;
823
824
825
826
827
828
829
830
831

  case Rayleigh1_anticorr:
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;

832
      if ((nb_tx==2) && (nb_rx==1)) { //check this
833
        R_sqrt_ptr2 = R_sqrt_21_anticorr;
834
835
      }
      else if ((nb_tx==2) && (nb_rx==2)) {
836
        R_sqrt_ptr2 = R_sqrt_22_anticorr;
837
      }
838
839
      else
        R_sqrt_ptr2 = NULL;
840

841
      fill_channel_desc(chan_desc,nb_tx,
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
858
859
860
      break;

  case Rice1:
Elena Lukashova's avatar
Elena Lukashova committed
861
862
863
864
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 0.1;
865
      aoa = 0.7854;
Elena Lukashova's avatar
Elena Lukashova committed
866
867
868
      maxDoppler = 0;

      fill_channel_desc(chan_desc,nb_tx,
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
Elena Lukashova's avatar
Elena Lukashova committed
885
      break;
886
887

  case AWGN:
Elena Lukashova's avatar
Elena Lukashova committed
888
889
890
891
892
893
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 0.0;
      aoa = 0.0;
      maxDoppler = 0;
894

Elena Lukashova's avatar
Elena Lukashova committed
895
      fill_channel_desc(chan_desc,nb_tx,
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
Elena Lukashova's avatar
Elena Lukashova committed
912
913
914
      printf("AWGN: ricean_factor %f\n",chan_desc->ricean_factor);

      break;
915

916
917
918
919
920
921
922
923
924
  case TS_SHIFT:
      nb_taps = 2;
      Td = ts_shift_delays[1];
      channel_length = 10;
      ricean_factor = 0.0;
      aoa = 0.0;
      maxDoppler = 0;

      fill_channel_desc(chan_desc,nb_tx,
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   ts_shift_amps,
                                   ts_shift_delays,
                                   NULL,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
941
942
943
944
      printf("TS_SHIFT: ricean_factor %f\n",chan_desc->ricean_factor);

      break;

945
  case Rice1_corr:
Elena Lukashova's avatar
Elena Lukashova committed
946
947
948
949
950
951
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 0.1;
      aoa = .03;
      maxDoppler = 0;
952

Elena Lukashova's avatar
Elena Lukashova committed
953
      if ((nb_tx==2) && (nb_rx==1)) {
954
        R_sqrt_ptr2 = R_sqrt_21_corr;
Elena Lukashova's avatar
Elena Lukashova committed
955
956
      }
      else if ((nb_tx==2) && (nb_rx==2)) {
957
        R_sqrt_ptr2 = R_sqrt_22_corr;
Elena Lukashova's avatar
Elena Lukashova committed
958
959
      }
      else
960
        R_sqrt_ptr2 = NULL;
961

Elena Lukashova's avatar
Elena Lukashova committed
962
      fill_channel_desc(chan_desc,nb_tx,
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   1);
Elena Lukashova's avatar
Elena Lukashova committed
979
980
981
      break;

  case Rice1_anticorr:
982
983
984
985
986
987
988
989
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 0.1;
      aoa = .03;
      maxDoppler = 0;

      if ((nb_tx==2) && (nb_rx==1)) {
990
        R_sqrt_ptr2 = R_sqrt_21_anticorr;
991
992
      }
      else if ((nb_tx==2) && (nb_rx==2)) {
993
        R_sqrt_ptr2 = R_sqrt_22_anticorr;
994
      }
995
996
      else
        R_sqrt_ptr2 = NULL;
997

998
      fill_channel_desc(chan_desc,nb_tx,
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   1);
1015
      break;
1016

1017
1018
1019
1020
1021
1022
1023
1024
  case Rayleigh1_orthogonal:
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = 0.03;
      maxDoppler = 0;

1025

1026
      if ((nb_tx==2) && (nb_rx==2)) {
1027
        R_sqrt_ptr2 = R_sqrt_22_orthogonal;
1028
      }
1029
1030
      else
        R_sqrt_ptr2 = NULL;
1031
1032

      fill_channel_desc(chan_desc,nb_tx,
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
1049
      break;
1050

1051
1052
1053
1054
1055
1056
1057
1058
  case Rayleigh1_orth_eff_ch_TM4_prec_real:
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = 0.03;
      maxDoppler = 0;

1059

1060
      if ((nb_tx==2) && (nb_rx==2)) {
1061
        R_sqrt_ptr2 = R_sqrt_22_orth_eff_ch_TM4_prec_real;
1062
      }
1063
1064
      else
        R_sqrt_ptr2 = NULL;
1065
1066

      fill_channel_desc(chan_desc,nb_tx,
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   1);
1083
      break;
1084

1085
1086
1087
1088
1089
1090
1091
1092
      case Rayleigh1_orth_eff_ch_TM4_prec_imag:
      nb_taps = 1;
      Td = 0;
      channel_length = 1;
      ricean_factor = 1;
      aoa = 0.03;
      maxDoppler = 0;

1093

1094
      if ((nb_tx==2) && (nb_rx==2)) {
1095
        R_sqrt_ptr2 = R_sqrt_22_orth_eff_ch_TM4_prec_imag;
1096
      }
1097
1098
      else
        R_sqrt_ptr2 = NULL;
1099
1100

      fill_channel_desc(chan_desc,nb_tx,
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
                                   nb_rx,
                                   nb_taps,
                                   channel_length,
                                   default_amp_lin,
                                   NULL,
                                   R_sqrt_ptr2,
                                   Td,
                                   sampling_rate,
                                   channel_bandwidth,
                                   ricean_factor,
                                   aoa,
                                   forgetting_factor,
                                   maxDoppler,
                                   channel_offset,
                                   path_loss_dB,
                                   0);
1117
      break;
1118

1119
1120
1121
       case Rayleigh8_orth_eff_ch_TM4_prec_real:

    if ((nb_tx==2) && (nb_rx==2)) {
1122
1123
        R_sqrt_ptr2 = R_sqrt_22_orth_eff_ch_TM4_prec_real;
        //R_sqrt_ptr2 = NULL;
1124
      }
1125
1126
1127
      else
        R_sqrt_ptr2 = NULL;

1128
1129
1130

      nb_taps = 8;
      Td = 0.8;
1131
      channel_length = (int)11+2*sampling_rate*Td;
1132
1133
1134
1135
1136
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;

      fill_channel_desc(chan_desc,
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
                        nb_tx,
                        nb_rx,
                        nb_taps,
                        channel_length,
                        default_amps_lin,
                        NULL,
                        R_sqrt_ptr2,
                        Td,
                        sampling_rate,
                        channel_bandwidth,
                        ricean_factor,
                        aoa,
                        forgetting_factor,
                        maxDoppler,
                        channel_offset,
                        path_loss_dB,
                        0);

1155
      break;
1156

1157
1158
1159
      case Rayleigh8_orth_eff_ch_TM4_prec_imag:
      nb_taps = 8;
      Td = 0.8;
1160
      channel_length = (int)11+2*sampling_rate*Td;
1161
1162
1163
      ricean_factor = 1;
      aoa = .03;
      maxDoppler = 0;
1164

1165
      if ((nb_tx==2) && (nb_rx==2)) {
1166
        R_sqrt_ptr2 = R_sqrt_22_orth_eff_ch_TM4_prec_imag;
1167
      }
1168
1169
      else
        R_sqrt_ptr2 = NULL;
1170
1171

       fill_channel_desc(chan_desc,
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
                        nb_tx,
                        nb_rx,
                        nb_taps,
                        channel_length,
                        default_amps_lin,
                        NULL,
                        R_sqrt_ptr2,
                        Td,
                        sampling_rate,
                        channel_bandwidth,
                        ricean_factor,
                        aoa,
                        forgetting_factor,
                        maxDoppler,
                        channel_offset,
                        path_loss_dB,
                        0);
1189
      break;
1190

1191
1192
1193
1194
1195
1196
  default:
    LOG_W(OCM,"channel model not yet supported\n");
    free(chan_desc);
    return(NULL);
  }
  LOG_D(OCM,"[CHANNEL] RF %f\n",chan_desc->ricean_factor);
Elena Lukashova's avatar
Elena Lukashova committed
1197
  for (i=0;i<chan_desc->nb_taps;i++)
1198
1199
1200
1201
1202
1203
1204
1205
    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;

  return(chan_desc);
}


Elena Lukashova's avatar
Elena Lukashova committed
1206
int random_channel(channel_desc_t *desc, uint8_t abstraction_flag) {
1207

1208
1209
1210
1211
  double s;
  int i,k,l,aarx,aatx;
  struct complex anew[NB_ANTENNAS_TX*NB_ANTENNAS_RX],acorr[NB_ANTENNAS_TX*NB_ANTENNAS_RX];
  struct complex phase, alpha, beta;
1212

1213
  if ((desc->nb_tx>NB_ANTENNAS_TX) || (desc->nb_rx > NB_ANTENNAS_RX)) {
1214
    msg("random_channel.c: Error: temporary buffer for channel not big enough (%d,%d)\n",desc->nb_tx,desc->nb_rx);
1215
1216
1217
    return(-1);
  }

1218
  start_meas(&desc->random_channel);
Elena Lukashova's avatar
Elena Lukashova committed
1219
1220
1221
  for (i=0;i<(int)desc->nb_taps;i++) {
    for (aarx=0;aarx<desc->nb_rx;aarx++) {
      for (aatx=0;aatx<desc->nb_tx;aatx++) {
1222

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
        anew[aarx+(aatx*desc->nb_rx)].x = sqrt(desc->ricean_factor*desc->amps[i]/2) * gaussdouble(0.0,1.0);
        anew[aarx+(aatx*desc->nb_rx)].y = sqrt(desc->ricean_factor*desc->amps[i]/2) * gaussdouble(0.0,1.0);

        if ((i==0) && (desc->ricean_factor != 1.0)) {
          if (desc->random_aoa==1) {
            desc->aoa = uniformrandom()*2*M_PI;
          }

          // this assumes that both RX and TX have linear antenna arrays with lambda/2 antenna spacing.
          // Furhter it is assumed that the arrays are parallel to each other and that they are far enough apart so
          // that we can safely assume plane wave propagation.
          phase.x = cos(M_PI*((aarx-aatx)*sin(desc->aoa)));
          phase.y = sin(M_PI*((aarx-aatx)*sin(desc->aoa)));

          anew[aarx+(aatx*desc->nb_rx)].x += phase.x * sqrt(1.0-desc->ricean_factor);
          anew[aarx+(aatx*desc->nb_rx)].y += phase.y * sqrt(1.0-desc->ricean_factor);
        }
1240
#ifdef DEBUG_CH