random_channel.c 37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

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
void fill_channel_desc(channel_desc_t *chan_desc,
36 37 38 39 40 41 42 43
                       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
44 45
                       double sampling_rate,
		       double channel_bandwidth,
46 47 48 49 50 51 52 53 54
                       double ricean_factor,
                       double aoa,
                       double forgetting_factor,
                       double max_Doppler,
                       int32_t channel_offset,
                       double path_loss_dB,
                       uint8_t random_aoa)
{

55
  uint16_t i,j;
56 57 58
  double delta_tau;

  LOG_I(OCM,"[CHANNEL] Getting new channel descriptor, nb_tx %d, nb_rx %d, nb_taps %d, channel_length %d\n",
59
        nb_tx,nb_rx,nb_taps,channel_length);
60 61 62 63 64 65 66

  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");
67

68 69 70
  if (delays==NULL) {
    chan_desc->delays = (double*) malloc(nb_taps*sizeof(double));
    delta_tau = Td/nb_taps;
71

72 73
    for (i=0; i<nb_taps; i++)
      chan_desc->delays[i] = ((double)i)*delta_tau;
74
  } else
75 76 77
    chan_desc->delays         = delays;

  chan_desc->Td             = Td;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
78 79
  chan_desc->sampling_rate             = sampling_rate;
  chan_desc->channel_bandwidth         = channel_bandwidth;
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  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*));

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

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

98
  for (i = 0; i<nb_tx*nb_rx; i++)
99 100 101
    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);
102

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

  LOG_D(OCM,"[CHANNEL] Doing R_sqrt ...\n");
109

110
  if (R_sqrt == NULL) {
111 112
    chan_desc->R_sqrt         = (struct complex**) calloc(nb_taps,sizeof(struct complex*));

113
    for (i = 0; i<nb_taps; i++) {
114 115
      chan_desc->R_sqrt[i]    = (struct complex*) calloc(nb_tx*nb_rx*nb_tx*nb_rx,sizeof(struct complex));

116
      for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
117 118
        chan_desc->R_sqrt[i][j].x = 1.0;
        chan_desc->R_sqrt[i][j].y = 0.0;
119 120
      }
    }
121
  } else {
122 123 124 125 126 127 128 129 130 131
    chan_desc->R_sqrt = 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].x,chan_desc->R_sqrt[i][j].y);
    }
  }

  LOG_D(OCM,"[CHANNEL] RF %f\n",chan_desc->ricean_factor);
132 133

  for (i=0; i<chan_desc->nb_taps; i++)
134 135 136 137
    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;

138 139 140 141 142
  reset_meas(&chan_desc->random_channel);
  reset_meas(&chan_desc->interp_time);
  reset_meas(&chan_desc->interp_freq);
  reset_meas(&chan_desc->convolution);

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
}

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

163 164 165 166 167 168
//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}
};
169 170 171
struct complex *R_sqrt_22_corr[1]     = {R_sqrt_22_corr_tap};

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

175 176 177 178 179 180
//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}
};
181 182 183
struct complex *R_sqrt_22_anticorr[1]     = {R_sqrt_22_anticorr_tap};

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

struct complex **R_sqrt_ptr2;


190 191 192
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
193 194
                                     double sampling_rate,
				     double channel_bandwidth,
195 196 197 198
                                     double forgetting_factor,
                                     int32_t channel_offset,
                                     double path_loss_dB)
{
199 200

  channel_desc_t *chan_desc = (channel_desc_t *)malloc(sizeof(channel_desc_t));
201
  uint16_t i,j;
202 203 204 205 206 207
  double sum_amps;
  double aoa,ricean_factor,Td,maxDoppler;
  int channel_length,nb_taps;

  chan_desc->nb_tx          = nb_tx;
  chan_desc->nb_rx          = nb_rx;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
208 209
  chan_desc->sampling_rate             = sampling_rate;
  chan_desc->channel_bandwidth         = channel_bandwidth;
210 211 212 213 214 215 216 217 218 219 220 221 222
  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;

  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);
223

224 225 226 227
  case SCM_B:
    LOG_W(OCM,"channel model not yet supported\n");
    free(chan_desc);
    return(NULL);
228

229 230 231
  case SCM_C:
    chan_desc->nb_taps        = 18;
    chan_desc->Td             = 4.625;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
