lte_adjust_sync.c 4.77 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/extern.h"

26 27
#include "UTIL/LOG/vcd_signal_dumper.h"

28
#define DEBUG_PHY
29 30

int lte_est_timing_advance(LTE_DL_FRAME_PARMS *frame_parms,
31
                           LTE_eNB_SRS *lte_eNB_srs,
32 33 34 35
                           unsigned int  *eNB_id,
                           unsigned char clear,
                           unsigned char number_of_cards,
                           short coef)
36 37 38 39 40 41 42 43 44 45 46 47 48

{

  static int max_pos_fil2 = 0;
  int temp, i, aa, max_pos = 0,ind;
  int max_val=0;
  short Re,Im,ncoef;
#ifdef DEBUG_PHY
  char fname[100],vname[100];
#endif

  ncoef = 32768 - coef;

49
  for (ind=0; ind<number_of_cards; ind++) {
50 51 52 53 54

    if (ind==0)
      max_val=0;


55
    for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
56
      // do ifft of channel estimate
57 58
      switch(frame_parms->N_RB_DL) {
      case 6:
59 60
	dft128((int16_t*) &lte_eNB_srs->srs_ch_estimates[aa][0],
	       (int16_t*) lte_eNB_srs->srs_ch_estimates_time[aa],
61 62 63
	       1);
	break;
      case 25:
64 65
	dft512((int16_t*) &lte_eNB_srs->srs_ch_estimates[aa][0],
	       (int16_t*) lte_eNB_srs->srs_ch_estimates_time[aa],
66 67 68
	       1);
	break;
      case 50:
69 70
	dft1024((int16_t*) &lte_eNB_srs->srs_ch_estimates[aa][0],
		(int16_t*) lte_eNB_srs->srs_ch_estimates_time[aa],
71 72 73
		1);
	break;
      case 100:
74 75
	dft2048((int16_t*) &lte_eNB_srs->srs_ch_estimates[aa][0],
	       (int16_t*) lte_eNB_srs->srs_ch_estimates_time[aa],
76 77 78
	       1);
	break;
      }
79 80 81
#ifdef DEBUG_PHY
      sprintf(fname,"srs_ch_estimates_time_%d%d.m",ind,aa);
      sprintf(vname,"srs_time_%d%d",ind,aa);
82
      write_output(fname,vname,lte_eNB_srs->srs_ch_estimates_time[aa],frame_parms->ofdm_symbol_size*2,2,1);
83 84 85 86 87 88 89
#endif
    }

    // we only use channel estimates from tx antenna 0 here
    // remember we fixed the SRS to use only every second subcarriers
    for (i = 0; i < frame_parms->ofdm_symbol_size/2; i++) {
      temp = 0;
90 91

      for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
92 93
        Re = ((int16_t*)lte_eNB_srs->srs_ch_estimates_time[aa])[(i<<1)];
        Im = ((int16_t*)lte_eNB_srs->srs_ch_estimates_time[aa])[1+(i<<1)];
94
        temp += (Re*Re/2) + (Im*Im/2);
95
      }
96

97
      if (temp > max_val) {
98 99 100
        max_pos = i;
        max_val = temp;
        *eNB_id = ind;
101 102 103 104 105 106 107 108 109
      }
    }
  }

  // filter position to reduce jitter
  if (clear == 1)
    max_pos_fil2 = max_pos;
  else
    max_pos_fil2 = ((max_pos_fil2 * coef) + (max_pos * ncoef)) >> 15;
110

111 112 113 114
  return(max_pos_fil2);
}


115
int lte_est_timing_advance_pusch(PHY_VARS_eNB* eNB,uint8_t UE_id)
116 117
{
  int temp, i, aa, max_pos=0, max_val=0;
Cedric Roux's avatar
Cedric Roux committed
118
  short Re,Im;
119

120 121
  LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
  LTE_eNB_PUSCH *eNB_pusch_vars = eNB->pusch_vars[UE_id];
122
  int32_t **ul_ch_estimates_time=  eNB_pusch_vars->drs_ch_estimates_time;
123
  uint8_t cyclic_shift = 0;
Raymond Knopp's avatar
 
Raymond Knopp committed
124
  int sync_pos = (frame_parms->ofdm_symbol_size-cyclic_shift*frame_parms->ofdm_symbol_size/12)%(frame_parms->ofdm_symbol_size);
125

126 127 128
  AssertFatal(frame_parms->ofdm_symbol_size > 127,"frame_parms->ofdm_symbol_size %d<128\n",frame_parms->ofdm_symbol_size);
  AssertFatal(frame_parms->nb_antennas_rx >0 && frame_parms->nb_antennas_rx<3,"frame_parms->nb_antennas_rx %d not in [0,1]\n",
	      frame_parms->nb_antennas_rx);
129
  for (i = 0; i < frame_parms->ofdm_symbol_size; i++) {
130 131 132
    temp = 0;

    for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) {
133 134
      Re = ((int16_t*)ul_ch_estimates_time[aa])[(i<<1)];
      Im = ((int16_t*)ul_ch_estimates_time[aa])[1+(i<<1)];
135 136 137 138 139 140 141
      temp += (Re*Re/2) + (Im*Im/2);
    }

    if (temp > max_val) {
      max_pos = i;
      max_val = temp;
    }
142 143
  }

144 145
  if (max_pos>frame_parms->ofdm_symbol_size/2)
    max_pos = max_pos-frame_parms->ofdm_symbol_size;
146

147
  //#ifdef DEBUG_PHY
Cedric Roux's avatar
Cedric Roux committed
148
  LOG_D(PHY,"frame %d: max_pos = %d, sync_pos=%d\n",eNB->proc.frame_rx,max_pos,sync_pos);
149
  //#endif //DEBUG_PHY
150

Cedric Roux's avatar
Cedric Roux committed
151
  return max_pos - sync_pos;
152
}