|
|
@ -367,151 +367,154 @@ int refsignal_dl_sync_find_peak(srsran_refsignal_dl_sync_t* q, cf_t* buffer, uin
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srsran_refsignal_dl_sync_run(srsran_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t nsamples)
|
|
|
|
int srsran_refsignal_dl_sync_run(srsran_refsignal_dl_sync_t* q, cf_t* buffer, uint32_t nsamples)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (q) {
|
|
|
|
if (q == NULL || buffer == NULL) {
|
|
|
|
uint32_t sf_len = q->ifft.sf_sz;
|
|
|
|
return SRSRAN_ERROR_INVALID_INPUTS;
|
|
|
|
uint32_t sf_count = 0;
|
|
|
|
}
|
|
|
|
float rsrp_lin = 0.0f;
|
|
|
|
uint32_t sf_len = q->ifft.sf_sz;
|
|
|
|
float rsrp_lin_min = +INFINITY;
|
|
|
|
uint32_t sf_count = 0;
|
|
|
|
float rsrp_lin_max = -INFINITY;
|
|
|
|
float rsrp_lin = 0.0f;
|
|
|
|
float rssi_lin = 0.0f;
|
|
|
|
float rsrp_lin_min = +INFINITY;
|
|
|
|
float cfo_acc = 0.0f;
|
|
|
|
float rsrp_lin_max = -INFINITY;
|
|
|
|
float cfo_min = +INFINITY;
|
|
|
|
float rssi_lin = 0.0f;
|
|
|
|
float cfo_max = -INFINITY;
|
|
|
|
float cfo_acc = 0.0f;
|
|
|
|
float sss_strength_avg = 0.0f;
|
|
|
|
float cfo_min = +INFINITY;
|
|
|
|
float sss_strength_false_avg = 0.0f;
|
|
|
|
float cfo_max = -INFINITY;
|
|
|
|
float rsrp_false_avg = 0.0f;
|
|
|
|
float sss_strength_avg = 0.0f;
|
|
|
|
bool false_alarm = false;
|
|
|
|
float sss_strength_false_avg = 0.0f;
|
|
|
|
|
|
|
|
float rsrp_false_avg = 0.0f;
|
|
|
|
// Stage 1: find peak
|
|
|
|
bool false_alarm = false;
|
|
|
|
int peak_idx = refsignal_dl_sync_find_peak(q, buffer, nsamples);
|
|
|
|
|
|
|
|
|
|
|
|
// Stage 1: find peak
|
|
|
|
// Stage 2: Proccess subframes
|
|
|
|
int peak_idx = refsignal_dl_sync_find_peak(q, buffer, nsamples);
|
|
|
|
if (peak_idx >= 0) {
|
|
|
|
|
|
|
|
// Calculate initial subframe index and sample
|
|
|
|
// Stage 2: Proccess subframes
|
|
|
|
uint32_t sf_idx_init = SRSRAN_NOF_SF_X_FRAME - (peak_idx / sf_len) % SRSRAN_NOF_SF_X_FRAME;
|
|
|
|
if (peak_idx >= 0) {
|
|
|
|
uint32_t n_init = peak_idx % sf_len;
|
|
|
|
// Calculate initial subframe index and sample
|
|
|
|
|
|
|
|
uint32_t sf_idx_init = SRSRAN_NOF_SF_X_FRAME - (peak_idx / sf_len) % SRSRAN_NOF_SF_X_FRAME;
|
|
|
|
for (uint32_t sf_idx = sf_idx_init, n = n_init; n < (nsamples - sf_len + 1);
|
|
|
|
uint32_t n_init = peak_idx % sf_len;
|
|
|
|
sf_idx = (sf_idx + 1) % SRSRAN_NOF_SF_X_FRAME, n += sf_len) {
|
|
|
|
|
|
|
|
cf_t* buf = &buffer[n];
|
|
|
|
for (uint32_t sf_idx = sf_idx_init, n = n_init; n < (nsamples - sf_len + 1);
|
|
|
|
|
|
|
|
sf_idx = (sf_idx + 1) % SRSRAN_NOF_SF_X_FRAME, n += sf_len) {
|
|
|
|
// Measure subframe rsrp, rssi and accumulate
|
|
|
|
cf_t* buf = &buffer[n];
|
|
|
|
float rsrp = 0.0f, rssi = 0.0f, cfo = 0.0f;
|
|
|
|
|
|
|
|
srsran_refsignal_dl_sync_measure_sf(q, buf, sf_idx, &rsrp, &rssi, &cfo);
|
|
|
|
// Measure subframe rsrp, rssi and accumulate
|
|
|
|
|
|
|
|
float rsrp = 0.0f, rssi = 0.0f, cfo = 0.0f;
|
|
|
|
// Update measurements
|
|
|
|
srsran_refsignal_dl_sync_measure_sf(q, buf, sf_idx, &rsrp, &rssi, &cfo);
|
|
|
|
rsrp_lin += rsrp;
|
|
|
|
|
|
|
|
rsrp_lin_min = SRSRAN_MIN(rsrp_lin_min, rsrp);
|
|
|
|
// Update measurements
|
|
|
|
rsrp_lin_max = SRSRAN_MAX(rsrp_lin_max, rsrp);
|
|
|
|
rsrp_lin += rsrp;
|
|
|
|
|
|
|
|
rsrp_lin_min = SRSRAN_MIN(rsrp_lin_min, rsrp);
|
|
|
|
rssi_lin += rssi;
|
|
|
|
rsrp_lin_max = SRSRAN_MAX(rsrp_lin_max, rsrp);
|
|
|
|
|
|
|
|
|
|
|
|
cfo_acc += cfo;
|
|
|
|
rssi_lin += rssi;
|
|
|
|
cfo_min = SRSRAN_MIN(cfo_min, cfo);
|
|
|
|
|
|
|
|
cfo_max = SRSRAN_MAX(cfo_max, cfo);
|
|
|
|
cfo_acc += cfo;
|
|
|
|
|
|
|
|
cfo_min = SRSRAN_MIN(cfo_min, cfo);
|
|
|
|
// Compute PSS/SSS strength
|
|
|
|
cfo_max = SRSRAN_MAX(cfo_max, cfo);
|
|
|
|
if (sf_idx % (SRSRAN_NOF_SF_X_FRAME / 2) == 0) {
|
|
|
|
|
|
|
|
float sss_strength = 0.0f;
|
|
|
|
// Compute PSS/SSS strength
|
|
|
|
float sss_strength_false = 0.0f;
|
|
|
|
if (sf_idx % (SRSRAN_NOF_SF_X_FRAME / 2) == 0) {
|
|
|
|
refsignal_dl_pss_sss_strength(q, buf, sf_idx, NULL, &sss_strength, &sss_strength_false);
|
|
|
|
float sss_strength = 0.0f;
|
|
|
|
|
|
|
|
float sss_strength_false = 0.0f;
|
|
|
|
float rsrp_false = 0.0f;
|
|
|
|
refsignal_dl_pss_sss_strength(q, buf, sf_idx, NULL, &sss_strength, &sss_strength_false);
|
|
|
|
srsran_refsignal_dl_sync_measure_sf(q, buf, sf_idx + 1, &rsrp_false, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
float rsrp_false = 0.0f;
|
|
|
|
sss_strength_avg += sss_strength;
|
|
|
|
srsran_refsignal_dl_sync_measure_sf(q, buf, sf_idx + 1, &rsrp_false, NULL, NULL);
|
|
|
|
sss_strength_false_avg += sss_strength_false;
|
|
|
|
|
|
|
|
rsrp_false_avg += rsrp_false;
|
|
|
|
sss_strength_avg += sss_strength;
|
|
|
|
}
|
|
|
|
sss_strength_false_avg += sss_strength_false;
|
|
|
|
|
|
|
|
rsrp_false_avg += rsrp_false;
|
|
|
|
// Increment counter
|
|
|
|
|
|
|
|
sf_count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Average measurements
|
|
|
|
// Increment counter
|
|
|
|
if (sf_count) {
|
|
|
|
sf_count++;
|
|
|
|
rsrp_lin /= sf_count;
|
|
|
|
}
|
|
|
|
rssi_lin /= sf_count;
|
|
|
|
|
|
|
|
cfo_acc /= sf_count;
|
|
|
|
|
|
|
|
sss_strength_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
|
|
|
|
sss_strength_false_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
|
|
|
|
rsrp_false_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RSRP conversion to dB
|
|
|
|
// Average measurements
|
|
|
|
float rsrp_dB_min = srsran_convert_power_to_dBm(rsrp_lin_min);
|
|
|
|
if (sf_count) {
|
|
|
|
float rsrp_dB_max = srsran_convert_power_to_dBm(rsrp_lin_max);
|
|
|
|
rsrp_lin /= sf_count;
|
|
|
|
float rsrp_dB = srsran_convert_power_to_dBm(rsrp_lin);
|
|
|
|
rssi_lin /= sf_count;
|
|
|
|
float rsrp_false_dB = srsran_convert_power_to_dBm(rsrp_false_avg);
|
|
|
|
cfo_acc /= sf_count;
|
|
|
|
|
|
|
|
sss_strength_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
// Stage 3: Final false alarm decision
|
|
|
|
sss_strength_false_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
uint32_t false_count = 0;
|
|
|
|
rsrp_false_avg /= (2.0f * sf_count / SRSRAN_NOF_SF_X_FRAME);
|
|
|
|
if (sss_strength_avg < sss_strength_false_avg * REFSIGNAL_DL_SSS_FALSE_RATIO_SEVERE) {
|
|
|
|
}
|
|
|
|
false_alarm = true;
|
|
|
|
|
|
|
|
} else if (sss_strength_avg < sss_strength_false_avg * REFSIGNAL_DL_SSS_FALSE_RATIO_MILD) {
|
|
|
|
|
|
|
|
false_count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cfo_max - cfo_min > REFSIGNAL_DL_CFO_MIN_MAX_SEVERE) {
|
|
|
|
// RSRP conversion to dB
|
|
|
|
false_alarm = true;
|
|
|
|
float rsrp_dB_min = srsran_convert_power_to_dBm(rsrp_lin_min);
|
|
|
|
} else if (cfo_max - cfo_min > REFSIGNAL_DL_CFO_MIN_MAX_MILD) {
|
|
|
|
float rsrp_dB_max = srsran_convert_power_to_dBm(rsrp_lin_max);
|
|
|
|
false_count++;
|
|
|
|
float rsrp_dB = srsran_convert_power_to_dBm(rsrp_lin);
|
|
|
|
}
|
|
|
|
float rsrp_false_dB = srsran_convert_power_to_dBm(rsrp_false_avg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Stage 3: Final false alarm decision
|
|
|
|
|
|
|
|
uint32_t false_count = 0;
|
|
|
|
|
|
|
|
if (sss_strength_avg < sss_strength_false_avg * REFSIGNAL_DL_SSS_FALSE_RATIO_SEVERE) {
|
|
|
|
|
|
|
|
false_alarm = true;
|
|
|
|
|
|
|
|
} else if (sss_strength_avg < sss_strength_false_avg * REFSIGNAL_DL_SSS_FALSE_RATIO_MILD) {
|
|
|
|
|
|
|
|
false_count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rsrp_dB_max - rsrp_dB_min > REFSIGNAL_DL_RSRP_MIN_MAX_SEVERE) {
|
|
|
|
if (cfo_max - cfo_min > REFSIGNAL_DL_CFO_MIN_MAX_SEVERE) {
|
|
|
|
false_alarm = true;
|
|
|
|
false_alarm = true;
|
|
|
|
} else if (rsrp_dB_max - rsrp_dB_min > REFSIGNAL_DL_RSRP_MIN_MAX_MILD) {
|
|
|
|
} else if (cfo_max - cfo_min > REFSIGNAL_DL_CFO_MIN_MAX_MILD) {
|
|
|
|
false_count++;
|
|
|
|
false_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (rsrp_dB - rsrp_false_dB < REFSIGNAL_DL_RSRP_FALSE_RATIO_SEVERE) {
|
|
|
|
if (rsrp_dB_max - rsrp_dB_min > REFSIGNAL_DL_RSRP_MIN_MAX_SEVERE) {
|
|
|
|
false_alarm = true;
|
|
|
|
false_alarm = true;
|
|
|
|
} else if (rsrp_dB - rsrp_false_dB < REFSIGNAL_DL_RSRP_FALSE_RATIO_MILD) {
|
|
|
|
} else if (rsrp_dB_max - rsrp_dB_min > REFSIGNAL_DL_RSRP_MIN_MAX_MILD) {
|
|
|
|
false_count++;
|
|
|
|
false_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Allow only one check fail
|
|
|
|
if (rsrp_dB - rsrp_false_dB < REFSIGNAL_DL_RSRP_FALSE_RATIO_SEVERE) {
|
|
|
|
if (false_count > REFSIGNAL_DL_MAX_FAULT_CHECK) {
|
|
|
|
false_alarm = true;
|
|
|
|
false_alarm = true;
|
|
|
|
} else if (rsrp_dB - rsrp_false_dB < REFSIGNAL_DL_RSRP_FALSE_RATIO_MILD) {
|
|
|
|
}
|
|
|
|
false_count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFO("-- pci=%03d; rsrp_dB=(%+.1f|%+.1f|%+.1f); rsrp_max-min=%.1f; rsrp_false_ratio=%.1f; "
|
|
|
|
// Allow only one check fail
|
|
|
|
"cfo=(%.1f|%.1f|%.1f); cfo_max-min=%.1f; sss_ratio=%f; false_count=%d;",
|
|
|
|
if (false_count > REFSIGNAL_DL_MAX_FAULT_CHECK) {
|
|
|
|
q->refsignal.cell.id,
|
|
|
|
false_alarm = true;
|
|
|
|
rsrp_dB_min,
|
|
|
|
}
|
|
|
|
rsrp_dB,
|
|
|
|
|
|
|
|
rsrp_dB_max,
|
|
|
|
INFO("-- pci=%03d; rsrp_dB=(%+.1f|%+.1f|%+.1f); rsrp_max-min=%.1f; rsrp_false_ratio=%.1f; "
|
|
|
|
rsrp_dB_max - rsrp_dB_min,
|
|
|
|
"cfo=(%.1f|%.1f|%.1f); cfo_max-min=%.1f; sss_ratio=%f; false_count=%d;",
|
|
|
|
rsrp_dB - rsrp_false_dB,
|
|
|
|
q->refsignal.cell.id,
|
|
|
|
cfo_min,
|
|
|
|
rsrp_dB_min,
|
|
|
|
cfo_acc,
|
|
|
|
rsrp_dB,
|
|
|
|
cfo_max,
|
|
|
|
rsrp_dB_max,
|
|
|
|
cfo_max - cfo_min,
|
|
|
|
rsrp_dB_max - rsrp_dB_min,
|
|
|
|
sss_strength_avg / sss_strength_false_avg,
|
|
|
|
rsrp_dB - rsrp_false_dB,
|
|
|
|
false_count);
|
|
|
|
cfo_min,
|
|
|
|
|
|
|
|
cfo_acc,
|
|
|
|
if (!false_alarm) {
|
|
|
|
cfo_max,
|
|
|
|
// Calculate in dBm
|
|
|
|
cfo_max - cfo_min,
|
|
|
|
q->rsrp_dBfs = rsrp_dB;
|
|
|
|
sss_strength_avg / sss_strength_false_avg,
|
|
|
|
|
|
|
|
false_count);
|
|
|
|
// Calculate RSSI in dBm
|
|
|
|
|
|
|
|
q->rssi_dBfs = srsran_convert_power_to_dBm(rssi_lin);
|
|
|
|
if (!false_alarm) {
|
|
|
|
|
|
|
|
// Calculate in dBm
|
|
|
|
// Calculate RSRQ
|
|
|
|
q->rsrp_dBfs = rsrp_dB;
|
|
|
|
q->rsrq_dB = srsran_convert_power_to_dB(q->refsignal.cell.nof_prb) + q->rsrp_dBfs - q->rssi_dBfs;
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate RSSI in dBm
|
|
|
|
q->found = true;
|
|
|
|
q->rssi_dBfs = srsran_convert_power_to_dBm(rssi_lin);
|
|
|
|
q->cfo_Hz = cfo_acc;
|
|
|
|
|
|
|
|
q->peak_index = peak_idx;
|
|
|
|
// Calculate RSRQ
|
|
|
|
} else {
|
|
|
|
q->rsrq_dB = srsran_convert_power_to_dB(q->refsignal.cell.nof_prb) + q->rsrp_dBfs - q->rssi_dBfs;
|
|
|
|
refsignal_set_results_not_found(q);
|
|
|
|
|
|
|
|
}
|
|
|
|
q->found = true;
|
|
|
|
|
|
|
|
q->cfo_Hz = cfo_acc;
|
|
|
|
|
|
|
|
q->peak_index = peak_idx;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
refsignal_set_results_not_found(q);
|
|
|
|
refsignal_set_results_not_found(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
refsignal_set_results_not_found(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SRSRAN_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void srsran_refsignal_dl_sync_measure_sf(srsran_refsignal_dl_sync_t* q,
|
|
|
|
void srsran_refsignal_dl_sync_measure_sf(srsran_refsignal_dl_sync_t* q,
|
|
|
|