232
    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));
233 234
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
235

236
    for (i = 0; i<chan_desc->nb_taps; i++) {
237
      chan_desc->amps[i]      = pow(10,.1*scm_c_amps_dB[i]);
238 239
      sum_amps += chan_desc->amps[i];
    }
240

241 242
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
243

244 245 246 247 248 249 250
    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*));
251 252 253 254 255 256 257 258

    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++)
259 260 261
      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**));
262

263
    if (nb_tx==2 && nb_rx==2) {
264 265 266 267 268 269 270 271 272
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
    } else if (nb_tx==2 && nb_rx==1) {
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R21_sqrt[i][0];
    } else if (nb_tx==1 && nb_rx==2) {
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R12_sqrt[i][0];
    } else {
273
      for (i = 0; i<6; i++) {
274 275 276 277 278 279 280 281
        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);
282 283
      }
    }
284

285
    break;
286

287
  case SCM_D:
288 289 290
    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
291
    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));
292 293
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
294

295
    for (i = 0; i<chan_desc->nb_taps; i++) {
296
      chan_desc->amps[i]      = pow(10,.1*scm_c_amps_dB[i]);
297 298
      sum_amps += chan_desc->amps[i];
    }
299

300 301
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
302

303 304 305 306 307 308 309
    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*));
310 311 312 313 314 315 316 317

    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++)
318 319 320
      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**));
321

322
    if (nb_tx==2 && nb_rx==2) {
323 324 325 326 327 328 329 330 331
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
    } else if (nb_tx==2 && nb_rx==1) {
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R21_sqrt[i][0];
    } else if (nb_tx==1 && nb_rx==2) {
      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R12_sqrt[i][0];
    } else {
332
      for (i = 0; i<6; i++) {
333 334 335 336 337 338 339 340
        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);
341 342
      }
    }
343

344
    break;
345

346 347 348
  case EPA:
    chan_desc->nb_taps        = 7;
    chan_desc->Td             = .410;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
349
    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));
350 351
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
352

353
    for (i = 0; i<chan_desc->nb_taps; i++) {
354
      chan_desc->amps[i]      = pow(10,.1*epa_amps_dB[i]);
355 356
      sum_amps += chan_desc->amps[i];
    }
357

358 359
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
360

361 362 363 364 365 366 367
    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*));
368 369 370 371 372 373 374 375

    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++)
376
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
377

378 379
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
380 381 382 383

      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
    } else {
384
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
385

386
      for (i = 0; i<6; i++) {
387 388 389 390 391 392 393 394
        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");
395 396
      }
    }
397

398
    break;
399

400 401 402
  case EVA:
    chan_desc->nb_taps        = 9;
    chan_desc->Td             = 2.51;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
403
    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));
404 405
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
406

407
    for (i = 0; i<chan_desc->nb_taps; i++) {
408
      chan_desc->amps[i]      = pow(10,.1*eva_amps_dB[i]);
409 410
      sum_amps += chan_desc->amps[i];
    }
411

412 413
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
414

415 416 417 418 419 420 421
    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*));
422 423 424 425 426 427 428 429

    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++)
430
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
431

432 433
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
434 435 436 437

      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
    } else {
438
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
439

440
      for (i = 0; i<6; i++) {
441 442 443 444 445 446 447 448
        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");
449 450
      }
    }
451

452
    break;
453

454 455 456
  case ETU:
    chan_desc->nb_taps        = 9;
    chan_desc->Td             = 5.0;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
457
    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));
458 459
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
460

461
    for (i = 0; i<chan_desc->nb_taps; i++) {
462
      chan_desc->amps[i]      = pow(10,.1*etu_amps_dB[i]);
463 464
      sum_amps += chan_desc->amps[i];
    }
465

466 467
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
468

469 470 471 472 473 474 475
    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*));
476 477 478 479 480 481 482 483

    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++)
484
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));
485

486 487
    if (nb_tx==2 && nb_rx==2) {
      chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex**));
488 489 490 491

      for (i = 0; i<6; i++)
        chan_desc->R_sqrt[i] = (struct complex*) &R22_sqrt[i][0];
    } else {
492
      chan_desc->R_sqrt         = (struct complex**) malloc(6*sizeof(struct complex**));
493

494
      for (i = 0; i<6; i++) {
495 496 497 498 499 500 501 502
        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");
503 504
      }
    }
