2019-04-26 12:27:38 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2013-2019 Software Radio Systems Limited
|
2014-01-28 03:41:17 -08:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* This file is part of srsLTE.
|
2014-03-03 11:09:26 -08:00
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2015-05-08 08:05:40 -07:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2014-03-03 11:09:26 -08:00
|
|
|
* published by the Free Software Foundation, either version 3 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-03-18 05:31:13 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2014-01-28 03:41:17 -08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-05-08 08:05:40 -07:00
|
|
|
* GNU Affero General Public License for more details.
|
2014-01-28 03:41:17 -08:00
|
|
|
*
|
2015-05-08 08:05:40 -07:00
|
|
|
* A copy of the GNU Affero General Public License can be found in
|
2014-03-03 11:09:26 -08:00
|
|
|
* the LICENSE file in the top-level directory of this distribution
|
|
|
|
* and at http://www.gnu.org/licenses/.
|
|
|
|
*
|
2014-01-28 03:41:17 -08:00
|
|
|
*/
|
|
|
|
|
2015-04-03 05:49:12 -07:00
|
|
|
/******************************************************************************
|
|
|
|
* File: sync.h
|
|
|
|
*
|
|
|
|
* Description: Time and frequency synchronization using the PSS and SSS signals.
|
|
|
|
*
|
|
|
|
* The object is designed to work with signals sampled at 1.92 Mhz
|
|
|
|
* centered at the carrier frequency. Thus, downsampling is required
|
|
|
|
* if the signal is sampled at higher frequencies.
|
|
|
|
*
|
|
|
|
* Correlation peak is detected comparing the maximum at the output
|
|
|
|
* of the correlator with a threshold. The comparison accepts two
|
|
|
|
* modes: absolute value or peak-to-mean ratio, which are configured
|
|
|
|
* with the functions sync_pss_det_absolute() and sync_pss_det_peakmean().
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Reference: 3GPP TS 36.211 version 10.0.0 Release 10 Sec. 6.11.1, 6.11.2
|
|
|
|
*****************************************************************************/
|
2014-03-03 11:09:26 -08:00
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#ifndef SRSLTE_SYNC_H
|
|
|
|
#define SRSLTE_SYNC_H
|
2014-01-28 03:41:17 -08:00
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
#include <stdbool.h>
|
2014-07-21 07:19:17 -07:00
|
|
|
#include <math.h>
|
2014-03-27 09:31:25 -07:00
|
|
|
|
2015-03-18 05:16:28 -07:00
|
|
|
#include "srslte/config.h"
|
2017-05-18 00:48:24 -07:00
|
|
|
#include "srslte/phy/sync/pss.h"
|
|
|
|
#include "srslte/phy/sync/sss.h"
|
|
|
|
#include "srslte/phy/sync/cfo.h"
|
|
|
|
#include "srslte/phy/sync/cp.h"
|
2014-01-28 03:41:17 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
#define SRSLTE_SYNC_FFT_SZ_MIN 64
|
|
|
|
#define SRSLTE_SYNC_FFT_SZ_MAX 2048
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-12-09 15:29:48 -08:00
|
|
|
typedef enum {SSS_DIFF=0, SSS_PARTIAL_3=2, SSS_FULL=1} sss_alg_t;
|
|
|
|
|
2015-03-18 05:31:13 -07:00
|
|
|
typedef struct SRSLTE_API {
|
2017-12-03 20:13:07 -08:00
|
|
|
srslte_pss_t pss;
|
|
|
|
srslte_pss_t pss_i[2];
|
|
|
|
srslte_sss_t sss;
|
2015-11-09 10:15:33 -08:00
|
|
|
srslte_cp_synch_t cp_synch;
|
|
|
|
cf_t *cfo_i_corr[2];
|
2017-05-03 08:48:40 -07:00
|
|
|
int decimate;
|
2014-08-01 14:26:28 -07:00
|
|
|
float threshold;
|
2014-07-21 08:54:25 -07:00
|
|
|
float peak_value;
|
2014-07-21 07:19:17 -07:00
|
|
|
uint32_t N_id_2;
|
|
|
|
uint32_t N_id_1;
|
2014-08-01 14:26:28 -07:00
|
|
|
uint32_t sf_idx;
|
2014-07-21 07:19:17 -07:00
|
|
|
uint32_t fft_size;
|
2014-08-01 14:26:28 -07:00
|
|
|
uint32_t frame_size;
|
2015-11-09 10:15:33 -08:00
|
|
|
uint32_t max_offset;
|
|
|
|
uint32_t nof_symbols;
|
|
|
|
uint32_t cp_len;
|
2017-09-12 02:10:32 -07:00
|
|
|
float current_cfo_tol;
|
2014-12-09 15:29:48 -08:00
|
|
|
sss_alg_t sss_alg;
|
2014-06-17 02:11:41 -07:00
|
|
|
bool detect_cp;
|
|
|
|
bool sss_en;
|
2015-03-18 05:41:50 -07:00
|
|
|
srslte_cp_t cp;
|
2014-10-14 05:46:58 -07:00
|
|
|
uint32_t m0;
|
|
|
|
uint32_t m1;
|
|
|
|
float m0_value;
|
|
|
|
float m1_value;
|
2015-01-20 23:55:40 -08:00
|
|
|
float M_norm_avg;
|
|
|
|
float M_ext_avg;
|
2016-10-04 10:11:04 -07:00
|
|
|
cf_t *temp;
|
2015-01-20 23:55:40 -08:00
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
uint32_t max_frame_size;
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
srslte_frame_type_t frame_type;
|
|
|
|
bool detect_frame_type;
|
2017-11-29 09:30:21 -08:00
|
|
|
|
|
|
|
// variables for various CFO estimation methods
|
|
|
|
bool cfo_cp_enable;
|
|
|
|
bool cfo_pss_enable;
|
|
|
|
bool cfo_i_enable;
|
|
|
|
|
|
|
|
bool cfo_cp_is_set;
|
|
|
|
bool cfo_pss_is_set;
|
|
|
|
bool cfo_i_initiated;
|
|
|
|
|
|
|
|
float cfo_cp_mean;
|
2017-12-16 03:46:29 -08:00
|
|
|
float cfo_pss;
|
2017-11-29 09:30:21 -08:00
|
|
|
float cfo_pss_mean;
|
|
|
|
int cfo_i_value;
|
|
|
|
|
|
|
|
float cfo_ema_alpha;
|
|
|
|
|
2017-12-17 14:05:28 -08:00
|
|
|
uint32_t cfo_cp_nsymbols;
|
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
srslte_cfo_t cfo_corr_frame;
|
|
|
|
srslte_cfo_t cfo_corr_symbol;
|
|
|
|
|
2017-12-03 20:13:07 -08:00
|
|
|
bool sss_channel_equalize;
|
2017-11-29 09:30:21 -08:00
|
|
|
bool pss_filtering_enabled;
|
|
|
|
cf_t sss_filt[SRSLTE_SYMBOL_SZ_MAX];
|
|
|
|
cf_t pss_filt[SRSLTE_SYMBOL_SZ_MAX];
|
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
bool sss_generated;
|
|
|
|
bool sss_detected;
|
|
|
|
bool sss_available;
|
|
|
|
srslte_dft_plan_t idftp_sss;
|
|
|
|
cf_t sss_recv[SRSLTE_SYMBOL_SZ_MAX];
|
|
|
|
cf_t sss_signal[2][SRSLTE_SYMBOL_SZ_MAX];
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
}srslte_sync_t;
|
2014-01-28 03:41:17 -08:00
|
|
|
|
2016-04-08 08:04:01 -07:00
|
|
|
typedef enum {
|
|
|
|
SRSLTE_SYNC_FOUND = 1,
|
|
|
|
SRSLTE_SYNC_FOUND_NOSPACE = 2,
|
|
|
|
SRSLTE_SYNC_NOFOUND = 0,
|
|
|
|
SRSLTE_SYNC_ERROR = -1
|
|
|
|
} srslte_sync_find_ret_t;
|
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_sync_init(srslte_sync_t *q,
|
|
|
|
uint32_t frame_size,
|
2015-11-09 10:15:33 -08:00
|
|
|
uint32_t max_offset,
|
2015-03-18 11:14:24 -07:00
|
|
|
uint32_t fft_size);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2017-05-08 07:29:34 -07:00
|
|
|
SRSLTE_API int srslte_sync_init_decim(srslte_sync_t *q,
|
|
|
|
uint32_t frame_size,
|
|
|
|
uint32_t max_offset,
|
|
|
|
uint32_t fft_size,
|
|
|
|
int decimate);
|
|
|
|
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_free(srslte_sync_t *q);
|
2014-03-27 09:31:25 -07:00
|
|
|
|
2017-09-01 04:29:11 -07:00
|
|
|
SRSLTE_API int srslte_sync_resize(srslte_sync_t *q,
|
|
|
|
uint32_t frame_size,
|
|
|
|
uint32_t max_offset,
|
|
|
|
uint32_t fft_size);
|
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_reset(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-08-01 14:26:28 -07:00
|
|
|
/* Finds a correlation peak in the input signal around position find_offset */
|
2016-04-08 08:04:01 -07:00
|
|
|
SRSLTE_API srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q,
|
2017-11-29 09:30:21 -08:00
|
|
|
const cf_t *input,
|
2016-04-08 08:04:01 -07:00
|
|
|
uint32_t find_offset,
|
|
|
|
uint32_t *peak_position);
|
2014-06-27 09:36:25 -07:00
|
|
|
|
2014-12-09 15:29:48 -08:00
|
|
|
/* Estimates the CP length */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q,
|
2017-11-29 09:30:21 -08:00
|
|
|
const cf_t *input,
|
2015-03-18 11:14:24 -07:00
|
|
|
uint32_t peak_pos);
|
2014-12-09 15:29:48 -08:00
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
/* Sets the threshold for peak comparison */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_set_threshold(srslte_sync_t *q,
|
|
|
|
float threshold);
|
2014-08-01 14:26:28 -07:00
|
|
|
|
|
|
|
/* Gets the subframe idx (0 or 5) */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API uint32_t srslte_sync_get_sf_idx(srslte_sync_t *q);
|
2014-03-27 09:31:25 -07:00
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
/* Gets the peak value */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API float srslte_sync_get_peak_value(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-12-09 15:29:48 -08:00
|
|
|
/* Choose SSS detection algorithm */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_set_sss_algorithm(srslte_sync_t *q,
|
|
|
|
sss_alg_t alg);
|
2014-12-09 15:29:48 -08:00
|
|
|
|
|
|
|
/* Sets PSS exponential averaging alpha weight */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_set_em_alpha(srslte_sync_t *q,
|
|
|
|
float alpha);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-08-01 14:26:28 -07:00
|
|
|
/* Sets the N_id_2 to search for */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_sync_set_N_id_2(srslte_sync_t *q,
|
|
|
|
uint32_t N_id_2);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
SRSLTE_API int srslte_sync_set_N_id_1(srslte_sync_t* q, uint32_t N_id_1);
|
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
/* Gets the Physical CellId from the last call to synch_run() */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API int srslte_sync_get_cell_id(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
/* Enables/disables filtering of the central PRBs before PSS CFO estimation or SSS correlation*/
|
|
|
|
SRSLTE_API void srslte_sync_set_pss_filt_enable(srslte_sync_t *q,
|
|
|
|
bool enable);
|
|
|
|
|
2017-12-03 20:13:07 -08:00
|
|
|
SRSLTE_API void srslte_sync_set_sss_eq_enable(srslte_sync_t *q,
|
|
|
|
bool enable);
|
2017-11-29 09:30:21 -08:00
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
/* Gets the CFO estimation from the last call to synch_run() */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API float srslte_sync_get_cfo(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
/* Resets internal CFO state */
|
|
|
|
SRSLTE_API void srslte_sync_cfo_reset(srslte_sync_t *q);
|
|
|
|
|
|
|
|
/* Copies CFO internal state from another object to avoid long transients */
|
|
|
|
SRSLTE_API void srslte_sync_copy_cfo(srslte_sync_t *q,
|
|
|
|
srslte_sync_t *src_obj);
|
2015-04-14 01:41:17 -07:00
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
/* Enable different CFO estimation stages */
|
|
|
|
SRSLTE_API void srslte_sync_set_cfo_i_enable(srslte_sync_t *q,
|
|
|
|
bool enable);
|
|
|
|
SRSLTE_API void srslte_sync_set_cfo_cp_enable(srslte_sync_t *q,
|
2017-12-17 14:05:28 -08:00
|
|
|
bool enable,
|
|
|
|
uint32_t nof_symbols);
|
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
SRSLTE_API void srslte_sync_set_cfo_pss_enable(srslte_sync_t *q,
|
|
|
|
bool enable);
|
2015-11-09 10:15:33 -08:00
|
|
|
|
2017-11-29 09:30:21 -08:00
|
|
|
/* Sets CFO correctors tolerance (in Hz) */
|
|
|
|
SRSLTE_API void srslte_sync_set_cfo_tol(srslte_sync_t *q,
|
|
|
|
float tol);
|
2015-11-10 08:13:08 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
SRSLTE_API void srslte_sync_set_frame_type(srslte_sync_t* q, srslte_frame_type_t frame_type);
|
2015-11-09 10:15:33 -08:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
/* Sets the exponential moving average coefficient for CFO averaging */
|
|
|
|
SRSLTE_API void srslte_sync_set_cfo_ema_alpha(srslte_sync_t* q, float alpha);
|
2017-11-29 09:30:21 -08:00
|
|
|
|
2014-03-27 09:31:25 -07:00
|
|
|
/* Gets the CP length estimation from the last call to synch_run() */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API srslte_cp_t srslte_sync_get_cp(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2014-10-14 05:46:58 -07:00
|
|
|
/* Sets the CP length estimation (must do it if disabled) */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_set_cp(srslte_sync_t *q,
|
|
|
|
srslte_cp_t cp);
|
2014-10-14 05:46:58 -07:00
|
|
|
|
2014-06-27 09:36:25 -07:00
|
|
|
/* Enables/Disables SSS detection */
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API void srslte_sync_sss_en(srslte_sync_t *q,
|
|
|
|
bool enabled);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2017-12-03 20:13:07 -08:00
|
|
|
SRSLTE_API srslte_pss_t* srslte_sync_get_cur_pss_obj(srslte_sync_t *q);
|
2015-11-09 10:15:33 -08:00
|
|
|
|
2015-03-18 11:14:24 -07:00
|
|
|
SRSLTE_API bool srslte_sync_sss_detected(srslte_sync_t *q);
|
2014-07-21 07:19:17 -07:00
|
|
|
|
2019-04-23 01:53:11 -07:00
|
|
|
SRSLTE_API bool srslte_sync_sss_available(srslte_sync_t* q);
|
|
|
|
|
2014-06-27 09:36:25 -07:00
|
|
|
/* Enables/Disables CP detection */
|
2019-04-23 01:53:11 -07:00
|
|
|
SRSLTE_API void srslte_sync_cp_en(srslte_sync_t* q, bool enabled);
|
2014-01-28 03:41:17 -08:00
|
|
|
|
2018-03-31 10:04:04 -07:00
|
|
|
#endif // SRSLTE_SYNC_H
|
2014-01-28 03:41:17 -08:00
|
|
|
|