|
|
@ -37,11 +37,10 @@
|
|
|
|
#include "srslte/phy/utils/vector.h"
|
|
|
|
#include "srslte/phy/utils/vector.h"
|
|
|
|
#include "srslte/phy/sync/cfo.h"
|
|
|
|
#include "srslte/phy/sync/cfo.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define MEANPEAK_EMA_ALPHA 0.1
|
|
|
|
|
|
|
|
#define CFO_EMA_ALPHA 0.1
|
|
|
|
#define CFO_EMA_ALPHA 0.1
|
|
|
|
#define CP_EMA_ALPHA 0.1
|
|
|
|
#define CP_EMA_ALPHA 0.1
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_CFO_TOL 50.0 // Hz
|
|
|
|
#define DEFAULT_CFO_TOL 0.0 // Hz
|
|
|
|
|
|
|
|
|
|
|
|
static bool fft_size_isvalid(uint32_t fft_size) {
|
|
|
|
static bool fft_size_isvalid(uint32_t fft_size) {
|
|
|
|
if (fft_size >= SRSLTE_SYNC_FFT_SZ_MIN && fft_size <= SRSLTE_SYNC_FFT_SZ_MAX && (fft_size%64) == 0) {
|
|
|
|
if (fft_size >= SRSLTE_SYNC_FFT_SZ_MIN && fft_size <= SRSLTE_SYNC_FFT_SZ_MAX && (fft_size%64) == 0) {
|
|
|
@ -51,13 +50,12 @@ static bool fft_size_isvalid(uint32_t fft_size) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int srslte_sync_init(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size)
|
|
|
|
int srslte_sync_init(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return srslte_sync_init_decim(q, frame_size, max_offset, fft_size, 1);
|
|
|
|
return srslte_sync_init_decim(q, frame_size, max_offset, fft_size, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size, int decimate) {
|
|
|
|
int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offset, uint32_t fft_size, int decimate)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
int ret = SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
|
|
|
|
|
|
|
@ -66,31 +64,34 @@ int srslte_sync_init_decim(srslte_sync_t *q, uint32_t frame_size, uint32_t max_o
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = SRSLTE_ERROR;
|
|
|
|
ret = SRSLTE_ERROR;
|
|
|
|
bzero(q, sizeof(srslte_sync_t));
|
|
|
|
bzero(q, sizeof(srslte_sync_t));
|
|
|
|
q->detect_cp = true;
|
|
|
|
|
|
|
|
q->sss_en = true;
|
|
|
|
|
|
|
|
q->mean_cfo = 0;
|
|
|
|
|
|
|
|
q->mean_cfo2 = 0;
|
|
|
|
|
|
|
|
q->N_id_2 = 1000;
|
|
|
|
q->N_id_2 = 1000;
|
|
|
|
q->N_id_1 = 1000;
|
|
|
|
q->N_id_1 = 1000;
|
|
|
|
q->cfo_i = 0;
|
|
|
|
|
|
|
|
q->find_cfo_i = false;
|
|
|
|
|
|
|
|
q->find_cfo_i_initiated = false;
|
|
|
|
|
|
|
|
q->cfo_ema_alpha = CFO_EMA_ALPHA;
|
|
|
|
q->cfo_ema_alpha = CFO_EMA_ALPHA;
|
|
|
|
|
|
|
|
q->sss_alg = SSS_FULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
q->detect_cp = true;
|
|
|
|
|
|
|
|
q->sss_en = true;
|
|
|
|
|
|
|
|
q->cfo_pss_enable = false;
|
|
|
|
|
|
|
|
q->cfo_cp_enable = false;
|
|
|
|
|
|
|
|
q->cfo_i_initiated = false;
|
|
|
|
|
|
|
|
q->pss_filtering_enabled = false;
|
|
|
|
|
|
|
|
q->sss_filtering_enabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
q->fft_size = fft_size;
|
|
|
|
q->fft_size = fft_size;
|
|
|
|
q->frame_size = frame_size;
|
|
|
|
q->frame_size = frame_size;
|
|
|
|
q->max_offset = max_offset;
|
|
|
|
q->max_offset = max_offset;
|
|
|
|
q->sss_alg = SSS_FULL;
|
|
|
|
|
|
|
|
q->max_frame_size = frame_size;
|
|
|
|
q->max_frame_size = frame_size;
|
|
|
|
q->mean_cfo_isunset = true;
|
|
|
|
|
|
|
|
q->mean_cfo2_isunset = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
q->enable_cfo_corr = true;
|
|
|
|
srslte_sync_cfo_reset(q);
|
|
|
|
if (srslte_cfo_init(&q->cfocorr, q->frame_size)) {
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_cfo_init(&q->cfo_corr_frame, q->frame_size)) {
|
|
|
|
fprintf(stderr, "Error initiating CFO\n");
|
|
|
|
fprintf(stderr, "Error initiating CFO\n");
|
|
|
|
goto clean_exit;
|
|
|
|
goto clean_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_cfo_init(&q->cfocorr2, q->frame_size)) {
|
|
|
|
if (srslte_cfo_init(&q->cfo_corr_symbol, q->fft_size)) {
|
|
|
|
fprintf(stderr, "Error initiating CFO\n");
|
|
|
|
fprintf(stderr, "Error initiating CFO\n");
|
|
|
|
goto clean_exit;
|
|
|
|
goto clean_exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -146,19 +147,24 @@ clean_exit:
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_free(srslte_sync_t *q) {
|
|
|
|
void srslte_sync_free(srslte_sync_t *q)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (q) {
|
|
|
|
if (q) {
|
|
|
|
|
|
|
|
|
|
|
|
srslte_pss_synch_free(&q->pss);
|
|
|
|
srslte_pss_synch_free(&q->pss);
|
|
|
|
srslte_sss_synch_free(&q->sss);
|
|
|
|
srslte_sss_synch_free(&q->sss);
|
|
|
|
srslte_cfo_free(&q->cfocorr);
|
|
|
|
srslte_cfo_free(&q->cfo_corr_frame);
|
|
|
|
srslte_cfo_free(&q->cfocorr2);
|
|
|
|
srslte_cfo_free(&q->cfo_corr_symbol);
|
|
|
|
srslte_cp_synch_free(&q->cp_synch);
|
|
|
|
srslte_cp_synch_free(&q->cp_synch);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (q->cfo_i_initiated) {
|
|
|
|
for (int i=0;i<2;i++) {
|
|
|
|
for (int i=0;i<2;i++) {
|
|
|
|
if (q->cfo_i_corr[i]) {
|
|
|
|
if (q->cfo_i_corr[i]) {
|
|
|
|
free(q->cfo_i_corr[i]);
|
|
|
|
free(q->cfo_i_corr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srslte_pss_synch_free(&q->pss_i[i]);
|
|
|
|
srslte_pss_synch_free(&q->pss_i[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (q->temp) {
|
|
|
|
if (q->temp) {
|
|
|
|
free(q->temp);
|
|
|
|
free(q->temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -173,53 +179,51 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse
|
|
|
|
frame_size <= 307200 &&
|
|
|
|
frame_size <= 307200 &&
|
|
|
|
fft_size_isvalid(fft_size))
|
|
|
|
fft_size_isvalid(fft_size))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ret = SRSLTE_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (frame_size > q->max_frame_size) {
|
|
|
|
if (frame_size > q->max_frame_size) {
|
|
|
|
fprintf(stderr, "Error in sync_resize(): frame_size must be lower than initialized\n");
|
|
|
|
fprintf(stderr, "Error in sync_resize(): frame_size must be lower than initialized\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
q->detect_cp = true;
|
|
|
|
|
|
|
|
q->sss_en = true;
|
|
|
|
|
|
|
|
q->mean_cfo = 0;
|
|
|
|
|
|
|
|
q->mean_cfo2 = 0;
|
|
|
|
|
|
|
|
q->N_id_2 = 1000;
|
|
|
|
|
|
|
|
q->N_id_1 = 1000;
|
|
|
|
|
|
|
|
q->cfo_i = 0;
|
|
|
|
|
|
|
|
q->find_cfo_i = false;
|
|
|
|
|
|
|
|
q->find_cfo_i_initiated = false;
|
|
|
|
|
|
|
|
q->cfo_ema_alpha = CFO_EMA_ALPHA;
|
|
|
|
|
|
|
|
q->fft_size = fft_size;
|
|
|
|
q->fft_size = fft_size;
|
|
|
|
q->frame_size = frame_size;
|
|
|
|
q->frame_size = frame_size;
|
|
|
|
q->max_offset = max_offset;
|
|
|
|
q->max_offset = max_offset;
|
|
|
|
q->sss_alg = SSS_FULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
q->enable_cfo_corr = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_pss_synch_resize(&q->pss, max_offset, fft_size, 0)) {
|
|
|
|
if (srslte_pss_synch_resize(&q->pss, q->max_offset, q->fft_size, 0)) {
|
|
|
|
fprintf(stderr, "Error resizing PSS object\n");
|
|
|
|
fprintf(stderr, "Error resizing PSS object\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (srslte_sss_synch_resize(&q->sss, fft_size)) {
|
|
|
|
if (srslte_sss_synch_resize(&q->sss, q->fft_size)) {
|
|
|
|
fprintf(stderr, "Error resizing SSS object\n");
|
|
|
|
fprintf(stderr, "Error resizing SSS object\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_cp_synch_resize(&q->cp_synch, fft_size)) {
|
|
|
|
if (srslte_cp_synch_resize(&q->cp_synch, q->fft_size)) {
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_cfo_resize(&q->cfocorr, q->frame_size)) {
|
|
|
|
if (srslte_cfo_resize(&q->cfo_corr_frame, q->frame_size)) {
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (srslte_cfo_resize(&q->cfocorr2, q->frame_size)) {
|
|
|
|
if (srslte_cfo_resize(&q->cfo_corr_symbol, q->fft_size)) {
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
fprintf(stderr, "Error resizing CFO\n");
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (q->cfo_i_initiated) {
|
|
|
|
|
|
|
|
for (int i=0;i<2;i++) {
|
|
|
|
|
|
|
|
int offset=(i==0)?-1:1;
|
|
|
|
|
|
|
|
if (srslte_pss_synch_resize(&q->pss_i[i], q->max_offset, q->fft_size, offset)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error initializing PSS object\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int t=0;t<q->frame_size;t++) {
|
|
|
|
|
|
|
|
q->cfo_i_corr[i][t] = cexpf(-2*_Complex_I*M_PI*offset*(float) t/q->fft_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update CFO tolerance
|
|
|
|
// Update CFO tolerance
|
|
|
|
srslte_sync_set_cfo_tol(q, q->current_cfo_tol);
|
|
|
|
srslte_sync_set_cfo_tol(q, q->current_cfo_tol);
|
|
|
|
|
|
|
|
|
|
|
@ -235,30 +239,14 @@ int srslte_sync_resize(srslte_sync_t *q, uint32_t frame_size, uint32_t max_offse
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_tol(srslte_sync_t *q, float tol) {
|
|
|
|
void srslte_sync_set_cfo_tol(srslte_sync_t *q, float tol) {
|
|
|
|
q->current_cfo_tol = tol;
|
|
|
|
q->current_cfo_tol = tol;
|
|
|
|
srslte_cfo_set_tol(&q->cfocorr, tol/(15000.0*q->fft_size));
|
|
|
|
srslte_cfo_set_tol(&q->cfo_corr_frame, tol/(15000.0*q->fft_size));
|
|
|
|
srslte_cfo_set_tol(&q->cfocorr2, tol/(15000.0*q->fft_size));
|
|
|
|
srslte_cfo_set_tol(&q->cfo_corr_symbol, tol/(15000.0*q->fft_size));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_threshold(srslte_sync_t *q, float threshold) {
|
|
|
|
void srslte_sync_set_threshold(srslte_sync_t *q, float threshold) {
|
|
|
|
q->threshold = threshold;
|
|
|
|
q->threshold = threshold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_cfo_i_detec_en(srslte_sync_t *q, bool enabled) {
|
|
|
|
|
|
|
|
q->find_cfo_i = enabled;
|
|
|
|
|
|
|
|
if (enabled && !q->find_cfo_i_initiated) {
|
|
|
|
|
|
|
|
for (int i=0;i<2;i++) {
|
|
|
|
|
|
|
|
int offset=(i==0)?-1:1;
|
|
|
|
|
|
|
|
if (srslte_pss_synch_init_fft_offset(&q->pss_i[i], q->max_offset, q->fft_size, offset)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error initializing PSS object\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int t=0;t<q->frame_size;t++) {
|
|
|
|
|
|
|
|
q->cfo_i_corr[i][t] = cexpf(-2*_Complex_I*M_PI*offset*(float) t/q->fft_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
q->find_cfo_i_initiated = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_sss_en(srslte_sync_t *q, bool enabled) {
|
|
|
|
void srslte_sync_sss_en(srslte_sync_t *q, bool enabled) {
|
|
|
|
q->sss_en = enabled;
|
|
|
|
q->sss_en = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -290,30 +278,59 @@ uint32_t srslte_sync_get_sf_idx(srslte_sync_t *q) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float srslte_sync_get_cfo(srslte_sync_t *q) {
|
|
|
|
float srslte_sync_get_cfo(srslte_sync_t *q) {
|
|
|
|
return q->mean_cfo2 + q->cfo_i;
|
|
|
|
return q->cfo_cp_mean + q->cfo_pss_mean + q->cfo_i_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo(srslte_sync_t *q, float cfo) {
|
|
|
|
void srslte_sync_cfo_reset(srslte_sync_t *q)
|
|
|
|
q->mean_cfo = cfo;
|
|
|
|
{
|
|
|
|
q->mean_cfo2 = cfo;
|
|
|
|
q->cfo_cp_mean = 0;
|
|
|
|
q->mean_cfo2_isunset = false;
|
|
|
|
q->cfo_cp_is_set = false;
|
|
|
|
q->mean_cfo_isunset = false;
|
|
|
|
q->cfo_pss_mean = 0;
|
|
|
|
|
|
|
|
q->cfo_pss_is_set = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_i(srslte_sync_t *q, int cfo_i) {
|
|
|
|
void srslte_sync_copy_cfo(srslte_sync_t *q, srslte_sync_t *src_obj) {
|
|
|
|
q->cfo_i = cfo_i;
|
|
|
|
q->cfo_cp_mean = src_obj->cfo_cp_mean;
|
|
|
|
|
|
|
|
q->cfo_pss_mean = src_obj->cfo_pss_mean;
|
|
|
|
|
|
|
|
q->cfo_i_value = src_obj->cfo_i_value;
|
|
|
|
|
|
|
|
q->cfo_cp_is_set = false;
|
|
|
|
|
|
|
|
q->cfo_pss_is_set = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
void srslte_sync_set_cfo_i_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
q->enable_cfo_corr = enable;
|
|
|
|
q->cfo_i_enable = enable;
|
|
|
|
|
|
|
|
if (q->cfo_i_enable && !q->cfo_i_initiated) {
|
|
|
|
|
|
|
|
for (int i=0;i<2;i++) {
|
|
|
|
|
|
|
|
int offset=(i==0)?-1:1;
|
|
|
|
|
|
|
|
if (srslte_pss_synch_init_fft_offset(&q->pss_i[i], q->max_offset, q->fft_size, offset)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error initializing PSS object\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int t=0;t<q->frame_size;t++) {
|
|
|
|
|
|
|
|
q->cfo_i_corr[i][t] = cexpf(-2*_Complex_I*M_PI*offset*(float) t/q->fft_size);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
q->cfo_i_initiated = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_ema_alpha(srslte_sync_t *q, float alpha) {
|
|
|
|
void srslte_sync_set_sss_filt_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
q->cfo_ema_alpha = alpha;
|
|
|
|
q->sss_filtering_enabled = enable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float srslte_sync_get_last_peak_value(srslte_sync_t *q) {
|
|
|
|
void srslte_sync_set_pss_filt_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
return q->peak_value;
|
|
|
|
q->pss_filtering_enabled = enable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_cp_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
|
|
|
|
q->cfo_cp_enable = enable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_pss_enable(srslte_sync_t *q, bool enable) {
|
|
|
|
|
|
|
|
q->cfo_pss_enable = enable;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_cfo_ema_alpha(srslte_sync_t *q, float alpha) {
|
|
|
|
|
|
|
|
q->cfo_ema_alpha = alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float srslte_sync_get_peak_value(srslte_sync_t *q) {
|
|
|
|
float srslte_sync_get_peak_value(srslte_sync_t *q) {
|
|
|
@ -324,18 +341,17 @@ void srslte_sync_cp_en(srslte_sync_t *q, bool enabled) {
|
|
|
|
q->detect_cp = enabled;
|
|
|
|
q->detect_cp = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool srslte_sync_sss_is_en(srslte_sync_t *q) {
|
|
|
|
void srslte_sync_set_em_alpha(srslte_sync_t *q, float alpha)
|
|
|
|
return q->sss_en;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_em_alpha(srslte_sync_t *q, float alpha) {
|
|
|
|
|
|
|
|
srslte_pss_synch_set_ema_alpha(&q->pss, alpha);
|
|
|
|
srslte_pss_synch_set_ema_alpha(&q->pss, alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
srslte_cp_t srslte_sync_get_cp(srslte_sync_t *q) {
|
|
|
|
srslte_cp_t srslte_sync_get_cp(srslte_sync_t *q)
|
|
|
|
|
|
|
|
{
|
|
|
|
return q->cp;
|
|
|
|
return q->cp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void srslte_sync_set_cp(srslte_sync_t *q, srslte_cp_t cp) {
|
|
|
|
void srslte_sync_set_cp(srslte_sync_t *q, srslte_cp_t cp)
|
|
|
|
|
|
|
|
{
|
|
|
|
q->cp = cp;
|
|
|
|
q->cp = cp;
|
|
|
|
q->cp_len = SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(1,q->fft_size):SRSLTE_CP_LEN_EXT(q->fft_size);
|
|
|
|
q->cp_len = SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_LEN_NORM(1,q->fft_size):SRSLTE_CP_LEN_EXT(q->fft_size);
|
|
|
|
if (q->frame_size < q->fft_size) {
|
|
|
|
if (q->frame_size < q->fft_size) {
|
|
|
@ -345,7 +361,8 @@ void srslte_sync_set_cp(srslte_sync_t *q, srslte_cp_t cp) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srslte_sync_set_sss_algorithm(srslte_sync_t *q, sss_alg_t alg) {
|
|
|
|
void srslte_sync_set_sss_algorithm(srslte_sync_t *q, sss_alg_t alg)
|
|
|
|
|
|
|
|
{
|
|
|
|
q->sss_alg = alg;
|
|
|
|
q->sss_alg = alg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -353,7 +370,7 @@ void srslte_sync_set_sss_algorithm(srslte_sync_t *q, sss_alg_t alg) {
|
|
|
|
* "SSS Detection Method for Initial Cell Search in 3GPP LTE FDD/TDD Dual Mode Receiver"
|
|
|
|
* "SSS Detection Method for Initial Cell Search in 3GPP LTE FDD/TDD Dual Mode Receiver"
|
|
|
|
* by Jung-In Kim et al.
|
|
|
|
* by Jung-In Kim et al.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, cf_t *input, uint32_t peak_pos)
|
|
|
|
srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, const cf_t *input, uint32_t peak_pos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
float R_norm=0, R_ext=0, C_norm=0, C_ext=0;
|
|
|
|
float R_norm=0, R_ext=0, C_norm=0, C_ext=0;
|
|
|
|
float M_norm=0, M_ext=0;
|
|
|
|
float M_norm=0, M_ext=0;
|
|
|
@ -369,8 +386,8 @@ srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, cf_t *input, uint32_t peak_p
|
|
|
|
|
|
|
|
|
|
|
|
if (nof_symbols > 0) {
|
|
|
|
if (nof_symbols > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
cf_t *input_cp_norm = &input[peak_pos-nof_symbols*(q->fft_size+cp_norm_len)];
|
|
|
|
const cf_t *input_cp_norm = &input[peak_pos-nof_symbols*(q->fft_size+cp_norm_len)];
|
|
|
|
cf_t *input_cp_ext = &input[peak_pos-nof_symbols*(q->fft_size+cp_ext_len)];
|
|
|
|
const cf_t *input_cp_ext = &input[peak_pos-nof_symbols*(q->fft_size+cp_ext_len)];
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<nof_symbols;i++) {
|
|
|
|
for (int i=0;i<nof_symbols;i++) {
|
|
|
|
R_norm += crealf(srslte_vec_dot_prod_conj_ccc(&input_cp_norm[q->fft_size], input_cp_norm, cp_norm_len));
|
|
|
|
R_norm += crealf(srslte_vec_dot_prod_conj_ccc(&input_cp_norm[q->fft_size], input_cp_norm, cp_norm_len));
|
|
|
@ -413,28 +430,21 @@ srslte_cp_t srslte_sync_detect_cp(srslte_sync_t *q, cf_t *input, uint32_t peak_p
|
|
|
|
/* Returns 1 if the SSS is found, 0 if not and -1 if there is not enough space
|
|
|
|
/* Returns 1 if the SSS is found, 0 if not and -1 if there is not enough space
|
|
|
|
* to correlate
|
|
|
|
* to correlate
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int sync_sss(srslte_sync_t *q, cf_t *input, uint32_t peak_pos, srslte_cp_t cp) {
|
|
|
|
int sync_sss_symbol(srslte_sync_t *q, const cf_t *input)
|
|
|
|
int sss_idx, ret;
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
srslte_sss_synch_set_N_id_2(&q->sss, q->N_id_2);
|
|
|
|
srslte_sss_synch_set_N_id_2(&q->sss, q->N_id_2);
|
|
|
|
|
|
|
|
|
|
|
|
/* Make sure we have enough room to find SSS sequence */
|
|
|
|
|
|
|
|
sss_idx = (int) peak_pos-2*q->fft_size-SRSLTE_CP_LEN(q->fft_size, (SRSLTE_CP_ISNORM(q->cp)?SRSLTE_CP_NORM_LEN:SRSLTE_CP_EXT_LEN));
|
|
|
|
|
|
|
|
if (sss_idx < 0) {
|
|
|
|
|
|
|
|
DEBUG("Not enough room to decode SSS (sss_idx=%d, peak_pos=%d)\n", sss_idx, peak_pos);
|
|
|
|
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("Searching SSS around sss_idx: %d, peak_pos: %d\n", sss_idx, peak_pos);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(q->sss_alg) {
|
|
|
|
switch(q->sss_alg) {
|
|
|
|
case SSS_DIFF:
|
|
|
|
case SSS_DIFF:
|
|
|
|
srslte_sss_synch_m0m1_diff(&q->sss, &input[sss_idx], &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
srslte_sss_synch_m0m1_diff(&q->sss, input, &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SSS_PARTIAL_3:
|
|
|
|
case SSS_PARTIAL_3:
|
|
|
|
srslte_sss_synch_m0m1_partial(&q->sss, &input[sss_idx], 3, NULL, &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
srslte_sss_synch_m0m1_partial(&q->sss, input, 3, NULL, &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case SSS_FULL:
|
|
|
|
case SSS_FULL:
|
|
|
|
srslte_sss_synch_m0m1_partial(&q->sss, &input[sss_idx], 1, NULL, &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
srslte_sss_synch_m0m1_partial(&q->sss, input, 1, NULL, &q->m0, &q->m0_value, &q->m1, &q->m1_value);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -451,20 +461,23 @@ int sync_sss(srslte_sync_t *q, cf_t *input, uint32_t peak_pos, srslte_cp_t cp) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
srslte_pss_synch_t* srslte_sync_get_cur_pss_obj(srslte_sync_t *q) {
|
|
|
|
srslte_pss_synch_t* srslte_sync_get_cur_pss_obj(srslte_sync_t *q)
|
|
|
|
|
|
|
|
{
|
|
|
|
srslte_pss_synch_t *pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]};
|
|
|
|
srslte_pss_synch_t *pss_obj[3] = {&q->pss_i[0], &q->pss, &q->pss_i[1]};
|
|
|
|
return pss_obj[q->cfo_i+1];
|
|
|
|
return pss_obj[q->cfo_i_value+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static float cfo_estimate(srslte_sync_t *q, cf_t *input) {
|
|
|
|
static float cfo_cp_estimate(srslte_sync_t *q, const cf_t *input)
|
|
|
|
|
|
|
|
{
|
|
|
|
uint32_t cp_offset = 0;
|
|
|
|
uint32_t cp_offset = 0;
|
|
|
|
cp_offset = srslte_cp_synch(&q->cp_synch, input, q->max_offset, 2, SRSLTE_CP_LEN_NORM(1,q->fft_size));
|
|
|
|
cp_offset = srslte_cp_synch(&q->cp_synch, input, q->max_offset, 7, SRSLTE_CP_LEN_NORM(1,q->fft_size));
|
|
|
|
cf_t cp_corr_max = srslte_cp_synch_corr_output(&q->cp_synch, cp_offset);
|
|
|
|
cf_t cp_corr_max = srslte_cp_synch_corr_output(&q->cp_synch, cp_offset);
|
|
|
|
float cfo = -carg(cp_corr_max) / M_PI / 2;
|
|
|
|
float cfo = -carg(cp_corr_max) / M_PI / 2;
|
|
|
|
return cfo;
|
|
|
|
return cfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int cfo_i_estimate(srslte_sync_t *q, cf_t *input, int find_offset, int *peak_pos) {
|
|
|
|
static int cfo_i_estimate(srslte_sync_t *q, const cf_t *input, int find_offset, int *peak_pos, int *cfo_i)
|
|
|
|
|
|
|
|
{
|
|
|
|
float peak_value;
|
|
|
|
float peak_value;
|
|
|
|
float max_peak_value = -99;
|
|
|
|
float max_peak_value = -99;
|
|
|
|
int max_cfo_i = 0;
|
|
|
|
int max_cfo_i = 0;
|
|
|
@ -472,6 +485,9 @@ static int cfo_i_estimate(srslte_sync_t *q, cf_t *input, int find_offset, int *p
|
|
|
|
for (int cfo_i=0;cfo_i<3;cfo_i++) {
|
|
|
|
for (int cfo_i=0;cfo_i<3;cfo_i++) {
|
|
|
|
srslte_pss_synch_set_N_id_2(pss_obj[cfo_i], q->N_id_2);
|
|
|
|
srslte_pss_synch_set_N_id_2(pss_obj[cfo_i], q->N_id_2);
|
|
|
|
int p = srslte_pss_synch_find_pss(pss_obj[cfo_i], &input[find_offset], &peak_value);
|
|
|
|
int p = srslte_pss_synch_find_pss(pss_obj[cfo_i], &input[find_offset], &peak_value);
|
|
|
|
|
|
|
|
if (p < 0) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (peak_value > max_peak_value) {
|
|
|
|
if (peak_value > max_peak_value) {
|
|
|
|
max_peak_value = peak_value;
|
|
|
|
max_peak_value = peak_value;
|
|
|
|
if (peak_pos) {
|
|
|
|
if (peak_pos) {
|
|
|
@ -481,30 +497,26 @@ static int cfo_i_estimate(srslte_sync_t *q, cf_t *input, int find_offset, int *p
|
|
|
|
max_cfo_i = cfo_i-1;
|
|
|
|
max_cfo_i = cfo_i-1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max_cfo_i;
|
|
|
|
if (cfo_i) {
|
|
|
|
}
|
|
|
|
*cfo_i = max_cfo_i;
|
|
|
|
|
|
|
|
|
|
|
|
float srslte_sync_cfo_estimate(srslte_sync_t *q, cf_t *input, int find_offset) {
|
|
|
|
|
|
|
|
float cfo_f = cfo_estimate(q, input);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cfo_i = 0;
|
|
|
|
|
|
|
|
if (q->find_cfo_i) {
|
|
|
|
|
|
|
|
cfo_i = cfo_i_estimate(q, input, find_offset, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (float) cfo_i + cfo_f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Finds the PSS sequence previously defined by a call to srslte_sync_set_N_id_2()
|
|
|
|
/** Finds the PSS sequence previously defined by a call to srslte_sync_set_N_id_2()
|
|
|
|
* around the position find_offset in the buffer input.
|
|
|
|
* around the position find_offset in the buffer input.
|
|
|
|
|
|
|
|
*
|
|
|
|
* Returns 1 if the correlation peak exceeds the threshold set by srslte_sync_set_threshold()
|
|
|
|
* Returns 1 if the correlation peak exceeds the threshold set by srslte_sync_set_threshold()
|
|
|
|
* or 0 otherwise. Returns a negative number on error (if N_id_2 has not been set)
|
|
|
|
* or 0 otherwise. Returns a negative number on error (if N_id_2 has not been set)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|
|
|
|
* The input signal is not modified. Any CFO correction is done in internal buffers
|
|
|
|
|
|
|
|
*
|
|
|
|
* The maximum of the correlation peak is always stored in *peak_position
|
|
|
|
* The maximum of the correlation peak is always stored in *peak_position
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, cf_t *input, uint32_t find_offset, uint32_t *peak_position)
|
|
|
|
srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, const cf_t *input, uint32_t find_offset, uint32_t *peak_position)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
srslte_sync_find_ret_t ret = SRSLTE_SYNC_ERROR;
|
|
|
|
srslte_sync_find_ret_t ret = SRSLTE_SYNC_ERROR;
|
|
|
|
|
|
|
|
int peak_pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (!q) {
|
|
|
|
if (!q) {
|
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
|
return SRSLTE_ERROR_INVALID_INPUTS;
|
|
|
@ -514,92 +526,142 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, cf_t *input, uint32_t
|
|
|
|
srslte_N_id_2_isvalid(q->N_id_2) &&
|
|
|
|
srslte_N_id_2_isvalid(q->N_id_2) &&
|
|
|
|
fft_size_isvalid(q->fft_size))
|
|
|
|
fft_size_isvalid(q->fft_size))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int peak_pos = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (peak_position) {
|
|
|
|
if (peak_position) {
|
|
|
|
*peak_position = 0;
|
|
|
|
*peak_position = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cf_t *input_cfo = input;
|
|
|
|
const cf_t *input_ptr = input;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* First CFO estimation stage is integer.
|
|
|
|
|
|
|
|
* Finds max PSS correlation for shifted +1/0/-1 integer versions.
|
|
|
|
|
|
|
|
* This should only used once N_id_2 is set
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (q->cfo_i_enable) {
|
|
|
|
|
|
|
|
if (cfo_i_estimate(q, input_ptr, find_offset, &peak_pos, &q->cfo_i_value) < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling finding PSS sequence at : %d \n", peak_pos);
|
|
|
|
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Correct it using precomputed signal and store in buffer (don't modify input signal)
|
|
|
|
|
|
|
|
if (q->cfo_i_value != 0) {
|
|
|
|
|
|
|
|
srslte_vec_prod_ccc((cf_t*) input_ptr, q->cfo_i_corr[q->cfo_i_value<0?0:1], q->temp, q->frame_size);
|
|
|
|
|
|
|
|
INFO("Compensating cfo_i=%d\n", q->cfo_i_value);
|
|
|
|
|
|
|
|
input_ptr = q->temp;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (q->enable_cfo_corr) {
|
|
|
|
/* Second stage is coarse fractional CFO estimation using CP.
|
|
|
|
float cfo = cfo_estimate(q, input);
|
|
|
|
* In case of multi-cell, this can lead to incorrect estimations if CFO from different cells is different
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (q->cfo_cp_enable) {
|
|
|
|
|
|
|
|
float cfo_cp = cfo_cp_estimate(q, input_ptr);
|
|
|
|
|
|
|
|
|
|
|
|
if (q->mean_cfo_isunset) {
|
|
|
|
if (!q->cfo_cp_is_set) {
|
|
|
|
q->mean_cfo = cfo;
|
|
|
|
q->cfo_cp_mean = cfo_cp;
|
|
|
|
q->mean_cfo_isunset = false;
|
|
|
|
q->cfo_cp_is_set = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/* compute exponential moving average CFO */
|
|
|
|
/* compute exponential moving average CFO */
|
|
|
|
q->mean_cfo = SRSLTE_VEC_EMA(cfo, q->mean_cfo, q->cfo_ema_alpha);
|
|
|
|
q->cfo_cp_mean = SRSLTE_VEC_EMA(cfo_cp, q->cfo_cp_mean, q->cfo_ema_alpha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Correct CFO with the averaged CFO estimation */
|
|
|
|
INFO("CP-CFO: estimated=%f, mean=%f\n", cfo_cp, q->cfo_cp_mean);
|
|
|
|
srslte_cfo_correct(&q->cfocorr2, input, q->temp, -q->mean_cfo / q->fft_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
input_cfo = q->temp;
|
|
|
|
/* Correct CFO with the averaged CFO estimation */
|
|
|
|
|
|
|
|
srslte_cfo_correct(&q->cfo_corr_frame, input_ptr, q->temp, -q->cfo_cp_mean / q->fft_size);
|
|
|
|
|
|
|
|
input_ptr = q->temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If integer CFO is enabled, find max PSS correlation for shifted +1/0/-1 integer versions */
|
|
|
|
/* Find maximum of PSS correlation. If Integer CFO is enabled, correlation is already done
|
|
|
|
if (q->find_cfo_i && q->enable_cfo_corr) {
|
|
|
|
*/
|
|
|
|
q->cfo_i = cfo_i_estimate(q, input_cfo, find_offset, &peak_pos);
|
|
|
|
if (!q->cfo_i_enable) {
|
|
|
|
if (q->cfo_i != 0) {
|
|
|
|
srslte_pss_synch_set_N_id_2(&q->pss, q->N_id_2);
|
|
|
|
srslte_vec_prod_ccc(input_cfo, q->cfo_i_corr[q->cfo_i<0?0:1], input_cfo, q->frame_size);
|
|
|
|
peak_pos = srslte_pss_synch_find_pss(&q->pss, &input_ptr[find_offset], q->threshold>0?&q->peak_value:NULL);
|
|
|
|
INFO("Compensating cfo_i=%d\n", q->cfo_i);
|
|
|
|
if (peak_pos < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling finding PSS sequence at : %d \n", peak_pos);
|
|
|
|
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
srslte_pss_synch_set_N_id_2(&q->pss, q->N_id_2);
|
|
|
|
INFO("PSS: id=%d, peak_pos=%d, peak_value=%f\n", q->N_id_2, peak_pos, q->peak_value);
|
|
|
|
peak_pos = srslte_pss_synch_find_pss(&q->pss, &input_cfo[find_offset], &q->peak_value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this compensates for the constant time shift caused by the low pass filter
|
|
|
|
// Save peak position
|
|
|
|
|
|
|
|
if (peak_position) {
|
|
|
|
|
|
|
|
*peak_position = (uint32_t) peak_pos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// In case of decimation, this compensates for the constant time shift caused by the low pass filter
|
|
|
|
if(q->decimate && peak_pos < 0) {
|
|
|
|
if(q->decimate && peak_pos < 0) {
|
|
|
|
peak_pos = 0 ;//peak_pos + q->decimate*(2);// replace 2 with q->filter_size -2;
|
|
|
|
peak_pos = 0 ;//peak_pos + q->decimate*(2);// replace 2 with q->filter_size -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (peak_pos < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling finding PSS sequence at : %d \n", peak_pos);
|
|
|
|
/* If peak is over threshold, compute CFO and SSS */
|
|
|
|
return SRSLTE_ERROR;
|
|
|
|
if (q->peak_value >= q->threshold || q->threshold == 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (q->cfo_pss_enable && peak_pos >= q->fft_size) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Filter central bands before PSS-based CFO estimation
|
|
|
|
|
|
|
|
const cf_t *pss_ptr = &input_ptr[find_offset + peak_pos - q->fft_size];
|
|
|
|
|
|
|
|
if (q->pss_filtering_enabled) {
|
|
|
|
|
|
|
|
srslte_pss_synch_filter(&q->pss, pss_ptr, q->pss_filt);
|
|
|
|
|
|
|
|
pss_ptr = q->pss_filt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (peak_position) {
|
|
|
|
// PSS-based CFO estimation
|
|
|
|
*peak_position = (uint32_t) peak_pos;
|
|
|
|
float cfo_pss = srslte_pss_synch_cfo_compute(&q->pss, pss_ptr);
|
|
|
|
|
|
|
|
if (!q->cfo_pss_is_set) {
|
|
|
|
|
|
|
|
q->cfo_pss_mean = cfo_pss;
|
|
|
|
|
|
|
|
q->cfo_pss_is_set = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
q->cfo_pss_mean = SRSLTE_VEC_EMA(cfo_pss, q->cfo_pss_mean, q->cfo_ema_alpha);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("PSS-CFO: filter=%s, estimated=%f, mean=%f\n",
|
|
|
|
|
|
|
|
q->pss_filtering_enabled?"yes":"no", cfo_pss, q->cfo_pss_mean);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try to detect SSS
|
|
|
|
// If there is enough space for CP and PSS-based CFO estimation
|
|
|
|
|
|
|
|
if (peak_pos + find_offset >= 2 * (q->fft_size + SRSLTE_CP_LEN_EXT(q->fft_size))) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If SSS search is enabled, correlate SSS sequence
|
|
|
|
if (q->sss_en) {
|
|
|
|
if (q->sss_en) {
|
|
|
|
|
|
|
|
|
|
|
|
// Set an invalid N_id_1 indicating SSS is yet to be detected
|
|
|
|
// Set an invalid N_id_1 indicating SSS is yet to be detected
|
|
|
|
q->N_id_1 = 1000;
|
|
|
|
q->N_id_1 = 1000;
|
|
|
|
|
|
|
|
|
|
|
|
if (sync_sss(q, input_cfo, find_offset + peak_pos, q->cp) < 0) {
|
|
|
|
int sss_idx = find_offset + peak_pos - 2 * q->fft_size -
|
|
|
|
DEBUG("No space for SSS processing. Frame starts at %d\n", peak_pos);
|
|
|
|
SRSLTE_CP_LEN(q->fft_size, (SRSLTE_CP_ISNORM(q->cp) ? SRSLTE_CP_NORM_LEN : SRSLTE_CP_EXT_LEN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const cf_t *sss_ptr = &input_ptr[sss_idx];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Correct CFO if detected in PSS
|
|
|
|
|
|
|
|
if (q->cfo_pss_enable) {
|
|
|
|
|
|
|
|
srslte_cfo_correct(&q->cfo_corr_symbol, sss_ptr, q->sss_filt, -q->cfo_pss_mean / q->fft_size);
|
|
|
|
|
|
|
|
sss_ptr = q->sss_filt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If peak is over threshold, compute CFO and SSS */
|
|
|
|
// Filter central bands before SSS estimation
|
|
|
|
if (q->peak_value >= q->threshold) {
|
|
|
|
if (q->sss_filtering_enabled) {
|
|
|
|
|
|
|
|
srslte_pss_synch_filter(&q->pss, sss_ptr, q->sss_filt);
|
|
|
|
|
|
|
|
sss_ptr = q->sss_filt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ret = SRSLTE_SYNC_FOUND;
|
|
|
|
if (sync_sss_symbol(q, sss_ptr) < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error correlating SSS\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Detect CP length
|
|
|
|
if (q->detect_cp) {
|
|
|
|
if (q->detect_cp) {
|
|
|
|
if (peak_pos + find_offset >= 2*(q->fft_size + SRSLTE_CP_LEN_EXT(q->fft_size))) {
|
|
|
|
srslte_sync_set_cp(q, srslte_sync_detect_cp(q, input_ptr, peak_pos + find_offset));
|
|
|
|
srslte_sync_set_cp(q, srslte_sync_detect_cp(q, input_cfo, peak_pos + find_offset));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
DEBUG("Not enough room to detect CP length. Peak position: %d\n", peak_pos);
|
|
|
|
DEBUG("Not enough room to detect CP length. Peak position: %d\n", peak_pos);
|
|
|
|
ret = SRSLTE_SYNC_FOUND_NOSPACE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (q->enable_cfo_pss) {
|
|
|
|
ret = SRSLTE_SYNC_FOUND;
|
|
|
|
if (peak_pos + find_offset >= 2*(q->fft_size + SRSLTE_CP_LEN_EXT(q->fft_size))) {
|
|
|
|
|
|
|
|
float cfo2 = srslte_pss_synch_cfo_compute(&q->pss, &input[find_offset + peak_pos - q->fft_size]);
|
|
|
|
|
|
|
|
if (q->mean_cfo2_isunset) {
|
|
|
|
|
|
|
|
q->mean_cfo2 = cfo2;
|
|
|
|
|
|
|
|
q->mean_cfo2_isunset = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
q->mean_cfo2 = SRSLTE_VEC_EMA(cfo2, q->mean_cfo2, q->cfo_ema_alpha);
|
|
|
|
ret = SRSLTE_SYNC_FOUND_NOSPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ret = SRSLTE_SYNC_NOFOUND;
|
|
|
|
ret = SRSLTE_SYNC_NOFOUND;
|
|
|
@ -607,7 +669,7 @@ srslte_sync_find_ret_t srslte_sync_find(srslte_sync_t *q, cf_t *input, uint32_t
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG("SYNC ret=%d N_id_2=%d find_offset=%d frame_len=%d, pos=%d peak=%.2f threshold=%.2f sf_idx=%d, CFO=%.3f kHz\n",
|
|
|
|
DEBUG("SYNC ret=%d N_id_2=%d find_offset=%d frame_len=%d, pos=%d peak=%.2f threshold=%.2f sf_idx=%d, CFO=%.3f kHz\n",
|
|
|
|
ret, q->N_id_2, find_offset, q->frame_size, peak_pos, q->peak_value,
|
|
|
|
ret, q->N_id_2, find_offset, q->frame_size, peak_pos, q->peak_value,
|
|
|
|
q->threshold, q->sf_idx, 15*(q->cfo_i+q->mean_cfo));
|
|
|
|
q->threshold, q->sf_idx, 15*(srslte_sync_get_cfo(q)));
|
|
|
|
|
|
|
|
|
|
|
|
} else if (srslte_N_id_2_isvalid(q->N_id_2)) {
|
|
|
|
} else if (srslte_N_id_2_isvalid(q->N_id_2)) {
|
|
|
|
fprintf(stderr, "Must call srslte_sync_set_N_id_2() first!\n");
|
|
|
|
fprintf(stderr, "Must call srslte_sync_set_N_id_2() first!\n");
|
|
|
|