505

506
    break;
507

508 509 510
  case MBSFN:
    chan_desc->nb_taps        = 18;
    chan_desc->Td             = 28.58;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
511
    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));
512 513
    sum_amps = 0;
    chan_desc->amps           = (double*) malloc(chan_desc->nb_taps*sizeof(double));
514

515
    for (i = 0; i<chan_desc->nb_taps; i++) {
516
      chan_desc->amps[i]      = pow(10,.1*mbsfn_amps_dB[i]);
517 518
      sum_amps += chan_desc->amps[i];
    }
519

520 521
    for (i = 0; i<chan_desc->nb_taps; i++)
      chan_desc->amps[i] /= sum_amps;
522

523 524 525 526 527 528 529
    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*));
530 531 532 533 534 535 536 537

    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++)
538 539
      chan_desc->a[i]         = (struct complex*) malloc(nb_tx*nb_rx * sizeof(struct complex));

nikaeinn's avatar
nikaeinn committed
540
    chan_desc->R_sqrt  = (struct complex**) malloc(6*sizeof(struct complex*));
541

542 543
    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));
544

545
      for (j = 0; j<nb_tx*nb_rx*nb_tx*nb_rx; j+=(nb_tx*nb_rx+1)) {
546 547
        chan_desc->R_sqrt[i][j].x = 1.0;
        chan_desc->R_sqrt[i][j].y = 0.0;
548
      }
549

550 551
      LOG_W(OCM,"correlation matrix only implemented for nb_tx==2 and nb_rx==2, using identity\n");
    }
552

553
    break;
554

555
  case Rayleigh8:
556 557
    nb_taps = 8;
    Td = 0.8;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
558
    channel_length = (int)11+2*sampling_rate*Td;
559 560 561 562 563 564 565 566 567 568 569 570 571
    ricean_factor = 1;
    aoa = .03;
    maxDoppler = 0;

    fill_channel_desc(chan_desc,
                      nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amps_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
572 573
                      sampling_rate,
		      channel_bandwidth,
574 575 576 577 578 579 580 581
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
582 583

  case Rice8:
584 585
    nb_taps = 8;
    Td = 0.8;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
586
    channel_length = (int)11+2*sampling_rate*Td;
587 588 589 590 591 592 593 594 595 596 597 598
    ricean_factor = 0.1;
    aoa = .03;
    maxDoppler = 0;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amps_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
599 600
                      sampling_rate,
		      channel_bandwidth,
601 602 603 604 605 606 607 608
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      1);
    break;
609 610

  case Rayleigh1:
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 1;
    aoa = .03;
    maxDoppler = 0;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
626 627
                      sampling_rate,
		      channel_bandwidth,
628 629 630 631 632 633 634 635
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
636 637

  case Rayleigh1_800:
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 1;
    aoa = .03;
    maxDoppler = 800;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
653 654
                      sampling_rate,
		      channel_bandwidth,
655 656 657 658 659 660 661 662
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
663 664

  case Rayleigh1_corr:
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 1;
    aoa = .03;
    maxDoppler = 0;

    if ((nb_tx==2) && (nb_rx==1)) {
      R_sqrt_ptr2 = R_sqrt_21_corr;
    } else if ((nb_tx==2) && (nb_rx==2)) {
      R_sqrt_ptr2 = R_sqrt_22_corr;
    } else
      R_sqrt_ptr2 = NULL;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      R_sqrt_ptr2,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
687 688
                      sampling_rate,
		      channel_bandwidth,
689 690 691 692 693 694 695 696
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
697 698

  case Rayleigh1_anticorr:
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 1;
    aoa = .03;
    maxDoppler = 0;

    if ((nb_tx==2) && (nb_rx==1)) {
      R_sqrt_ptr2 = R_sqrt_21_anticorr;
    } else if ((nb_tx==2) && (nb_rx==2)) {
      R_sqrt_ptr2 = R_sqrt_22_anticorr;
    } else
      R_sqrt_ptr2 = NULL;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      R_sqrt_ptr2,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
721 722
                      sampling_rate,
		      channel_bandwidth,
723 724 725 726 727 728 729 730
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
731 732

  case Rice1:
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 0.1;
    aoa = .03;
    maxDoppler = 0;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
748 749
                      sampling_rate,
		      channel_bandwidth,
750 751 752 753 754 755 756 757
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    break;
758 759

  case AWGN:
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 0.0;
    aoa = 0.0;
    maxDoppler = 0;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      NULL,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
775 776
                      sampling_rate,
		      channel_bandwidth,
777 778 779 780 781 782 783 784 785 786
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      0);
    printf("AWGN: ricean_factor %f\n",chan_desc->ricean_factor);

    break;
787 788

  case Rice1_corr:
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 0.1;
    aoa = .03;
    maxDoppler = 0;

    if ((nb_tx==2) && (nb_rx==1)) {
      R_sqrt_ptr2 = R_sqrt_21_corr;
    } else if ((nb_tx==2) && (nb_rx==2)) {
      R_sqrt_ptr2 = R_sqrt_22_corr;
    } else
      R_sqrt_ptr2 = NULL;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      R_sqrt_ptr2,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
811 812
                      sampling_rate,
		      channel_bandwidth,
813 814 815 816 817 818 819 820
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      1);
    break;
821 822

  case Rice1_anticorr:
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
    nb_taps = 1;
    Td = 0;
    channel_length = 1;
    ricean_factor = 0.1;
    aoa = .03;
    maxDoppler = 0;

    if ((nb_tx==2) && (nb_rx==1)) {
      R_sqrt_ptr2 = R_sqrt_21_anticorr;
    } else if ((nb_tx==2) && (nb_rx==2)) {
      R_sqrt_ptr2 = R_sqrt_22_anticorr;
    } else
      R_sqrt_ptr2 = NULL;

    fill_channel_desc(chan_desc,nb_tx,
                      nb_rx,
                      nb_taps,
                      channel_length,
                      default_amp_lin,
                      NULL,
                      R_sqrt_ptr2,
                      Td,
Florian Kaltenberger's avatar
Florian Kaltenberger committed
845 846
                      sampling_rate,
		      channel_bandwidth,
847 848 849 850 851 852 853 854
                      ricean_factor,
                      aoa,
                      forgetting_factor,
                      maxDoppler,
                      channel_offset,
                      path_loss_dB,
                      1);
    break;
855 856 857 858 859 860

  default:
    LOG_W(OCM,"channel model not yet supported\n");
    free(chan_desc);
    return(NULL);
  }
861

862
  LOG_D(OCM,"[CHANNEL] RF %f\n",chan_desc->ricean_factor);
863 864

  for (i=0; i<chan_desc->nb_taps; i++)
865 866 867 868 869 870 871 872
    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);
}


873 874 875
int random_channel(channel_desc_t *desc, uint8_t abstraction_flag)
{

876 877 878 879
  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;
880

881
  if ((desc->nb_tx>NB_ANTENNAS_TX) || (desc->nb_rx > NB_ANTENNAS_RX)) {
882
    msg("random_channel.c: Error: temporary buffer for channel not big enough (%d,%d)\n",desc->nb_tx,desc->nb_rx);
883 884 885
    return(-1);
  }

886
  start_meas(&desc->random_channel);
887

888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
  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++) {

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

910
#ifdef DEBUG_CH
911 912
        printf("(%d,%d,%d) %f->(%f,%f) (%f,%f) phase (%f,%f)\n",aarx,aatx,i,desc->amps[i],anew[aarx+(aatx*desc->nb_rx)].x,anew[aarx+(aatx*desc->nb_rx)].y,desc->aoa,desc->ricean_factor,phase.x,phase.y);
#endif
913 914 915 916 917 918 919
      } //aatx
    } //aarx

    /*
    // for debugging set a=anew;
    for (aarx=0;aarx<desc->nb_rx;aarx++) {
      for (aatx=0;aatx<desc->nb_tx;aatx++) {
920 921 922
    desc->a[i][aarx+(aatx*desc->nb_rx)].x = anew[aarx+(aatx*desc->nb_rx)].x;
    desc->a[i][aarx+(aatx*desc->nb_rx)].y = anew[aarx+(aatx*desc->nb_rx)].y;
    printf("anew(%d,%d) = %f+1j*%f\n",aatx,aarx,anew[aarx+(aatx*desc->nb_rx)].x, anew[aarx+(aatx*desc->nb_rx)].y);
923 924 925 926 927 928 929 930 931 932
     }
    }
    */
    //apply correlation matrix
    //compute acorr = R_sqrt[i] * anew
    alpha.x = 1.0;
    alpha.y = 0.0;
    beta.x = 0.0;
    beta.y = 0.0;

933 934 935
    cblas_zgemv(CblasRowMajor, CblasNoTrans, desc->nb_tx*desc->nb_rx, desc->nb_tx*desc->nb_rx,
                (void*) &alpha, (void*) desc->R_sqrt[i/3], desc->nb_rx*desc->nb_tx,
                (void*) anew, 1, (void*) &beta, (void*) acorr, 1);
936 937 938 939

    /*
    for (aarx=0;aarx<desc->nb_rx;aarx++) {
      for (aatx=0;aatx<desc->nb_tx;aatx++) {
940 941 942
    desc->a[i][aarx+(aatx*desc->nb_rx)].x = acorr[aarx+(aatx*desc->nb_rx)].x;
    desc->a[i][aarx+(aatx*desc->nb_rx)].y = acorr[aarx+(aatx*desc->nb_rx)].y;
    printf("tap %d, acorr1(%d,%d) = %f+1j*%f\n",i,aatx,aarx,acorr[aarx+(aatx*desc->nb_rx)].x, acorr[aarx+(aatx*desc->nb_rx)].y);
943 944 945 946
      }
    }
    */

947
    if (desc->first_run==1) {
948
      cblas_zcopy(desc->nb_tx*desc->nb_rx, (void*) acorr, 1, (void*) desc->a[i], 1);
949
    } else {
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966
      // a = alpha*acorr+beta*a
      // a = beta*a
      // a = a+alpha*acorr
      alpha.x = sqrt(1-desc->forgetting_factor);
      alpha.y = 0;
      beta.x = sqrt(desc->forgetting_factor);
      beta.y = 0;
      cblas_zscal(desc->nb_tx*desc->nb_rx, (void*) &beta, (void*) desc->a[i], 1);
      cblas_zaxpy(desc->nb_tx*desc->nb_rx, (void*) &alpha, (void*) acorr, 1, (void*) desc->a[i], 1);

      //  desc->a[i][aarx+(aatx*desc->nb_rx)].x = (sqrt(desc->forgetting_factor)*desc->a[i][aarx+(aatx*desc->nb_rx)].x) + sqrt(1-desc->forgetting_factor)*anew.x;
      //  desc->a[i][aarx+(aatx*desc->nb_rx)].y = (sqrt(desc->forgetting_factor)*desc->a[i][aarx+(aatx*desc->nb_rx)].y) + sqrt(1-desc->forgetting_factor)*anew.y;
    }

    /*
    for (aarx=0;aarx<desc->nb_rx;aarx++) {
      for (aatx=0;aatx<desc->nb_tx;aatx++) {
967 968 969
    //desc->a[i][aarx+(aatx*desc->nb_rx)].x = acorr[aarx+(aatx*desc->nb_rx)].x;
    //desc->a[i][aarx+(aatx*desc->nb_rx)].y = acorr[aarx+(aatx*desc->nb_rx)].y;
    printf("tap %d, a(%d,%d) = %f+1j*%f\n",i,aatx,aarx,desc->a[i][aarx+(aatx*desc->nb_rx)].x, desc->a[i][aarx+(aatx*desc->nb_rx)].y);
970 971 972 973
      }
    }
    */

974 975
  } //nb_taps

976
  stop_meas(&desc->random_channel);
977 978

  //memset((void *)desc->ch[aarx+(aatx*desc->nb_rx)],0,(int)(desc->channel_length)*sizeof(struct complex));
979

980
  if (abstraction_flag==0) {
981 982 983 984 985 986 987 988 989 990 991 992 993 994
    start_meas(&desc->interp_time);

    for (aarx=0; aarx<desc->nb_rx; aarx++) {
      for (aatx=0; aatx<desc->nb_tx; aatx++) {
        if (desc->channel_length == 1) {
          desc->ch[aarx+(aatx*desc->nb_rx)][0].x = desc->a[0][aarx+(aatx*desc->nb_rx)].x;
          desc->ch[aarx+(aatx*desc->nb_rx)][0].y = desc->a[0][aarx+(aatx*desc->nb_rx)].y;
        } else {

          for (k=0; k<(int)desc->channel_length; k++) {
            desc->ch[aarx+(aatx*desc->nb_rx)][k].x = 0.0;
            desc->ch[aarx+(aatx*desc->nb_rx)][k].y = 0.0;

            for (l=0; l<desc->nb_taps; l++) {
Florian Kaltenberger's avatar
Florian Kaltenberger committed
995
              if ((k - (desc->delays[l]*desc->sampling_rate) - NB_SAMPLES_CHANNEL_OFFSET) == 0)
996 997
                s = 1.0;
              else
Florian Kaltenberger's avatar
Florian Kaltenberger committed
998 999
                s = sin(M_PI*(k - (desc->delays[l]*desc->sampling_rate) - NB_SAMPLES_CHANNEL_OFFSET))/
                    (M_PI*(k - (desc->delays[l]*desc->sampling_rate) - NB_SAMPLES_CHANNEL_OFFSET));
1000 1001 1002 1003 1004 1005 1006

              desc->ch[aarx+(aatx*desc->nb_rx)][k].x += s*desc->a[l][aarx+(aatx*desc->nb_rx)].x;
              desc->ch[aarx+(aatx*desc->nb_rx)][k].y += s*desc->a[l][aarx+(aatx*desc->nb_rx)].y;
              //    printf("l %d : desc->ch.x %f\n",l,desc->a[l][aarx+(aatx*desc->nb_rx)].x);

            } //nb_taps

1007
#ifdef DEBUG_CH
1008
            printf("(%d,%d,%d)->(%f,%f)\n",k,aarx,aatx,desc->ch[aarx+(aatx*desc->nb_rx)][k].x,desc->ch[aarx+(aatx*desc->nb_rx)][k].y);
1009
#endif
1010 1011 1012 1013 1014 1015
          }
        } //channel_length
      } //aatx
    } //aarx

    stop_meas(&desc->interp_time);
1016
  }
1017 1018 1019 1020 1021 1022 1023

  if (desc->first_run==1)
    desc->first_run = 0;

  return (0);
}

Florian Kaltenberger's avatar
Florian Kaltenberger committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
double N_RB2sampling_rate(uint16_t N_RB)
{
  double sampling_rate;
  switch (N_RB) {
  case 6:
    sampling_rate = 1.92;
    break;
    
  case 25:
    sampling_rate = 7.68;
    break;
    
  case 50:
    sampling_rate = 15.36;
    break;
    
  case 100:
    sampling_rate = 30.72;
    break;
    
  default:
    LOG_E(PHY,"Unknown N_PRB\n");
    return(-1);  
  }

  return(sampling_rate);
}

double N_RB2channel_bandwidth(uint16_t N_RB)
{
  double channel_bandwidth;
  switch (N_RB) {
  case 6:
    channel_bandwidth = 1.25;
    break;
    
  case 25:
    channel_bandwidth = 5.00;
    break;
    
  case 50:
    channel_bandwidth = 10.00;
    break;
    
  case 100:
    channel_bandwidth = 20.00;
    break;
    
  default:
    LOG_E(PHY,"Unknown N_PRB\n");
    return(-1);  
  }
  return(channel_bandwidth);
}

1079
#ifdef RANDOM_CHANNEL_MAIN
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1080
#define sampling_rate 5.0
1081
#define Td 2.0
1082 1083
main(int argc,char **argv)
{
1084 1085

  double amps[8] = {.8,.2,.1,.04,.02,.01,.005};
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1086
  struct complex ch[(int)(1+2*sampling_rate*Td)],phase;
1087
  int i;
1088

1089 1090 1091
  randominit();
  phase.x = 1.0;
  phase.y = 0;
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1092
  random_channel(amps,Td, 8,sampling_rate,ch,(double)1.0,&phase);
1093
  /*
Florian Kaltenberger's avatar
Florian Kaltenberger committed
1094
  for (i=0;i<(11+2*sampling_rate*Td);i++){
1095 1096 1097 1098 1099 1100
    printf("%f + sqrt(-1)*%f\n",ch[i].x,ch[i].y);
  }
  */
}

#endif